Module: Edr::Model::ClassMethods
- Defined in:
- lib/edr/model.rb
Instance Method Summary collapse
- #_new_instance(hash = {}) ⇒ Object
- #build(data = _new_instance) ⇒ Object
- #fields(*field_names) ⇒ Object
- #wrap_associations(*association_names) ⇒ Object
Instance Method Details
#_new_instance(hash = {}) ⇒ Object
82 83 84 |
# File 'lib/edr/model.rb', line 82 def _new_instance hash = {} Registry.data_class_for(self).new hash end |
#build(data = _new_instance) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/edr/model.rb', line 55 def build(data = _new_instance) instance = new if data.kind_of?(Hash) instance._data = _new_instance(data) else instance._data = data end return instance end |
#fields(*field_names) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/edr/model.rb', line 67 def fields *field_names field_names.each do |field_name| def_delegators :_data, field_name def_delegators :_data, "#{field_name}=" end end |
#wrap_associations(*association_names) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/edr/model.rb', line 74 def wrap_associations *association_names association_names.each do |association_name| define_method association_name do wrap(association association_name) end end end |