Class: ScopeChain::Chain

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

Defined Under Namespace

Classes: ConflictedExistenceError

Constant Summary collapse

[:select, :where, :includes, :order, :find, :sum, :new, :create, :create!, :limit, :joins]
ALIASES =
{}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass) {|_self| ... } ⇒ Chain

Returns a new instance of Chain.

Yields:

  • (_self)

Yield Parameters:



62
63
64
65
66
67
68
69
70
71
# File 'lib/scope_chain.rb', line 62

def initialize(klass, &block)
  self.klass = klass
  @expectations = []
  @exists_condition = false

  link_manual_scopes
  link_named_scopes

  yield self if block_given?
end

Instance Attribute Details

#klassObject

Returns the value of attribute klass.



61
62
63
# File 'lib/scope_chain.rb', line 61

def klass
  @klass
end

Instance Method Details

#all(returned) ⇒ Object



85
86
87
88
# File 'lib/scope_chain.rb', line 85

def all(returned)
  add_link :all
  returns returned
end

#exists!Object



97
98
99
# File 'lib/scope_chain.rb', line 97

def exists!
  set_exists true
end

#missing!Object



101
102
103
# File 'lib/scope_chain.rb', line 101

def missing!
  set_exists false
end

#returns(object) ⇒ Object



90
91
92
93
94
95
# File 'lib/scope_chain.rb', line 90

def returns(object)
  # DON'T LOOK
  @expectations.last.instance_variable_set(:@return_values, Mocha::ReturnValues.build(object))
  
  self
end