Class: Anima
- Inherits:
-
Module
- Object
- Module
- Anima
- Includes:
- Adamantium::Flat
- Defined in:
- lib/anima.rb,
lib/anima/error.rb,
lib/anima/update.rb,
lib/anima/builder.rb,
lib/anima/attribute.rb
Overview
Main library namespace and mixin
Defined Under Namespace
Modules: Update Classes: Attribute, Builder, Error
Instance Attribute Summary collapse
-
#attributes ⇒ AttributeSet
readonly
private
Return names.
Instance Method Summary collapse
-
#add(*names) ⇒ Anima
private
Return new anima with attributes added.
-
#attribute_names ⇒ Enumerable<Symbol>
private
Return attribute names.
-
#attributes_hash(object) ⇒ Hash
private
Return attributes hash for instance.
-
#initialize(*names) ⇒ undefined
constructor
private
Initialize object.
-
#initialize_instance(object, attribute_hash) ⇒ self
private
Initialize instance.
-
#remove(*names) ⇒ Anima
Return new anima with attributes removed.
Constructor Details
#initialize(*names) ⇒ undefined
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize object
25 26 27 |
# File 'lib/anima.rb', line 25 def initialize(*names) @attributes = names.uniq.map(&Attribute.method(:new)).freeze end |
Instance Attribute Details
#attributes ⇒ AttributeSet (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return names
17 18 19 |
# File 'lib/anima.rb', line 17 def attributes @attributes end |
Instance Method Details
#add(*names) ⇒ Anima
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return new anima with attributes added
39 40 41 |
# File 'lib/anima.rb', line 39 def add(*names) new(attribute_names + names) end |
#attribute_names ⇒ Enumerable<Symbol>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return attribute names
77 78 79 |
# File 'lib/anima.rb', line 77 def attribute_names attributes.map(&:name) end |
#attributes_hash(object) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return attributes hash for instance
65 66 67 68 69 |
# File 'lib/anima.rb', line 65 def attributes_hash(object) attributes.each_with_object({}) do |attribute, attributes_hash| attributes_hash[attribute.name] = attribute.get(object) end end |
#initialize_instance(object, attribute_hash) ⇒ self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize instance
92 93 94 95 96 97 98 |
# File 'lib/anima.rb', line 92 def initialize_instance(object, attribute_hash) assert_known_attributes(object, attribute_hash) attributes.each do |attribute| attribute.load(object, attribute_hash) end self end |
#remove(*names) ⇒ Anima
Return new anima with attributes removed
53 54 55 |
# File 'lib/anima.rb', line 53 def remove(*names) new(attribute_names - names) end |