modis 2.1.0 → 3.0.0

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
- SHA1:
3
- metadata.gz: bb24ac739595677e1200448641dc4e7c35a26f1d
4
- data.tar.gz: 428715902d2b7e335e16d7ee2b65aa58c3864b52
2
+ SHA256:
3
+ metadata.gz: 05bca2cd787d1ec58cc5c274071e759662787d15744028afd26e8c5686e98a0f
4
+ data.tar.gz: fd65fc90ad00304558727529f1fcdbae12d9768a7870c9a89a567203ab65f6c8
5
5
  SHA512:
6
- metadata.gz: 7f34d83dd16b16bd113a116d060523c8f832593f604e318077be24d279d8a9f06ce269f86a3935f5fbe8e1a70d815075a54f69c9ee3f4d45eaa0fafc211a461e
7
- data.tar.gz: a3451db68ba6943d667fb11470c9635dfb0c74ac9449b330125ffe7be4d9b0c3e94df459d8a2acb8ab0069a6fa80fadf4c83a8630898ef26c023857f34cfa473
6
+ metadata.gz: 3651e8862dc7d6a15d640fcc7260d7515515d65976900f3c53f56d1240dd0e63a6a5a547b3bce7facff6e6a85b2382dd0a52e4469e89d890f682d1547713c7bb
7
+ data.tar.gz: 59f47ccdeb055ca70774e88d40a0a203123c230871d5e7d36dedaa9ac7a4e1a0c4e4aa9b4aa6f7b7c01d74f2d5e6c22d7cb4cfc6721bbe142ebd202aaf42cb69
@@ -2,6 +2,7 @@ AllCops:
2
2
  Exclude:
3
3
  - modis.gemspec
4
4
  - vendor/**/*
5
+ - gemfiles/**/*
5
6
 
6
7
  LineLength:
7
8
  Enabled: false
@@ -1 +1 @@
1
- 2.4.1
1
+ 2.5.3
@@ -1,12 +1,25 @@
1
+ language: ruby
2
+
1
3
  sudo: false
4
+
5
+ cache: bundler
6
+
2
7
  services:
3
- - redis-server
4
- language: ruby
8
+ - redis-server
9
+
5
10
  rvm:
6
- - 2.2.4
7
- - 2.3.0
8
- - 2.4.0
9
- - jruby-9.1.9.0
11
+ - 2.3.8
12
+ - 2.4.5
13
+ - 2.5.3
14
+ - jruby-9.1.17.0
15
+ - jruby-9.2.5.0
16
+
17
+ gemfile:
18
+ - gemfiles/rails_42.gemfile
19
+ - gemfiles/rails_50.gemfile
20
+ - gemfiles/rails_51.gemfile
21
+ - gemfiles/rails_52.gemfile
22
+
10
23
  env:
11
24
  global:
12
25
  secure: LrTz0Pq2ibNZuKDhdzcrvEUSNxUpPopEq9aJeCxy3UpV0v4vpHBtWV0S6zofvf98g/RkZ6cGI1u+0H578dHgE6pWTo+iR8LAwqPKofrFIWRkeo+M77Vs5swahb3mQyPOcig1hfVWDm25MsojePYm70eBIcBU55NWImtdePXfiU0=
