Class: Unparser::Anima
- Inherits:
-
Module
- Object
- Module
- Unparser::Anima
- Includes:
- Adamantium
- Defined in:
- lib/unparser/anima.rb,
lib/unparser/anima/error.rb,
lib/unparser/anima/attribute.rb
Overview
Original code before vendoring and reduction from: github.com/mbj/anima.
Defined Under Namespace
Modules: InstanceMethods Classes: Attribute, Error
Instance Attribute Summary collapse
-
#attributes ⇒ AttributeSet
readonly
Return names.
Instance Method Summary collapse
-
#add(*names) ⇒ Anima
Return new anima with attributes added.
-
#attribute_names ⇒ Enumerable<Symbol>
Return attribute names.
-
#attributes_hash(object) ⇒ Hash
Return attributes hash for instance.
-
#initialize(*names) ⇒ undefined
constructor
Initialize object.
-
#initialize_instance(object, attribute_hash) ⇒ self
Initialize instance.
-
#remove(*names) ⇒ Anima
Return new anima with attributes removed.
Constructor Details
#initialize(*names) ⇒ undefined
Initialize object
rubocop:disable Lint/MissingSuper
18 19 20 |
# File 'lib/unparser/anima.rb', line 18 def initialize(*names) @attributes = names.uniq.map(&Attribute.public_method(:new)).freeze end |
Instance Attribute Details
#attributes ⇒ AttributeSet (readonly)
Return names
11 12 13 |
# File 'lib/unparser/anima.rb', line 11 def attributes @attributes end |
Instance Method Details
#add(*names) ⇒ Anima
Return new anima with attributes added
31 32 33 |
# File 'lib/unparser/anima.rb', line 31 def add(*names) new(attribute_names + names) end |
#attribute_names ⇒ Enumerable<Symbol>
Return attribute names
61 62 63 |
# File 'lib/unparser/anima.rb', line 61 def attribute_names attributes.map(&:name) end |
#attributes_hash(object) ⇒ Hash
Return attributes hash for instance
52 53 54 55 56 |
# File 'lib/unparser/anima.rb', line 52 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
Initialize instance
73 74 75 76 77 78 79 |
# File 'lib/unparser/anima.rb', line 73 def initialize_instance(object, attribute_hash) assert_known_attributes(object.class, attribute_hash) attributes.each do |attribute| attribute.load(object, attribute_hash) end self end |
#remove(*names) ⇒ Anima
Return new anima with attributes removed
43 44 45 |
# File 'lib/unparser/anima.rb', line 43 def remove(*names) new(attribute_names - names) end |