Class: RailsOptimizer::Reflection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner, name) ⇒ Reflection

Returns a new instance of Reflection.



5
6
7
8
# File 'lib/rails_optimizer/reflection.rb', line 5

def initialize(owner, name)
	@owner = owner
	@name = name
end

Instance Attribute Details

#foreign_keyObject

Returns the value of attribute foreign_key.



3
4
5
# File 'lib/rails_optimizer/reflection.rb', line 3

def foreign_key
  @foreign_key
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/rails_optimizer/reflection.rb', line 3

def name
  @name
end

#ownerObject

Returns the value of attribute owner.



3
4
5
# File 'lib/rails_optimizer/reflection.rb', line 3

def owner
  @owner
end

Instance Method Details

#foreign_typeObject



26
27
28
# File 'lib/rails_optimizer/reflection.rb', line 26

def foreign_type
	reflection.foreign_type
end

#klassObject



10
11
12
13
14
15
16
# File 'lib/rails_optimizer/reflection.rb', line 10

def klass
	if reflection.polymorphic?
		owner.read_attribute(foreign_type).constantize
	else
		reflection.klass
	end
end

#reflectionObject



22
23
24
# File 'lib/rails_optimizer/reflection.rb', line 22

def reflection
	@reflection ||= owner._reflections[name]
end

#scopeObject



18
19
20
# File 'lib/rails_optimizer/reflection.rb', line 18

def scope
	reflection.scope
end