cushion 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,8 @@
1
+ Copyright (c) 2011 Helge Rausch <helge@rausch.io>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8
+
@@ -3,7 +3,7 @@ $:.push File.expand_path('../lib', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'cushion'
6
- s.version = '0.0.4'
6
+ s.version = '0.0.5'
7
7
  s.authors = ['Helge Rausch']
8
8
  s.email = ['helge@rausch.io']
9
9
  s.homepage = 'https://github.com/tsujigiri/cushion'
@@ -8,6 +8,9 @@ require 'active_support/core_ext/string/inflections'
8
8
  require 'active_support/core_ext/object'
9
9
 
10
10
  class Cushion < HashWithIndifferentAccess
11
+
12
+ attr_accessor :id
13
+
11
14
  def initialize(*args, &block)
12
15
  if args[0].is_a?(String)
13
16
  uri = args.shift
@@ -31,8 +34,8 @@ class Cushion < HashWithIndifferentAccess
31
34
  self.class.server [ $2 || 'localhost', $4 ? $4.to_i : 5984 ]
32
35
  @document_location = {}
33
36
  @document_location[:database] = $5
34
- @id = $7
35
- @document_location[:uri] = "/#{@document_location[:database]}/#{@id}" if @id
37
+ self.id = $7
38
+ @document_location[:uri] = "/#{@document_location[:database]}/#{id}" if id
36
39
  end
37
40
 
38
41
  def self.create_database uri
@@ -52,27 +55,26 @@ class Cushion < HashWithIndifferentAccess
52
55
  @revision
53
56
  end
54
57
 
55
- def id
56
- @id
57
- end
58
-
59
58
  def load
60
- replace(self.class.get(document_location[:uri]))
59
+ doc = self.class.get(document_location[:uri])
60
+ self.id = doc.delete('_id')
61
+ @revision = doc.delete('_rev')
62
+ replace doc
61
63
  end
62
64
 
63
65
  def save
64
66
  unless self.class.database_created
65
67
  self.class.create_database('/' << document_location[:database])
66
68
  end
67
- if @id.present?
69
+ if id.present?
68
70
  copy = @revision ? self.merge(_rev: @revision) : self.dup
69
71
  response = self.class.put(document_location[:uri], copy)
70
72
  @revision = response['rev']
71
73
  else
72
74
  response = self.class.post('/' << document_location[:database], self)
73
- @id = response['id']
75
+ self.id = response['id']
74
76
  @revision = response['rev']
75
- @document_location[:uri] = "/#{@document_location[:database]}/#{@id}"
77
+ @document_location[:uri] = "/#{@document_location[:database]}/#{id}"
76
78
  end
77
79
  @revision
78
80
  end
@@ -16,6 +16,8 @@ class CushionTest < Test::Unit::TestCase
16
16
  doc = Cushion.new(@doc_uri)
17
17
  assert_equal nil, doc[:foo]
18
18
  doc.load
19
+ assert_nil doc[:_id]
20
+ assert_nil doc[:_rev]
19
21
  assert_equal "bar", doc[:foo]
20
22
  assert_equal 'test_doc', @doc.id
21
23
  new_revision = revision.to_i + 1
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cushion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-05 00:00:00.000000000 Z
12
+ date: 2011-11-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: test-unit
16
- requirement: &11099760 !ruby/object:Gem::Requirement
16
+ requirement: &17592060 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *11099760
24
+ version_requirements: *17592060
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: shoulda
27
- requirement: &11099020 !ruby/object:Gem::Requirement
27
+ requirement: &17591380 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *11099020
35
+ version_requirements: *17591380
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: ruby-debug19
38
- requirement: &11098400 !ruby/object:Gem::Requirement
38
+ requirement: &17590700 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *11098400
46
+ version_requirements: *17590700
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: active_support
49
- requirement: &11097680 !ruby/object:Gem::Requirement
49
+ requirement: &17590040 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *11097680
57
+ version_requirements: *17590040
58
58
  description: A Hash with indifferent access and CouchDB persistence layer
59
59
  email:
60
60
  - helge@rausch.io
@@ -64,6 +64,7 @@ extra_rdoc_files: []
64
64
  files:
65
65
  - .gitignore
66
66
  - Gemfile
67
+ - LICENSE.txt
67
68
  - README.md
68
69
  - Rakefile
69
70
  - cushion.gemspec