couch_potato 1.7.0 → 1.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 30f6ff4ae48fa386a7c210a840f7bc2e5504e812
4
- data.tar.gz: e3cc6d272dab7679b7766bb96a0b9cdf557ad2b3
3
+ metadata.gz: 7afdf21007e24fddeb4df04575ea8ee1062e4b29
4
+ data.tar.gz: 815dc0bd6c4a35a2770a28aff57e1901da66fc62
5
5
  SHA512:
6
- metadata.gz: d8ec9aba049750bc2d18053ba05633d4a593d6fd7e44f002746dd629d2fd8c4ad6297228f549b9653d60ad9a54e410ad6334aa6356c1d3a2d6825b102241cb43
7
- data.tar.gz: 1b9106d793d8874f32345492ad25aac13a1a3817df7af885d3f084117c7c9a8a34f7fbcd3eca834ee0b62cb4f2d20c9b86fbcdb015979e20712475dd0b9f383e
6
+ metadata.gz: d0aedb24caecaac662bd3758683b74cb723d3361f0b25ad55463c102dfe6242b62a877337fa0c43091a4d52f0220371fb227fea2307c0fcc631d4767b5ae807a
7
+ data.tar.gz: fdbdea5fa1179b9026480fd128537e36e7b61edd385edbaf87899725a7af63540fddae8bd747471739307e1b6de4695e2e75c61fcb686402412f85d182c86d6c
@@ -1,16 +1,16 @@
1
+ language: ruby
1
2
  rvm:
2
- - 2.0.0
3
- - 2.1.2
4
- - 2.2.2
5
- - 2.3.0
6
- - jruby-9.0.1.0
7
- - rbx-2.5.8
3
+ - "2.2"
4
+ - "2.3.0"
5
+ - "jruby-9.0.5.0"
6
+ - "rbx-3.9"
8
7
  services:
9
8
  - couchdb
10
9
  gemfile:
11
10
  - gemfiles/active_support_4_0
12
11
  - gemfiles/active_support_4_1
13
12
  - gemfiles/active_support_4_2
13
+ - gemfiles/active_support_5_0
14
14
  before_install:
15
15
  gem install bundler --version 1.11.2
16
16
  before_script:
data/CHANGES.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## Changes
2
2
 
3
+ ### 1.7.1
4
+
5
+ * added support for properties of type Integer
6
+
3
7
  ### 1.7.0
4
8
 
5
9
  * added `_revisions` method that returns all available revisions of a document.
data/README.md CHANGED
@@ -27,11 +27,7 @@ Lastly Couch Potato aims to provide a seamless integration with Ruby on Rails, e
27
27
 
28
28
  ### Supported Environments
29
29
 
30
- * Ruby 2.0, 2.1, 2.2, Rubinius
31
- * CouchDB 1.6.0
32
- * ActiveSupport 4.0, 4.1, 4.2
33
-
34
- (Supported means I run the specs against those before releasing a new gem.)
30
+ Check travis.yml for supported Ruby/ActiveSupport versions.
35
31
 
36
32
  ### Installation
37
33
 
@@ -164,18 +160,18 @@ end
164
160
  ```
165
161
 
166
162
  In this case `Address` also implements `CouchPotato::Persistence` which means its JSON representation will be added to the user document.
167
- Couch Potato also has support for the basic types (right now `Fixnum`, `Date`, `Time` and `:boolean` are supported):
163
+ Couch Potato also has support for the basic types (right now `Integer`, `Date`, `Time` and `:boolean` are supported):
168
164
 
169
165
  ```ruby
170
166
  class User
171
167
  include CouchPotato::Persistence
172
168
 
173
- property :age, :type => Fixnum
169
+ property :age, :type => Integer
174
170
  property :receive_newsletter, :type => :boolean
175
171
  end
176
172
  ```
177
173
 
178
- With this in place when you set the user's age as a String (e.g. using an HTML form) it will be converted into a `Fixnum` automatically.
174
+ With this in place when you set the user's age as a String (e.g. using an HTML form) it will be converted into a `Integer` automatically.
179
175
 
180
176
 
181
177
  Properties can have a default value:
@@ -472,7 +468,7 @@ You can pass in your own view specifications by passing in `:type => MyViewSpecC
472
468
 
473
469
  ##### Digest view names
474
470
 
475
- If turned on, Couch Potato will append an MD5 digest of the map function to each view name. This makes sure (together with split_design_documents_per_view) that no views/design documents are ever updated. Instead, new ones are created. Since reindexing can take a long time once your database is larger, you want to avoid blocking your app while CouchDB is busy. Instead, you create a new view, warm it up, and only then start using it.
471
+ If turned on, Couch Potato will append an MD5 digest of the map function to each view name. This makes sure (together with split_design_documents_per_view) that no views/design documents are ever updated. Instead, new ones are created. Since reindexing can take a long time once your database is larger, you want to avoid blocking your app while CouchDB is busy. Instead, you create a new view, warm it up, and only then start using it.
476
472
 
