Class: CouchRestAdapter::Base
- Inherits:
-
CouchRest::Document
- Object
- CouchRest::Document
- CouchRestAdapter::Base
show all
- Extended by:
- ActiveModel::Naming
- Includes:
- ActiveModel::Conversion, ActiveModel::Validations, ActiveSupport::Callbacks, AttributeMethod, DbConfig, DocumentManagement, QueryViews
- Defined in:
- lib/couch_rest_adapter.rb
Constant Summary
DocumentManagement::UUID_DOC
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from QueryViews
included
#_set_id_and_namespace, included, #query, #set_id, #uuids
Methods included from DbConfig
included
#attribute_methods, #base_id, #method_without_equals, #read_value, #read_write, #write_value, #writer?
Constructor Details
#initialize(attributes = {}) ⇒ Base
Returns a new instance of Base.
29
30
31
32
|
# File 'lib/couch_rest_adapter.rb', line 29
def initialize attributes = {}
raise NotImplementedError if abstract?
super attributes
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
69
70
71
72
73
74
75
|
# File 'lib/couch_rest_adapter.rb', line 69
def method_missing method, *args, &block
if attribute_methods.include? method.to_s
read_write method, args.first
else
super
end
end
|
Class Method Details
.all ⇒ Object
34
35
36
|
# File 'lib/couch_rest_adapter.rb', line 34
def self.all
query_view('all', default_design_doc)
end
|
.all_by_type ⇒ Object
38
39
40
|
# File 'lib/couch_rest_adapter.rb', line 38
def self.all_by_type
query_view('by_type', default_design_doc)
end
|
.find(doc_id) ⇒ Object
42
43
44
|
# File 'lib/couch_rest_adapter.rb', line 42
def self.find doc_id
new database.get( doc_id.namespace_me(object_name) ).to_hash
end
|
.method_missing(method, *args, &block) ⇒ Object
54
55
56
57
58
59
60
|
# File 'lib/couch_rest_adapter.rb', line 54
def self.method_missing method, *args, &block
if method.to_s =~ /^find_by_(.+)$/
find_by_attribute($1, args.first)
else
super
end
end
|
.respond_to?(method) ⇒ Boolean
50
51
52
|
# File 'lib/couch_rest_adapter.rb', line 50
def self.respond_to? method
(method.to_s =~ /^find_by_.*$/) ? true : super
end
|
.use_default_database ⇒ Object
46
47
48
|
# File 'lib/couch_rest_adapter.rb', line 46
def self.use_default_database
use_database CouchRest.database(full_path)
end
|
Instance Method Details
#persisted? ⇒ Boolean
77
78
79
|
# File 'lib/couch_rest_adapter.rb', line 77
def persisted?
true
end
|
#read_attribute_for_validation(key) ⇒ Object
81
82
83
|
# File 'lib/couch_rest_adapter.rb', line 81
def read_attribute_for_validation(key)
self[key.to_s]
end
|
#save ⇒ Object
62
63
64
65
66
67
|
# File 'lib/couch_rest_adapter.rb', line 62
def save
return false if invalid?
return false unless run_callbacks(:save)
_set_id_and_namespace
super
end
|