Class: RailsOptimizer::Association

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

Direct Known Subclasses

BelongsTo, HasOne

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner, name, *args) ⇒ Association

Returns a new instance of Association.



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

def initialize(owner, name, *args)
	@owner = owner
	@name  = name.to_s
	@args  = *args
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



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

def args
  @args
end

#klassObject

Returns the value of attribute klass.



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

def klass
  @klass
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#ownerObject

Returns the value of attribute owner.



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

def owner
  @owner
end

#reflectionObject

Returns the value of attribute reflection.



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

def reflection
  @reflection
end

Instance Method Details

#get_targetObject



23
24
25
26
# File 'lib/rails_optimizer/association.rb', line 23

def get_target
	return owner.association(name.to_sym).target if owner.association(name.to_sym).loaded?
	yield if block_given?
end

#reflection_scopeObject



19
20
21
# File 'lib/rails_optimizer/association.rb', line 19

def reflection_scope
	reflection.scope
end