477
473
  ##### Lists
478
474
 
@@ -630,7 +626,7 @@ class User
630
626
  include CouchPotato::Persistence
631
627
 
632
628
  property :name
633
- property :age, :type => Fixnum
629
+ property :age, :type => Integer
634
630
 
635
631
  view :by_name, :key => :name
636
632
  view :by_age, :key => :age
data/Rakefile CHANGED
@@ -24,7 +24,7 @@ task :spec do
24
24
  Rake::Task[:spec_unit].execute
25
25
  Rake::Task[:spec_functional].execute
26
26
  else
27
- %w(4_0 4_1 4_2).each do |version|
27
+ %w(4_0 4_1 4_2 5_0).each do |version|
28
28
  Bundler.with_clean_env do
29
29
  puts "Running tests with ActiveSupport #{version.sub('_', '.')}"
30
30
  sh "env BUNDLE_GEMFILE=gemfiles/active_support_#{version} bundle install"
@@ -12,13 +12,13 @@ Gem::Specification.new do |s|
12
12
  s.platform = Gem::Platform::RUBY
13
13
 
14
14
  s.add_dependency 'json', '~> 1.6'
15
- s.add_dependency 'couchrest', '~>2.0.0.rc3'
16
- s.add_dependency 'activemodel', '~> 4.0'
15
+ s.add_dependency 'couchrest', '~>2.0.0'
16
+ s.add_dependency 'activemodel', ['>= 4.0', '< 6.0']
17
17
 
18
18
  s.add_development_dependency 'rspec', '~>3.2.0'
19
19
  s.add_development_dependency 'timecop'
20
20
  s.add_development_dependency 'tzinfo'
21
- s.add_development_dependency 'rake'
21
+ s.add_development_dependency 'rake', '< 11.0'
22
22
 
23
23
  s.files = `git ls-files | grep -v "lib/couch_potato/rspec"`.split("\n")
24
24
  s.test_files = `git ls-files -- {test,spec,features}/* | grep -v rspec_matchers`.split("\n")
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'activemodel', '~>5.0.0'
4
+ gem 'rails', '~>5.0.0'
5
+ if RUBY_PLATFORM =~ /java/
6
+ gem 'therubyrhino'
7
+ else
8
+ gem 'therubyracer'
9
+ end
10
+
11
+ gemspec name: 'couch_potato', path: '..'
@@ -12,7 +12,7 @@ module CouchPotato
12
12
  Config.split_design_documents_per_view = false
13
13
  Config.digest_view_names = false
14
14
  Config.default_language = :javascript
15
- Config.database_host = "http://127.0.0.1:5984"
15
+ Config.database_host = 'http://127.0.0.1:5984'
16
16
 
17
17
  class NotFound < StandardError; end
18
18
  class Conflict < StandardError; end
@@ -25,19 +25,19 @@ module CouchPotato
25
25
 
26
26
  # Returns a database instance which you can then use to create objects and query views. You have to set the CouchPotato::Config.database_name before this works.
27
27
  def self.database
28
- @@__database ||= Database.new(self.couchrest_database)
28
+ Thread.current[:__couch_potato_database] ||= Database.new(couchrest_database)
29
29
  end
30
30
 
31
31
  # Returns the underlying CouchRest database object if you want low level access to your CouchDB. You have to set the CouchPotato::Config.database_name before this works.
32
32
  def self.couchrest_database
33
- @@__couchrest_database ||= CouchRest.database(full_url_to_database(CouchPotato::Config.database_name, CouchPotato::Config.database_host))
33
+ Thread.current[:__couchrest_database] ||= CouchRest.database(full_url_to_database(CouchPotato::Config.database_name, CouchPotato::Config.database_host))
34
34
  end
35
35
 
36
36
  # Returns a specific database instance
37
37
  def self.use(database_name)
38
- @@__databases ||= {}
39
- @@__databases["#{database_name}"] = Database.new(couchrest_database_for_name!(database_name)) unless @@__databases["#{database_name}"]
40
- @@__databases["#{database_name}"]
38
+ Thread.current[:__couch_potato_databases] ||= {}
39
+ Thread.current[:__couch_potato_databases][database_name] = Database.new(couchrest_database_for_name!(database_name)) unless Thread.current[:__couch_potato_databases][database_name]
40
+ Thread.current[:__couch_potato_databases][database_name]
41
41
  end
42
42
 
43
43
  # Executes a block of code and yields a datbase with the given name.
@@ -48,9 +48,9 @@ module CouchPotato
48
48
  # end