@@ -0,0 +1,17 @@
1
+ ## Unreleased
2
+
3
+ ## v3.0.0 - 2018-12-20
4
+
5
+ - Drop support for any Ruby < 2.3 and Rails < 4.2.
6
+ - Add support for Rails 5.2
7
+ - Resolve Rubocop lint violations
8
+ - Test combinations of Ruby and Rails versions in CI
9
+
10
+ ## v2.1.0
11
+
12
+ - Add `enable_all_index` option to allow disabling the `all` keys. [#7](https://github.com/ileitch/modis/pull/7)
13
+
14
+ ## v2.0.0
15
+
16
+ - Support MRI 2.2.2+ and JRuby 9k+ [#5](https://github.com/ileitch/modis/pull/5)
17
+ - Remove YAML (de)serialization support [#5](https://github.com/ileitch/modis/pull/5)
data/Gemfile CHANGED
@@ -2,18 +2,4 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
- gem 'rake'
6
- gem 'rspec'
7
-
8
- platform :mri do
9
- gem 'cane'
10
- gem 'codeclimate-test-reporter', require: nil
11
- gem 'rubocop', require: false
12
- gem 'simplecov', require: false
13
- end
14
-
15
- platform :mri_21 do
16
- gem 'stackprof'
17
- end
18
-
19
5
  gemspec
data/README.md CHANGED
@@ -8,7 +8,7 @@ ActiveModel + Redis with the aim to mimic ActiveRecord where possible.
8
8
 
9
9
  ## Requirements
10
10
 
11
- Modis supports CRuby 2.2.2+ and jRuby 9k+
11
+ Modis supports any actively supported Ruby and Ruby on Rails versions. As of 2018-12-20, that means CRuby 2.3+ and jRuby 9k+, as well as Rails 4.2+.
12
12
 
13
13
  ## Installation
14
14
 
@@ -28,12 +28,12 @@ Or install it yourself as:
28
28
 
29
29
  ```ruby
30
30
  class MyModel
31
- include Modis::Models
32
- attribute :name, String
33
- attribute :age, Integer
31
+ include Modis::Model
32
+ attribute :name, :string
33
+ attribute :age, :integer
34
34
  end
35
35
 
36
- MyModel.create!(:name => 'Ian', :age => 28)
36
+ MyModel.create!(name: 'Ian', age: 28)
37
37
  ```
38
38
 
39
39
  ### all index
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'activemodel', '~> 4.2.0'
6
+ gem 'activesupport', '~> 4.2.0'
7
+
8
+ gemspec path: '../'
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'activemodel', '~> 5.0.0'
6
+ gem 'activesupport', '~> 5.0.0'
7
+
8
+ gemspec path: '../'
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'activemodel', '~> 5.1.0'
6
+ gem 'activesupport', '~> 5.1.0'
7
+
8
+ gemspec path: '../'
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'activemodel', '~> 5.2.0'
6
+ gem 'activesupport', '~> 5.2.0'
7
+
8
+ gemspec path: '../'
@@ -20,23 +20,32 @@ module Modis
20
20
  @mutex = Mutex.new
21
21
 
22
22
  class << self
23
- attr_accessor :connection_pool, :redis_options, :connection_pool_size,
24
- :connection_pool_timeout
25
- end
23
+ attr_writer :redis_options, :connection_pool_size, :connection_pool_timeout,
24
+ :connection_pool
26
25
 
27
- self.redis_options = { driver: :hiredis }
28
- self.connection_pool_size = 5
29
- self.connection_pool_timeout = 5
26
+ def redis_options
27
+ @redis_options ||= { driver: :hiredis }
28
+ end
30
29
 
31
- def self.connection_pool
32
- return @connection_pool if @connection_pool
33
- @mutex.synchronize do
34
- options = { size: connection_pool_size, timeout: connection_pool_timeout }
35
- @connection_pool = ConnectionPool.new(options) { Redis.new(redis_options) }
30
+ def connection_pool_size
31
+ @connection_pool_size ||= 5
32
+ end
33
+
34
+ def connection_pool_timeout
35
+ @connection_pool_timeout ||= 5
36
36
  end
37
- end
38
37
 
39
- def self.with_connection
40
- connection_pool.with { |connection| yield(connection) }
38
+ def connection_pool
39
+ return @connection_pool if @connection_pool
40
+
41
+ @mutex.synchronize do
42
+ options = { size: connection_pool_size, timeout: connection_pool_timeout }
43
+ @connection_pool = ConnectionPool.new(options) { Redis.new(redis_options) }
44
+ end
45
+ end
46
+
47
+ def with_connection
48
+ connection_pool.with { |connection| yield(connection) }
49
+ end
41
50
  end
42
51
  end
@@ -19,8 +19,6 @@ module Modis
19
19
 
20
20
  module ClassMethods
21
21
  def bootstrap_attributes(parent = nil)
22
- attr_reader :attributes
23
-
24
22
  class << self
25
23
  attr_accessor :attributes, :attributes_with_defaults
26
24
  end
@@ -37,6 +35,7 @@ module Modis
37
35
 
38
36
  type_classes = Array(type).map do |t|
39
37
  raise UnsupportedAttributeType, t unless TYPES.key?(t)
38
+
40
39
  TYPES[t]
41
40
  end.flatten
42
41
 
@@ -53,7 +52,7 @@ module Modis
53
52
  end
54
53
  RUBY
55
54
 
56
- class_eval <<-RUBY, __FILE__, __LINE__
55
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
57
56
  def #{name}
58
57
  attributes['#{name}']
59
58
  end
@@ -72,6 +71,10 @@ module Modis
72
71
  end
73
72
  end
74
73
 
74
+ def attributes
75
+ @modis_attributes
76
+ end
77
+
75
78
  def assign_attributes(hash)
76
79
  hash.each do |k, v|
77
80
  setter = "#{k}="
@@ -91,15 +94,12 @@ module Modis
91
94
 
92
95
  def set_sti_type
93
96
  return unless self.class.sti_child?
94
- write_attribute(:type, self.class.name)
95
- end
96
97
 
97
- def reset_changes
98
- @changed_attributes = nil
98
+ write_attribute(:type, self.class.name)
99
99
  end
100
100
 
101
101
  def apply_defaults
102
- @attributes = Hash[self.class.attributes_with_defaults]
102
+ @modis_attributes = Hash[self.class.attributes_with_defaults]
103
103
  end
104
104
  end
105
105
  end
@@ -33,9 +33,7 @@ module Modis
33
33
 
34
34
  attributes = deserialize(record_for(redis, id))
35
35
 
36
- unless attributes['id'].present?
37
- raise RecordNotFound, "Couldn't find #{name} with id=#{id}"
38
- end
36
+ raise RecordNotFound, "Couldn't find #{name} with id=#{id}" unless attributes['id'].present?
39
37
 
40
38
  attributes
41
39
  end
@@ -69,6 +67,7 @@ module Modis
69
67
  def model_for(attributes)
70
68
  cls = model_class(attributes)
71
69
  return unless cls == self || cls < self
70
+
72
71
  cls.new(attributes, new_record: false)
73
72
  end
74
73
 
@@ -79,6 +78,7 @@ module Modis
79
78
 
80
79
  def model_class(record)
81
80
  return self if record["type"].blank?
81
+
82
82
  record["type"].constantize
83
83
  end
84
84
  end
@@ -21,14 +21,17 @@ module Modis
21
21
  def index(attribute)
22
22
  attribute = attribute.to_s
23
23
  raise IndexError, "No such attribute '#{attribute}'" unless attributes.key?(attribute)
24
+
24
25
  indexed_attributes << attribute
25
26
  end
26
27
 
27
28
  def where(query)
28
29
  raise IndexError, 'Queries using multiple indexes is not currently supported.' if query.keys.size > 1
30
+
29
31
  attribute, value = query.first
30
32
  ids = index_for(attribute, value)
31
33
  return [] if ids.empty?
34
+
32
35
  find_all(ids)
33
36
  end
34
37
 
@@ -35,9 +35,10 @@ module Modis
35
35
  apply_defaults
36
36
  set_sti_type
37
37
  assign_attributes(record) if record
38
- reset_changes
38
+ changes_applied
39
39
 
40
40
  return unless options.key?(:new_record)
41
+
41
42
  instance_variable_set('@new_record', options[:new_record])
42
43
  end
43
44
 
@@ -97,13 +97,13 @@ module Modis
97
97
 
98
98
  private
99
99
 
100
- def msgpack_array_header(n)
101
- if n < 16
102
- [0x90 | n].pack("C")
103
- elsif n < 65536
104
- [0xDC, n].pack("Cn")
100
+ def msgpack_array_header(values_size)
101
+ if values_size < 16
102
+ [0x90 | values_size].pack("C")
103
+ elsif values_size < 65536
104
+ [0xDC, values_size].pack("Cn")
105
105
  else
106
- [0xDD, n].pack("CN")
106
+ [0xDD, values_size].pack("CN")
107
107
  end.force_encoding(Encoding::UTF_8)
108
108
  end
109
109
  end
@@ -114,6 +114,7 @@ module Modis
114
114
 
115
115
  def key
116
116
  return nil if new_record?
117
+
117
118
  self.class.sti_child? ? self.class.sti_base_key_for(id) : self.class.key_for(id)
118
119
  end
119
120
 
@@ -179,7 +180,7 @@ module Modis
179
180
  future = persist
180
181
 
181
182
  if future && (future == :unchanged || future.value == 'OK')
182
- reset_changes
183
+ changes_applied
183
184
  @new_record = false
184
185
  true
185
186
  else
@@ -190,6 +191,7 @@ module Modis
190
191
  def validate(args)
191
192
  skip_validate = args.key?(:validate) && args[:validate] == false
192
193
  return if skip_validate || valid?
194
+
193
195
  raise Modis::RecordInvalid, errors.full_messages.join(', ')
194
196
  end
195
197
 
@@ -223,19 +225,18 @@ module Modis
223
225
 
224
226
  future
225
227
  end
228
+ # rubocop:enable Metrics/AbcSize, Metrics/PerceivedComplexity
226
229
 
227
230
  def coerced_attributes
228
231
  attrs = []
229
232
 
230
233
  if new_record?
231
234
  attributes.each do |k, v|
232
- if (self.class.attributes[k][:default] || nil) != v
233
- attrs << k << coerce_for_persistence(v)
234
- end
235
+ attrs << k << coerce_for_persistence(v) if (self.class.attributes[k][:default] || nil) != v
235
236
  end
236
237
  else
237
- changed_attributes.each do |k, _|
238
- attrs << k << coerce_for_persistence(attributes[k])
238
+ changed_attributes.each_key do |key|
239
+ attrs << key << coerce_for_persistence(attributes[key])
239
240
  end
240
241
  end
241
242
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Modis
4
- VERSION = '2.1.0'
4
+ VERSION = '3.0.0'
5
5
  end
@@ -18,8 +18,11 @@ Gem::Specification.new do |gem|
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ["lib"]
20
20
 
21
- gem.add_runtime_dependency 'activemodel', '>= 3.0'
22
- gem.add_runtime_dependency 'activesupport', '>= 3.0'
21
+ gem.required_ruby_version = ">= 2.3.0"
22
+
23
+ gem.add_runtime_dependency 'activemodel', '>= 4.2'
24
+ gem.add_runtime_dependency 'activesupport', '>= 4.2'
25
+ gem.add_runtime_dependency 'i18n', ['>= 0.7', '< 1.3']
23
26
  gem.add_runtime_dependency 'redis', '>= 3.0'
24
27
  gem.add_runtime_dependency 'hiredis', '>= 0.5'
25
28
  gem.add_runtime_dependency 'connection_pool', '>= 2'
@@ -30,4 +33,11 @@ Gem::Specification.new do |gem|
30
33
  else
31
34
  gem.add_runtime_dependency 'msgpack', '>= 0.5'
32
35
  end
36
+
37
+ gem.add_development_dependency 'rake'
38
+ gem.add_development_dependency 'rspec'
39
+ gem.add_development_dependency 'codeclimate-test-reporter'
40
+ gem.add_development_dependency 'cane'
41
+ gem.add_development_dependency 'rubocop', '0.61.1'
42
+ gem.add_development_dependency 'simplecov'
33
43
  end
@@ -3,7 +3,7 @@
3
3
  unless ENV['TRAVIS']
4
4
  begin
5
5
  require './spec/support/simplecov_helper'
6
- include SimpleCovHelper
6
+ include SimpleCovHelper # rubocop:disable Style/MixinUsage
7
7
  start_simple_cov('unit')
8
8
  rescue LoadError
9
9
  puts "Coverage disabled."
@@ -14,9 +14,7 @@ module SimpleCovHelper
14
14
  if ENV['TRAVIS']
15
15
  require 'codeclimate-test-reporter'
16
16
 
17
- if CodeClimate::TestReporter.run?
18
- formatters << CodeClimate::TestReporter::Formatter
19
- end
17
+ formatters << CodeClimate::TestReporter::Formatter if CodeClimate::TestReporter.run?
20
18
  end
21
19
 
22
20
  formatter SimpleCov::Formatter::MultiFormatter.new(*formatters)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: modis
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian Leitch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-24 00:00:00.000000000 Z
11
+ date: 2018-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -16,28 +16,48 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '3.0'
19
+ version: '4.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '3.0'
26
+ version: '4.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '3.0'
33
+ version: '4.2'
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: '3.0'
40
+ version: '4.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: i18n
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0.7'
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: '1.3'
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0.7'
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.3'
41
61
  - !ruby/object:Gem::Dependency
42
62
  name: redis
43
63
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +114,90 @@ dependencies:
94
114
  - - ">="
95
115
  - !ruby/object:Gem::Version
96
116
  version: '0.5'
117
+ - !ruby/object:Gem::Dependency
118
+ name: rake
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ - !ruby/object:Gem::Dependency
132
+ name: rspec
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ - !ruby/object:Gem::Dependency
146
+ name: codeclimate-test-reporter
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ type: :development
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ - !ruby/object:Gem::Dependency
160
+ name: cane
161
+ requirement: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ - !ruby/object:Gem::Dependency
174
+ name: rubocop
175
+ requirement: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - '='
178
+ - !ruby/object:Gem::Version
179
+ version: 0.61.1
180
+ type: :development
181
+ prerelease: false
182
+ version_requirements: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - '='
185
+ - !ruby/object:Gem::Version
186
+ version: 0.61.1
187
+ - !ruby/object:Gem::Dependency
188
+ name: simplecov
189
+ requirement: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ type: :development
195
+ prerelease: false
196
+ version_requirements: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - ">="
199
+ - !ruby/object:Gem::Version
200
+ version: '0'
97
201
  description: ActiveModel + Redis
98
202
  email:
99
203
  - port001@gmail.com
@@ -106,6 +210,7 @@ files:
106
210
  - ".ruby-gemset"
107
211
  - ".ruby-version"
108
212
  - ".travis.yml"
213
+ - CHANGELOG.md
109
214
  - Gemfile
110
215
  - LICENSE.txt
111
216
  - README.md
@@ -114,6 +219,10 @@ files:
114
219
  - benchmark/find.rb
115
220
  - benchmark/persistence.rb
116
221
  - benchmark/redis/connection/fakedis.rb
222
+ - gemfiles/rails_42.gemfile
223
+ - gemfiles/rails_50.gemfile
224
+ - gemfiles/rails_51.gemfile
225
+ - gemfiles/rails_52.gemfile
117
226
  - lib/modis.rb
118
227
  - lib/modis/attribute.rb
119
228
  - lib/modis/configuration.rb
@@ -148,7 +257,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
148
257
  requirements:
149
258
  - - ">="
150
259
  - !ruby/object:Gem::Version
151
- version: '0'
260
+ version: 2.3.0
152
261
  required_rubygems_version: !ruby/object:Gem::Requirement
153
262
  requirements:
154
263
  - - ">="
@@ -156,7 +265,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
265
  version: '0'
157
266
  requirements: []
158
267
  rubyforge_project:
159
- rubygems_version: 2.6.11
268
+ rubygems_version: 2.7.8
160
269
  signing_key:
161
270
  specification_version: 4
162
271
  summary: ActiveModel + Redis