Module: Mongrep::Model::VirtusExtensions

Included in:
Mongrep::Model
Defined in:
lib/mongrep/model.rb

Overview

Extensions to Virtus models

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ true, false

Checks for equality between self and other

Parameters:

  • other (Model)

    Another Model

Returns:

  • (true)

    If other has equal attributes

  • (false)

    otherwise



124
125
126
127
# File 'lib/mongrep/model.rb', line 124

def ==(other)
  return false unless other.is_a?(self.class)
  to_h == other.to_h
end

#to_hHash

Converts the model into a hash. This supports nested models.

Returns:

  • (Hash)

    A Hash representation of the models attributes



114
115
116
117
118
# File 'lib/mongrep/model.rb', line 114

def to_h
  result = {}
  super.each { |key, value| result[key] = hashify_value(value) }
  result
end