Class: Slipcover::Document
- Inherits:
-
Object
- Object
- Slipcover::Document
show all
- Defined in:
- lib/slipcover/document.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(database_name, attributes = {}) ⇒ Document
Returns a new instance of Document.
6
7
8
9
10
|
# File 'lib/slipcover/document.rb', line 6
def initialize(database_name, attributes={})
@database_name = database_name
self.attributes = attributes.symbolize_keys
set_intrinsic_values
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
3
4
5
|
# File 'lib/slipcover/document.rb', line 3
def attributes
@attributes
end
|
#database_name ⇒ Object
Returns the value of attribute database_name.
4
5
6
|
# File 'lib/slipcover/document.rb', line 4
def database_name
@database_name
end
|
#id ⇒ Object
Returns the value of attribute id.
3
4
5
|
# File 'lib/slipcover/document.rb', line 3
def id
@id
end
|
#rev ⇒ Object
Returns the value of attribute rev.
3
4
5
|
# File 'lib/slipcover/document.rb', line 3
def rev
@rev
end
|
Instance Method Details
#database ⇒ Object
48
49
50
|
# File 'lib/slipcover/document.rb', line 48
def database
@database ||= Slipcover::Database.new(database_name)
end
|
#delete ⇒ Object
34
35
36
37
38
39
40
41
|
# File 'lib/slipcover/document.rb', line 34
def delete
http_adapter.delete("#{url}?rev=#{rev}")
set_intrinsic_values({})
nullify_intrinsic_attributes
true
rescue Exception => e
false
end
|
#http_adapter ⇒ Object
14
15
16
|
# File 'lib/slipcover/document.rb', line 14
def http_adapter
@http_adapter ||= HttpAdapter.new
end
|
#save ⇒ Object
21
22
23
24
25
26
|
# File 'lib/slipcover/document.rb', line 21
def save
http_method = id ? :put : :post
doc_url = id ? url : database.url
response = send(http_method, doc_url, attributes_for_save)
set_intrinsic_values(response)
end
|
#url ⇒ Object
43
44
45
46
|
# File 'lib/slipcover/document.rb', line 43
def url
raise ArgumentError.new('no document id') unless id
"#{database.url}/#{CGI::escape(id)}"
end
|