Class: SampleModels::Model::Association

Inherits:
Delegator
  • Object
show all
Defined in:
lib/sample_models/model.rb

Instance Method Summary collapse

Constructor Details

#initialize(assoc) ⇒ Association

Returns a new instance of Association.



56
57
58
# File 'lib/sample_models/model.rb', line 56

def initialize(assoc)
  @assoc = assoc
end

Instance Method Details

#__getobj__Object



60
61
62
# File 'lib/sample_models/model.rb', line 60

def __getobj__
  @assoc
end

#belongs_to?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/sample_models/model.rb', line 64

def belongs_to?
  @assoc.macro == :belongs_to
end

#foreign_keyObject



68
69
70
71
72
73
74
# File 'lib/sample_models/model.rb', line 68

def foreign_key
  if @assoc.respond_to?(:foreign_key)
    @assoc.foreign_key
  else
    @assoc.primary_key_name
  end
end

#foreign_typeObject



76
77
78
79
80
81
82
# File 'lib/sample_models/model.rb', line 76

def foreign_type
  if @assoc.respond_to?(:foreign_type)
    @assoc.foreign_type
  else
    @assoc.instance_variable_get(:@options)[:foreign_type]
  end
end

#has_many?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/sample_models/model.rb', line 84

def has_many?
  @assoc.macro == :has_many
end

#polymorphic?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/sample_models/model.rb', line 88

def polymorphic?
  @assoc.options[:polymorphic]
end