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, options={})
  class_name = options[:class_name] || "Sfn::#{resource.to_s.classify}"
  parent_id = options[:parent_attribute] || "#{resource}_id"
  eval "    def \#{resource}\n      @\#{resource} ||= \#{class_name}.new(\#{parent_id}, self.satisfaction)\n    end\n  EOS\nend\n"

#has_many(resource, options = {}) ⇒ Object



2
3
4
5
6
7
8
9
# File 'lib/satisfaction/associations.rb', line 2

def has_many(resource, options={})
  class_name = options[:class_name] || "Sfn::#{resource.to_s.classify}"
  eval "    def \#{resource}\n      @\#{resource} ||= Sfn::ResourceCollection.new(\#{class_name}, self.satisfaction, '\#{options[:url]}')\n    end\n  EOS\nend\n"