Module: Elasticsearch::Persistence::SpawnMethods

Included in:
Relation
Defined in:
lib/elasticsearch/persistence/relation/spawn_methods.rb

Instance Method Summary collapse

Instance Method Details

#except(*skips) ⇒ Object

Removes from the query the condition(s) specified in skips.

Post.order('id asc').except(:order)                  # discards the order condition
Post.where('id > 10').order('id asc').except(:where) # discards the where condition but keeps the order


36
37
38
# File 'lib/elasticsearch/persistence/relation/spawn_methods.rb', line 36

def except(*skips)
  relation_with values.except(*skips)
end

#merge(other) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/elasticsearch/persistence/relation/spawn_methods.rb', line 13

def merge(other)
  if other.is_a?(Array)
    to_a & other
  elsif other
    spawn.merge!(other)
  else
    self
  end
end

#merge!(other) ⇒ Object

:nodoc:



23
24
25
26
27
28
29
30
# File 'lib/elasticsearch/persistence/relation/spawn_methods.rb', line 23

def merge!(other) # :nodoc:
  if !other.is_a?(Relation) && other.respond_to?(:to_proc)
    instance_exec(&other)
  else
    klass = other.is_a?(Hash) ? Relation::HashMerger : Relation::Merger
    klass.new(self, other).merge
  end
end

#only(*onlies) ⇒ Object

Removes any condition from the query other than the one(s) specified in onlies.

Post.order('id asc').only(:where)         # discards the order condition
Post.order('id asc').only(:where, :order) # uses the specified order


44
45
46
47
48
49
# File 'lib/elasticsearch/persistence/relation/spawn_methods.rb', line 44

def only(*onlies)
  if onlies.any? { |o| o == :where }
    onlies << :bind
  end
  relation_with values.slice(*onlies)
end

#spawnObject



9
10
11
# File 'lib/elasticsearch/persistence/relation/spawn_methods.rb', line 9

def spawn
  clone
end