Module: Schemad::Entity::ClassMethods
- Defined in:
- lib/schemad/entity.rb
Instance Method Summary collapse
- #attribute(name, args = {}, &block) ⇒ Object
- #attribute_names ⇒ Object
-
#from_data(data) ⇒ Object
expect data hash to have symbol keys at this point normalizer should standardize this.
- #inherited(subclass) ⇒ Object
Instance Method Details
#attribute(name, args = {}, &block) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/schemad/entity.rb', line 20 def attribute(name, args={}, &block) attr_accessor name define_parser_for(name, args, &block) @attributes << name end |
#attribute_names ⇒ Object
40 41 42 |
# File 'lib/schemad/entity.rb', line 40 def attribute_names @attributes end |
#from_data(data) ⇒ Object
expect data hash to have symbol keys at this point normalizer should standardize this
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/schemad/entity.rb', line 29 def from_data(data) obj = new @attributes.each do |key| value = obj.send "parse_#{key}", data obj.send "#{key}=", value end obj end |
#inherited(subclass) ⇒ Object
14 15 16 17 18 |
# File 'lib/schemad/entity.rb', line 14 def inherited(subclass) puts "INHERITED BY #{subclass}" default_attrs = inherited_var(:@attributes, []) subclass.instance_variable_set(:@attributes, default_attrs) end |