Module: ObjectJSONMapper::Associations::ClassMethods
- Defined in:
- lib/object_json_mapper/associations.rb
Instance Method Summary collapse
-
#has_many(name, options = {}) ⇒ ObjectJSONMapper::Relation<ObjectJSONMapper::Base>
rubocop:disable Style/PredicateName.
- #has_one(name, options = {}) ⇒ ObjectJSONMapper::Base (also: #belongs_to)
Instance Method Details
#has_many(name, options = {}) ⇒ ObjectJSONMapper::Relation<ObjectJSONMapper::Base>
rubocop:disable Style/PredicateName
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/object_json_mapper/associations.rb', line 49 def has_many(name, = {}) associations << HasMany.new(name, ) define_method(name) do |reload = false| cache_name = :"@#{__method__}" if instance_variable_defined?(cache_name) && reload == false return instance_variable_get(cache_name) end instance_variable_set( cache_name, self.class.associations.find(__method__).call(self) ) end end |
#has_one(name, options = {}) ⇒ ObjectJSONMapper::Base Also known as: belongs_to
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/object_json_mapper/associations.rb', line 77 def has_one(name, = {}) associations << HasOne.new(name, ) define_method(name) do |reload = false| cache_name = :"@#{__method__}" if instance_variable_defined?(cache_name) && reload == false return instance_variable_get(cache_name) end instance_variable_set( cache_name, self.class.associations.find(__method__).call(self) ) end end |