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

Version Path
active_mocker-1.3.2 lib/active_mocker/active_record/relationships.rb
active_mocker-1.3.1 lib/active_mocker/active_record/relationships.rb
active_mocker-1.3 lib/active_mocker/active_record/relationships.rb
active_mocker-1.2.4 lib/active_mocker/active_record/relationships.rb
active_mocker-1.2.3 lib/active_mocker/active_record/relationships.rb
active_mocker-1.2 lib/active_mocker/active_record/relationships.rb
active_mocker-1.2.pre.11 lib/active_mocker/active_record/relationships.rb
active_mocker-1.2.pre.10 lib/active_mocker/active_record/relationships.rb
active_mocker-1.2.pre.9 lib/active_mocker/active_record/relationships.rb
active_mocker-1.2.pre.8 lib/active_mocker/active_record/relationships.rb
active_mocker-1.2.pre.7 lib/active_mocker/active_record/relationships.rb
active_mocker-1.2.pre.6 lib/active_mocker/active_record/relationships.rb
active_mocker-1.2.pre.5 lib/active_mocker/active_record/relationships.rb
active_mocker-1.2.pre.4 lib/active_mocker/active_record/relationships.rb
active_mocker-1.2.pre.3 lib/active_mocker/active_record/relationships.rb
active_mocker-1.2.pre.2 lib/active_mocker/active_record/relationships.rb
active_mocker-1.2.pre.1 lib/active_mocker/active_record/relationships.rb
active_mocker-1.2.pre lib/active_mocker/active_record/relationships.rb
active_mocker-1.1.23 lib/active_mocker/active_record/relationships.rb
active_mocker-1.1.22 lib/active_mocker/active_record/relationships.rb