Module: Associations
- Included in:
- Satisfaction, Sfn::Resource
- Defined in:
- lib/satisfaction/associations.rb
Instance Method Summary collapse
Instance Method Details
#belongs_to(resource, options = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/satisfaction/associations.rb', line 11 def belongs_to(resource, ={}) class_name = [:class_name] || "Sfn::#{resource.to_s.classify}" parent_id = [:parent_attribute] || "#{resource}_id" eval <<-EOS def #{resource} @#{resource} ||= #{class_name}.new(#{parent_id}, self.satisfaction) end EOS end |
#has_many(resource, options = {}) ⇒ Object
2 3 4 5 6 7 8 9 |
# File 'lib/satisfaction/associations.rb', line 2 def has_many(resource, ={}) class_name = [:class_name] || "Sfn::#{resource.to_s.classify}" eval <<-EOS def #{resource} @#{resource} ||= Sfn::ResourceCollection.new(#{class_name}, self.satisfaction, '#{[:url]}') end EOS end |