Module: CouchRest::Model::DatabaseMethod

Extended by:
ActiveSupport::Concern
Included in:
Rotation
Defined in:
lib/couchrest/model/database_method.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object Also known as: eql?

The normal CouchRest::Model::Base comparison checks if the model’s database objects are the same. That is not good for use here, since the objects will always be different. Instead, we compare the string that each database evaluates to.



42
43
44
45
46
47
48
49
# File 'lib/couchrest/model/database_method.rb', line 42

def ==(other)
  return false unless other.is_a?(Base)
  if id.nil? && other.id.nil?
    to_hash == other.to_hash
  else
    id == other.id && database.to_s == other.database.to_s
  end
end

#databaseObject



16
17
18
19
20
21
22
# File 'lib/couchrest/model/database_method.rb', line 16

def database
  if self.class.database_method
    self.class.server.database(call_database_method)
  else
    self.class.database
  end
end

#database!Object



24
25
26
27
28
29
30
# File 'lib/couchrest/model/database_method.rb', line 24

def database!
  if self.class.database_method
    self.class.server.database!(call_database_method)
  else
    self.class.database!
  end
end

#database_exists?(db_name) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/couchrest/model/database_method.rb', line 32

def database_exists?(db_name)
  self.class.database_exists?(db_name)
end