Module: Couchbase::ActiveModel
- Included in:
- Model
- Defined in:
- lib/couchbase/active_model.rb
Instance Method Summary collapse
-
#==(other) ⇒ Object
Public: Overrides == to compare via class and entity id.
-
#eql?(other) ⇒ Boolean
Public: Overrides eql? to use == in the comparison.
-
#hash ⇒ Object
Public: Hashes our unique key instead of the entire object.
-
#to_model ⇒ Object
Public: Allows for access to ActiveModel functionality.
Instance Method Details
#==(other) ⇒ Object
Public: Overrides == to compare via class and entity id.
other - Another object to compare to
Example
movie = Movie.find(1234)
movie.to_key
# => 'movie-1234'
Returns a string representing the unique key.
65 66 67 |
# File 'lib/couchbase/active_model.rb', line 65 def ==(other) hash == other.hash end |
#eql?(other) ⇒ Boolean
Public: Overrides eql? to use == in the comparison.
other - Another object to compare to
Returns a boolean.
50 51 52 |
# File 'lib/couchbase/active_model.rb', line 50 def eql?(other) self == other end |
#hash ⇒ Object
Public: Hashes our unique key instead of the entire object. Ruby normally hashes an object to be used in comparisons. In our case we may have two techincally different objects referencing the same entity id, so we will hash just the class and id (via to_key) to compare so we get the expected result
Returns a string representing the unique key.
41 42 43 |
# File 'lib/couchbase/active_model.rb', line 41 def hash to_param.hash end |
#to_model ⇒ Object
Public: Allows for access to ActiveModel functionality.
Returns self.
30 31 32 |
# File 'lib/couchbase/active_model.rb', line 30 def to_model self end |