Module: Holotype
- Defined in:
- lib/holotype.rb,
lib/holotype/version.rb,
lib/holotype/attribute.rb,
lib/holotype/value_normalizer.rb,
lib/holotype/attribute/definition.rb,
lib/holotype/collection_normalizer.rb,
lib/holotype/attribute/read_only_error.rb,
lib/holotype/inheritance_disallowed_error.rb,
lib/holotype/attribute/immutable_value_error.rb,
lib/holotype/attributes_already_defined_error.rb,
lib/holotype/missing_required_attributes_error.rb,
lib/holotype/attribute/frozen_modification_error.rb,
lib/holotype/attribute/definition/no_value_class_error.rb,
lib/holotype/attribute/definition/default_conflict_error.rb,
lib/holotype/attribute/definition/required_conflict_error.rb,
lib/holotype/attribute/definition/no_collection_class_error.rb,
lib/holotype/collection_normalizer/expected_hash_like_collection_error.rb,
lib/holotype/collection_normalizer/expected_array_like_collection_error.rb
Defined Under Namespace
Modules: InstanceMethods
Classes: Attribute, AttributesAlreadyDefinedError, CollectionNormalizer, InheritanceDisallowedError, MissingRequiredAttributesError, ValueNormalizer
Constant Summary
collapse
- VERSION =
"1.0.0".freeze
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.extended(base) ⇒ Object
17
18
19
|
# File 'lib/holotype.rb', line 17
def extended base
base.send :include, InstanceMethods
end
|
Instance Method Details
#attribute(name, **options, &default) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/holotype.rb', line 22
def attribute name, **options, &default
name = name.to_sym
processed_options = if immutable?
[
__default_attribute_options,
options,
IMMUTABLE_OPTION,
].reduce :merge
else
[
__default_attribute_options,
options,
].reduce :merge
end
attribute = Attribute::Definition.new name,
**processed_options,
&default
attributes[name] = attribute
define_method name do
self.attributes[name].value
end
define_method "#{name}=" do |value|
self.attributes[name].value = value
end
end
|
#attributes ⇒ Object
59
60
61
|
# File 'lib/holotype.rb', line 59
def attributes
@attributes ||= Hash[]
end
|
#default_attribute_options(**options) ⇒ Object
77
78
79
|
# File 'lib/holotype.rb', line 77
def default_attribute_options **options
@default_attribute_options = options.freeze
end
|
#immutable? ⇒ Boolean
73
74
75
|
# File 'lib/holotype.rb', line 73
def immutable?
!!@immutable
end
|