Module: Elasticated::Mixins::Clonable

Included in:
Aggregation, BooleanClause, Conditions::StandardCondition, Query, QueryAggregations, QueryConditions, RangesBuilder
Defined in:
lib/elasticated/mixins/clonable.rb

Instance Method Summary collapse

Instance Method Details

#==(other_entity) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/elasticated/mixins/clonable.rb', line 22

def ==(other_entity)
  other_entity.class == self.class &&
  instance_variables.all? do |instance_variable|
    next true if instance_variable == :@_subaggregations # Subaggregated
    value = instance_variable_get instance_variable
    other_value = other_entity.instance_variable_get instance_variable
    case other_value.class
    when Array
      compare_arrays value, other_value
    else
      other_value == value
    end
  end
end

#cloneObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/elasticated/mixins/clonable.rb', line 5

def clone
  ret = super
  instance_variables.each do |instance_variable|
    value = instance_variable_get instance_variable
    value = case value.class
    when Array
      clone_array value
    when Hash
      Helpers.hash_deep_dup value
    else
      value.clone
    end
    ret.instance_variable_set instance_variable, value
  end
  ret
end