Sha256: fdf2b7ee8bed1b78a6221c64f11651d3d98713c04c215de9349d08ce95573e82

Contents?: true

Size: 620 Bytes

Versions: 10

Compression:

Stored size: 620 Bytes

Contents

module Associations
  def has_many(resource, options={})
    class_name = options[:class_name] || "Sfn::#{resource.to_s.classify}"
    eval <<-EOS
      def #{resource}
        @#{resource} ||= Sfn::ResourceCollection.new(#{class_name}, self.satisfaction, '#{options[:url]}')
      end
    EOS
  end
  
  def belongs_to(resource, options={})
    class_name = options[:class_name] || "Sfn::#{resource.to_s.classify}"
    parent_id = options[:parent_attribute] || "#{resource}_id"
    eval <<-EOS
      def #{resource}
        @#{resource} ||= #{class_name}.new(#{parent_id}, self.satisfaction)
      end
    EOS
  end
end

Version data entries

10 entries across 10 versions & 3 rubygems

Version Path
nullstyle-ruby-satisfaction-0.4.0 lib/satisfaction/associations.rb
pius-ruby-satisfaction-0.3.0 lib/satisfaction/associations.rb
pius-ruby-satisfaction-0.4.0 lib/satisfaction/associations.rb
pius-ruby-satisfaction-0.4.1 lib/satisfaction/associations.rb
pius-ruby-satisfaction-0.4.2 lib/satisfaction/associations.rb
pius-ruby-satisfaction-0.4.3 lib/satisfaction/associations.rb
pius-ruby-satisfaction-0.4.4 lib/satisfaction/associations.rb
ruby-satisfaction-0.6.1 lib/satisfaction/associations.rb
ruby-satisfaction-0.3.0 lib/satisfaction/associations.rb
ruby-satisfaction-0.4.0 lib/satisfaction/associations.rb