Sha256: ab6052340e4320cbd744b24b7cbd28f777aca435b43dd830392a0e2f228f4795
Contents?: true
Size: 983 Bytes
Versions: 22
Compression:
Stored size: 983 Bytes
Contents
require 'ostruct' module Relationships def self.included(base) base.extend(ClassMethods) end module ClassMethods attr_reader :has_and_belongs_to_many, :belongs_to, :has_one, :has_many end def relationships OpenStruct.new({has_many: @has_many ||= [], has_one: @has_one ||= [], belongs_to: @belongs_to ||= [], has_and_belongs_to_many: @has_and_belongs_to_many ||= []}) end def single_relationships belongs_to + has_one end def collections has_and_belongs_to_many + has_many end private def has_many(*args) @has_many ||= [] @has_many.push [args.first] end def has_one(*args) @has_one ||= [] @has_one.push [args.first] end def belongs_to(*args) @belongs_to ||= [] @belongs_to.push [args.first] end def has_and_belongs_to_many(*args) @has_and_belongs_to_many ||= [] @has_and_belongs_to_many.push [args.first] end end
Version data entries
22 entries across 22 versions & 1 rubygems