49
49
  #
50
50
  def self.with_database(database_name)
51
- @@__databases ||= {}
52
- @@__databases["#{database_name}"] = Database.new(couchrest_database_for_name(database_name)) unless @@__databases["#{database_name}"]
53
- yield(@@__databases["#{database_name}"])
51
+ Thread.current[:__couch_potato_databases] ||= {}
52
+ Thread.current[:__couch_potato_databases][database_name] = Database.new(couchrest_database_for_name(database_name)) unless Thread.current[:__couch_potato_databases][database_name]
53
+ yield Thread.current[:__couch_potato_databases][database_name]
54
54
  end
55
55
 
56
56
  # Returns a CouchRest-Database for directly accessing that functionality.
@@ -63,9 +63,7 @@ module CouchPotato
63
63
  CouchRest.database!(full_url_to_database(database_name))
64
64
  end
65
65
 
66
- private
67
-
68
- def self.full_url_to_database(database_name=CouchPotato::Config.database_name, database_host = CouchPotato::Config.database_host)
66
+ def self.full_url_to_database(database_name = CouchPotato::Config.database_name, database_host = CouchPotato::Config.database_host)
69
67
  raise('No Database configured. Set CouchPotato::Config.database_name') unless database_name
70
68
  if database_name.match(%r{https?://})
71
69
  database_name
@@ -145,10 +145,12 @@ module CouchPotato
145
145
  private
146
146
 
147
147
  def handle_write_conflict(document, validate, retries, &block)
148
- document = document.reload
149
148
  if retries == 5
150
149
  raise CouchPotato::Conflict.new
151
150
  else
151
+ reloaded = document.reload
152
+ document.attributes = reloaded.attributes
153
+ document._rev = reloaded._rev
152
154
  save_document document, validate, retries + 1, &block
153
155
  end
154
156
  end
@@ -28,7 +28,7 @@ module CouchPotato
28
28
 
29
29
  def cast_native(value, type)
30
30
  if type && !value.is_a?(type)
31
- if type == Fixnum
31
+ if [Fixnum, Integer].include? type
32
32
  BigDecimal.new(value.to_s.scan(NUMBER_REGEX).join).round unless value.blank?
33
33
  elsif type == Float
34
34
  value.to_s.scan(NUMBER_REGEX).join.to_f unless value.blank?
@@ -36,6 +36,8 @@ module CouchPotato
36
36
  BigDecimal.new(value.to_s) unless value.blank?
37
37
  elsif type == Hash
38
38
  value.to_hash unless value.blank?
39
+ elsif type.ancestors.include?(CouchPotato::Persistence)
40
+ type.new value unless value.blank?
39
41
  else
40
42
  type.json_create value unless value.blank?
41
43
  end
@@ -1,4 +1,4 @@
1
1
  module CouchPotato
2
- VERSION = '1.7.0'.freeze
2
+ VERSION = '1.7.1'.freeze
3
3
  RSPEC_VERSION = '3.4.0'.freeze
4
4
  end
@@ -19,7 +19,7 @@ describe 'conflict handling' do
19
19
  m.value += 1
20
20
  end
21
21
 
22
- expect(measurement.reload.value).to eql(3)
22
+ expect(measurement.value).to eql(3)
23
23
  end
24
24
 
25
25
  it 'raises an error after 5 tries' do
@@ -114,12 +114,21 @@ describe 'properties' do
114
114
  end
115
115
 
116
116
  it "should persist subclasses of the specified type" do
117
- w = Watch.new(:custom_address => [Address2.new])
117
+ w = Watch.new(:custom_address => [Address2.new(id: 'a1', city: 'Berlin')])
118
118
  CouchPotato.database.save_document! w
119
119
  w = CouchPotato.database.load_document w.id
120
+
120
121
  expect(w.custom_address[0]).to be_an_instance_of Address2
121
122
  end
122
123
 
124
+ it 'initializes an typed array property from an array of hashes' do
125
+ w = Watch.new(custom_address: [{id: 'a1', city: 'Berlin'}])
126
+
127
+ expect(w.custom_address.map(&:class)).to eq([Address])
128
+ expect(w.custom_address.map(&:id)).to eq(['a1'])
129
+ expect(w.custom_address.map(&:city)).to eq(['Berlin'])
130
+ end
131
+
123
132
  def it_should_persist value
124
133
  c = Comment.new :title => value
125
134
  CouchPotato.database.save_document! c
@@ -10,6 +10,7 @@ class Plant
10
10
  include CouchPotato::Persistence
11
11
  property :leaf_count
12
12
  property :typed_leaf_count, type: Fixnum
13
+ property :integer_something, type: Integer
13
14
  property :typed_leaf_size, type: Float
14
15
  property :branch, type: Branch
15
16
  end
@@ -40,6 +41,7 @@ describe 'attributes' do
40
41
  plant = Plant.new(leaf_count: 1)
41
42
 
42
43
  expect(plant.attributes).to eq('leaf_count' => 1, 'created_at' => nil,
44
+ 'integer_something' => nil,
43
45
  'updated_at' => nil, 'typed_leaf_count' => nil,
44
46
  'typed_leaf_size' => nil, 'branch' => nil)
45
47
  end
@@ -109,6 +111,57 @@ describe 'attributes' do
109
111
  end
110
112
  end
111
113
 
114
+ describe 'integer' do
115
+ it 'rounds a float to a fixnum' do
116
+ @plant.integer_something = 4.5
117
+
118
+ expect(@plant.integer_something).to eq(5)
119
+ end
120
+
121
+ it 'converts a string into a fixnum' do
122
+ @plant.integer_something = '4'
123
+
124
+ expect(@plant.integer_something).to eq(4)
125
+ end
126
+
127
+ it 'converts a string into a negative fixnum' do
128
+ @plant.integer_something = '-4'
129
+
130
+ expect(@plant.integer_something).to eq(-4)
131
+ end
132
+
133
+ it 'leaves a fixnum as is' do
134
+ @plant.integer_something = 4
135
+
136
+ expect(@plant.integer_something).to eq(4)
137
+ end
138
+
139
+ it 'leaves nil as is' do
140
+ @plant.integer_something = nil
141
+
142
+ expect(@plant.integer_something).to be_nil
143
+ end
144
+
145
+ it 'sets the attributes to zero if a string given' do
146
+ @plant.integer_something = 'x'
147
+
148
+ expect(@plant.integer_something).to eq(0)
149
+ end
150
+
151
+ it 'parses numbers out of a string' do
152
+ @plant.integer_something = 'x123'
153
+
154
+ expect(@plant.integer_something).to eq(123)
155
+ end
156
+
157
+ it 'sets the attributes to nil if given a blank string' do
158
+ @plant.integer_something = ''
159
+
160
+ expect(@plant.integer_something).to be_nil
161
+ end
162
+ end
163
+
164
+
112
165
  describe 'fixnum' do
113
166
  it 'rounds a float to a fixnum' do
114
167
  @plant.typed_leaf_count = 4.5
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: couch_potato
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Lang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-03 00:00:00.000000000 Z
11
+ date: 2017-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -30,28 +30,34 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 2.0.0.rc3
33
+ version: 2.0.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 2.0.0.rc3
40
+ version: 2.0.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: activemodel
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '4.0'
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: '6.0'
48
51
  type: :runtime
49
52
  prerelease: false
50
53
  version_requirements: !ruby/object:Gem::Requirement
51
54
  requirements:
52
- - - "~>"
55
+ - - ">="
53
56
  - !ruby/object:Gem::Version
54
57
  version: '4.0'
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: '6.0'
55
61
  - !ruby/object:Gem::Dependency
56
62
  name: rspec
57
63
  requirement: !ruby/object:Gem::Requirement
@@ -98,16 +104,16 @@ dependencies:
98
104
  name: rake
99
105
  requirement: !ruby/object:Gem::Requirement
100
106
  requirements:
101
- - - ">="
107
+ - - "<"
102
108
  - !ruby/object:Gem::Version
103
- version: '0'
109
+ version: '11.0'
104
110
  type: :development
105
111
  prerelease: false
106
112
  version_requirements: !ruby/object:Gem::Requirement
107
113
  requirements:
108
- - - ">="
114
+ - - "<"
109
115
  - !ruby/object:Gem::Version
110
- version: '0'
116
+ version: '11.0'
111
117
  description: Ruby persistence layer for CouchDB
112
118
  email: alex@upstre.am
113
119
  executables: []
@@ -128,6 +134,7 @@ files:
128
134
  - gemfiles/active_support_4_0
129
135
  - gemfiles/active_support_4_1
130
136
  - gemfiles/active_support_4_2
137
+ - gemfiles/active_support_5_0
131
138
  - init.rb
132
139
  - lib/core_ext/date.rb
133
140
  - lib/core_ext/time.rb
@@ -223,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
223
230
  version: '0'
224
231
  requirements: []
225
232
  rubyforge_project:
226
- rubygems_version: 2.4.7
233
+ rubygems_version: 2.4.5
227
234
  signing_key:
228
235
  specification_version: 4
229
236
  summary: Ruby persistence layer for CouchDB
@@ -270,4 +277,3 @@ test_files:
270
277
  - spec/update_spec.rb
271
278
  - spec/view_updates_spec.rb
272
279
  - spec/views_spec.rb
273
- has_rdoc: