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.
30
31
32
33
|
# File 'lib/couch_rest_adapter.rb', line 30
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
75
76
77
78
79
80
81
82
83
|
# File 'lib/couch_rest_adapter.rb', line 75
def method_missing method, *args, &block
if attribute_methods.include? method.to_s
read_write method, args.first
elsif method.to_s =~ /^(.+)=$/
read_write method, args.first
else
super
end
end
|
Class Method Details
.all ⇒ Object
35
36
37
|
# File 'lib/couch_rest_adapter.rb', line 35
def self.all
query_view('all', default_design_doc)
end
|
.all_by_type ⇒ Object
39
40
41
|
# File 'lib/couch_rest_adapter.rb', line 39
def self.all_by_type
query_view('by_type', default_design_doc)
end
|
.find(doc_id) ⇒ Object
43
44
45
|
# File 'lib/couch_rest_adapter.rb', line 43
def self.find doc_id
new database.get( doc_id.namespace_me(object_name) ).to_hash
end
|
.method_missing(method, *args, &block) ⇒ Object
55
56
57
58
59
60
61
|
# File 'lib/couch_rest_adapter.rb', line 55
def self.method_missing method, *args, &block
if method.to_s =~ /^find_by_(.+)$/
find_by_attribute($1, args.first, default_design_doc)
else
super
end
end
|
.respond_to?(method) ⇒ Boolean
51
52
53
|
# File 'lib/couch_rest_adapter.rb', line 51
def self.respond_to? method
(method.to_s =~ /^find_by_.*$/) ? true : super
end
|
.use_default_database ⇒ Object
47
48
49
|
# File 'lib/couch_rest_adapter.rb', line 47
def self.use_default_database
use_database CouchRest.database(full_path)
end
|
Instance Method Details
#persisted? ⇒ Boolean
85
86
87
|
# File 'lib/couch_rest_adapter.rb', line 85
def persisted?
true
end
|
#read_attribute_for_validation(key) ⇒ Object
89
90
91
|
# File 'lib/couch_rest_adapter.rb', line 89
def read_attribute_for_validation(key)
self[key.to_s]
end
|
#save(bulk = false) ⇒ Object
63
64
65
66
67
68
|
# File 'lib/couch_rest_adapter.rb', line 63
def save bulk = false
return false if invalid?
return false unless run_callbacks(:save)
_set_id_and_namespace
super bulk
end
|
#save!(bulk = false) ⇒ Object