Class: AssociationScope::Scope

Inherits:
Object
  • Object
show all
Defined in:
lib/association_scope/scope.rb,
lib/association_scope/scope/has_one_reflection.rb,
lib/association_scope/scope/through_reflection.rb,
lib/association_scope/scope/has_many_reflection.rb,
lib/association_scope/scope/belongs_to_reflection.rb,
lib/association_scope/scope/has_and_belongs_to_many_reflection.rb

Defined Under Namespace

Classes: BelongsToReflection, HasAndBelongsToManyReflection, HasManyReflection, HasOneReflection, ThroughReflection

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, association) ⇒ Scope

Returns a new instance of Scope.



7
8
9
10
# File 'lib/association_scope/scope.rb', line 7

def initialize(model, association)
  @model = model
  @association = association
end

Instance Attribute Details

#associationObject (readonly)

Returns the value of attribute association.



5
6
7
# File 'lib/association_scope/scope.rb', line 5

def association
  @association
end

#modelObject (readonly)

Returns the value of attribute model.



5
6
7
# File 'lib/association_scope/scope.rb', line 5

def model
  @model
end

Class Method Details

.inject_scopes(model, reflections) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/association_scope/scope.rb', line 12

def self.inject_scopes(model, reflections)
  model.reflections.slice(*reflections).each do |association, details|
    scope_type = details.class.to_s.split("::").last

    "AssociationScope::Scope::#{scope_type}".constantize.new(model, association).apply
  end
end