Class: AttrJson::Associations::Definer
- Inherits:
-
Object
- Object
- AttrJson::Associations::Definer
- Defined in:
- lib/attr_json/associations/definer.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(type, klass, args, options) ⇒ Definer
constructor
A new instance of Definer.
Constructor Details
#initialize(type, klass, args, options) ⇒ Definer
Returns a new instance of Definer.
12 13 14 15 16 |
# File 'lib/attr_json/associations/definer.rb', line 12 def initialize(type, klass, args, ) @type = type @klass = klass @assoc = Association.const_get(@type.to_s.classify).new(klass, args, ) end |
Instance Method Details
#call ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/attr_json/associations/definer.rb', line 18 def call @klass.attr_json_associations = @klass.attr_json_associations.merge(@assoc.name => @assoc) @klass.class_eval <<-RUBY, __FILE__, __LINE__ + 1 def #{@assoc.name} assoc = self.class.attr_json_associations[:#{@assoc.name}] @attr_json_associations_cache[:#{@assoc.name}] ||= AttrJson::Associations::Loader::#{@type.to_s.classify}.new(assoc, self).call end RUBY end |