Class: Superstore::BelongsTo::Reflection

Inherits:
Object
  • Object
show all
Defined in:
lib/superstore/belongs_to/reflection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, name, options) ⇒ Reflection

Returns a new instance of Reflection.



5
6
7
# File 'lib/superstore/belongs_to/reflection.rb', line 5

def initialize(model, name, options)
  @model, @name, @options = model, name, options
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



4
5
6
# File 'lib/superstore/belongs_to/reflection.rb', line 4

def model
  @model
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/superstore/belongs_to/reflection.rb', line 4

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/superstore/belongs_to/reflection.rb', line 4

def options
  @options
end

Instance Method Details

#class_nameObject



33
34
35
# File 'lib/superstore/belongs_to/reflection.rb', line 33

def class_name
  options[:class_name] || name.to_s.camelize
end

#default_primary_key?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/superstore/belongs_to/reflection.rb', line 21

def default_primary_key?
  primary_key == "id"
end

#foreign_keyObject



13
14
15
# File 'lib/superstore/belongs_to/reflection.rb', line 13

def foreign_key
  options[:foreign_key] || "#{name}_id"
end

#instance_variable_nameObject



9
10
11
# File 'lib/superstore/belongs_to/reflection.rb', line 9

def instance_variable_name
  "@#{name}"
end

#polymorphic?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/superstore/belongs_to/reflection.rb', line 29

def polymorphic?
  options[:polymorphic]
end

#polymorphic_columnObject



25
26
27
# File 'lib/superstore/belongs_to/reflection.rb', line 25

def polymorphic_column
  "#{name}_type"
end

#primary_keyObject



17
18
19
# File 'lib/superstore/belongs_to/reflection.rb', line 17

def primary_key
  options[:primary_key] || "id"
end