Module: ExposeAssociation::Base
- Defined in:
- lib/expose_association/base.rb
Instance Method Summary collapse
- #expose_association(association_name, options = {}, &block) ⇒ Object
- #setup_class_for_exposition(exposer) ⇒ Object
Instance Method Details
#expose_association(association_name, options = {}, &block) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/expose_association/base.rb', line 3 def expose_association association_name, = {}, &block exposer = AssociationExposer.new(self, association_name, ) setup_class_for_exposition(exposer) if block_given? exposer.instance_eval(&block) end end |
#setup_class_for_exposition(exposer) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/expose_association/base.rb', line 11 def setup_class_for_exposition(exposer) # allowing mass assignment of the has_one association self.attr_accessible exposer.association_attributes self.accepts_nested_attributes_for exposer.association_name self.class_eval <<-CODE def #{exposer.association_setup_method} self.#{exposer.association_name} ||= #{exposer.association_class}.new end CODE end |