Class: Vault::Scoping::Scope

Inherits:
Object
  • Object
show all
Includes:
Finders
Defined in:
lib/vault/scoping.rb

Direct Known Subclasses

Associations::HasManyProxy

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Finders

#[], #all

Constructor Details

#initialize(model, conditions) ⇒ Scope

Returns a new instance of Scope.



32
33
34
35
# File 'lib/vault/scoping.rb', line 32

def initialize(model, conditions)
  @model = model
  @conditions = conditions.stringify_keys
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/vault/scoping.rb', line 41

def method_missing(method, *)
  if model_has_scope?(method)
    merge(model.scopes[method.to_s])
  else
    super
  end
end

Instance Attribute Details

#conditionsObject (readonly)

Returns the value of attribute conditions.



30
31
32
# File 'lib/vault/scoping.rb', line 30

def conditions
  @conditions
end

#modelObject (readonly)

Returns the value of attribute model.



30
31
32
# File 'lib/vault/scoping.rb', line 30

def model
  @model
end

Instance Method Details

#respond_to?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/vault/scoping.rb', line 49

def respond_to?(method, include_private=false)
  model_has_scope?(method) || super
end

#storeObject



37
38
39
# File 'lib/vault/scoping.rb', line 37

def store
  @store ||= @model.store.filter(conditions)
end