Module: MongoModel::Scope::SpawnMethods

Included in:
MongoModel::Scope
Defined in:
lib/mongomodel/support/scope/spawn_methods.rb

Instance Method Summary collapse

Instance Method Details

#except(*exceptions) ⇒ Object


22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mongomodel/support/scope/spawn_methods.rb', line 22

def except(*exceptions)
  result = self.class.new(klass)

  MULTI_VALUE_METHODS.each do |method|
    result.send(:"#{method}_values=", send(:"#{method}_values")) unless exceptions.include?(method)
  end

  SINGLE_VALUE_METHODS.each do |method|
    result.send(:"#{method}_value=", send(:"#{method}_value")) unless exceptions.include?(method)
  end

  result
end

#merge(scope) ⇒ Object


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/mongomodel/support/scope/spawn_methods.rb', line 4

def merge(scope)
  result = clone

  MULTI_VALUE_METHODS.each do |method|
    values = send(:"#{method}_values") + scope.send(:"#{method}_values")
    result.send(:"#{method}_values=", values.uniq)
  end

  SINGLE_VALUE_METHODS.each do |method|
    value = scope.send(:"#{method}_value")
    result.send(:"#{method}_value=", value) if value
  end

  result.on_load_proc = scope.on_load_proc

  result
end