Module: Elasticated::Clonable

Instance Method Summary collapse

Instance Method Details

#==(other_entity) ⇒ Object



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

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



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

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