Module: CouchRest::Model::DatabaseMethod::ClassMethods
- Defined in:
- lib/couchrest/model/database_method.rb
Instance Method Summary collapse
-
#choose_database(*args) ⇒ Object
same as database(), but allows for an argument that gets passed through to database method.
- #database ⇒ Object
- #database! ⇒ Object
- #database_exists?(name) ⇒ Boolean
- #database_method(method = nil) ⇒ Object (also: #use_database_method)
- #db_name_with_prefix(name) ⇒ Object
Instance Method Details
#choose_database(*args) ⇒ Object
same as database(), but allows for an argument that gets passed through to database method.
96 97 98 |
# File 'lib/couchrest/model/database_method.rb', line 96 def choose_database(*args) self.server.database(call_database_method(*args)) end |
#database ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/couchrest/model/database_method.rb', line 73 def database if database_method if !self.respond_to?(database_method, true) raise ArgumentError.new("Incorrect argument to database_method(): no such method '#{method}' found in class #{self}.") end self.server.database(call_database_method) else @database ||= prepare_database(super) end end |
#database! ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/couchrest/model/database_method.rb', line 84 def database! if database_method self.server.database!(call_database_method) else @database ||= prepare_database(super) end end |
#database_exists?(name) ⇒ Boolean
105 106 107 108 109 110 111 112 113 |
# File 'lib/couchrest/model/database_method.rb', line 105 def database_exists?(name) name = db_name_with_prefix(name) begin CouchRest.head "#{self.server.uri}/#{name}" return true rescue CouchRest::NotFound return false end end |
#database_method(method = nil) ⇒ Object Also known as: use_database_method
65 66 67 68 69 70 |
# File 'lib/couchrest/model/database_method.rb', line 65 def database_method(method = nil) if method @database_method = method end @database_method end |
#db_name_with_prefix(name) ⇒ Object
100 101 102 103 |
# File 'lib/couchrest/model/database_method.rb', line 100 def db_name_with_prefix(name) conf = self.send(:connection_configuration) [conf[:prefix], name, conf[:suffix]].reject{|i|i.to_s.empty?}.join(conf[:join]) end |