modis 1.4.2 → 2.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
2
  SHA1:
3
- metadata.gz: 774c89b8695921821cc449741a450f77f69f649f
4
- data.tar.gz: 941a15b53b91e8c955a1599199867a0595b58b5a
3
+ metadata.gz: d72c95fa261834b9a837e642e63e3ef9094e6a00
4
+ data.tar.gz: d43a8f952fc05fc725adc94354d77ef4d8318a98
5
5
  SHA512:
6
- metadata.gz: 47964396569527b5f809150eaf9c6a82353226e66bfd05b49f5295cf520ed57ba84a07c63b7bdf52c181c4adbf6fc459e0f1f5b2207994f96992d067b220eff6
7
- data.tar.gz: 8a4b7f80c4c39593c8de11c457c1bd6430bbc3f559a739c3dab7b11282750bd29a53fb0f88d9deb4748983d9641f8d0699fcd45afdcf0094c52c7b3ef26b1d4f
6
+ metadata.gz: 8cf44d0818eb8c163064cee228732b1d86811b08475c033f45b90a4b23cc8e0fc8a1fe030c6822c4ae1e69e7e0873d53a3f0d304572ad3d538ad3d6c18a7490d
7
+ data.tar.gz: 1293bc123e53195e5cc5e44c4b77669a52927e5fd6ec3ee20c3523fc3f0ff875905b861a02be07c0f276e2571e951ba35d73d0bf1ef03b59da7139adf3594e00
data/.gitignore CHANGED
@@ -14,3 +14,4 @@ spec/reports
14
14
  test/tmp
15
15
  test/version_tmp
16
16
  tmp
17
+ Gemfile.lock
@@ -35,3 +35,9 @@ Style/StructInheritance:
35
35
 
36
36
  Metrics/ModuleLength:
37
37
  Enabled: false
38
+
39
+ Metrics/BlockLength:
40
+ Enabled: false
41
+
42
+ Security/YAMLLoad:
43
+ Enabled: false
@@ -1 +1 @@
1
- ruby-2.2.2
1
+ 2.4.1
@@ -3,11 +3,10 @@ services:
3
3
  - redis-server
4
4
  language: ruby
5
5
  rvm:
6
- - 2.0.0
7
- - 2.1.5
8
- - 2.2.0
9
- - jruby-1.7.18
10
- - rbx-2.5.0
6
+ - 2.2.4
7
+ - 2.3.0
8
+ - 2.4.0
9
+ - jruby-9.1.9.0
11
10
  env:
12
11
  global:
13
12
  secure: LrTz0Pq2ibNZuKDhdzcrvEUSNxUpPopEq9aJeCxy3UpV0v4vpHBtWV0S6zofvf98g/RkZ6cGI1u+0H578dHgE6pWTo+iR8LAwqPKofrFIWRkeo+M77Vs5swahb3mQyPOcig1hfVWDm25MsojePYm70eBIcBU55NWImtdePXfiU0=
data/Gemfile CHANGED
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gem 'rake'
4
6
  gem 'rspec'
5
7
 
6
8
  platform :mri do
7
- gem 'codeclimate-test-reporter', require: nil
8
9
  gem 'cane'
10
+ gem 'codeclimate-test-reporter', require: nil
9
11
  gem 'rubocop', require: false
10
12
  gem 'simplecov', require: false
11
13
  end
data/README.md CHANGED
@@ -6,6 +6,10 @@
6
6
 
7
7
  ActiveModel + Redis with the aim to mimic ActiveRecord where possible.
8
8
 
9
+ ## Requirements
10
+
11
+ Modis supports CRuby 2.2.2+ and jRuby 9k+
12
+
9
13
  ## Installation
10
14
 
11
15
  Add this line to your application's Gemfile:
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "rake"
2
4
  require "bundler/gem_tasks"
3
5
  require "rspec/core/rake_task"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'stackprof'
2
4
  require 'benchmark'
3
5
 
@@ -40,14 +42,14 @@ class Bench
40
42
 
41
43
  private
42
44
 
43
- def with_profile(name, &blk)
45
+ def with_profile(name)
44
46
  if ENV['PROFILE']
45
47
  mode = :wall
46
48
  out = "tmp/stackprof-#{mode}-#{name}.dump"
47
49
  @profiles << out
48
- StackProf.run(mode: mode, out: out, &blk)
50
+ StackProf.run(mode: mode, out: out, &Proc.new)
49
51
  else
50
- blk.call
52
+ yield
51
53
  end
52
54
  end
53
55
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  $LOAD_PATH.unshift('benchmark')
2
4
  require 'bench'
3
5
 
@@ -16,7 +18,7 @@ class User
16
18
  attribute :flag, :boolean
17
19
  attribute :array, :array
18
20
  attribute :hash, :hash
19
- attribute :string_or_hash, [:string, :hash]
21
+ attribute :string_or_hash, %i[string hash]
20
22
 
21
23
  index :name
22
24
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  $LOAD_PATH.unshift('benchmark')
2
4
  require 'bench'
3
5
 
@@ -16,7 +18,7 @@ class User
16
18
  attribute :flag, :boolean
17
19
  attribute :array, :array
18
20
  attribute :hash, :hash
19
- attribute :string_or_hash, [:string, :hash]
21
+ attribute :string_or_hash, %i[string hash]
20
22
 
21
23
  index :name
22
24
  end
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'redis'
2
4
  require 'connection_pool'
3
5
  require 'active_model'
4
6
  require 'active_support/all'
5
- require 'yaml'
6
7
  require 'msgpack'
7
8
 
8
9
  require 'modis/version'
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Modis
2
4
  module Attribute
3
5
  TYPES = { string: [String],
4
- integer: [Fixnum],
6
+ integer: [0.class],
5
7
  float: [Float],
6
8
  timestamp: [Time],
7
9
  hash: [Hash],
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Modis
2
4
  def self.configure
3
5
  yield config
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Modis
2
4
  class ModisError < StandardError; end
3
5
  class RecordNotSaved < ModisError; end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Modis
2
4
  module Finder
3
5
  def self.included(base)
@@ -61,7 +63,7 @@ module Modis
61
63
 
62
64
  def model_for(attributes)
63
65
  cls = model_class(attributes)
64
- return unless self == cls || cls < self
66
+ return unless cls == self || cls < self
65
67
  cls.new(attributes, new_record: false)
66
68
  end
67
69
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Modis
2
4
  module Index
3
5
  def self.included(base)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Modis
2
4
  module Model
3
5
  def self.included(base)
@@ -42,6 +44,6 @@ module Modis
42
44
  def ==(other)
43
45
  super || other.instance_of?(self.class) && id.present? && other.id == id
44
46
  end
45
- alias_method :eql?, :==
47
+ alias eql? ==
46
48
  end
47
49
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Modis
2
4
  module Persistence
3
5
  def self.included(base)
@@ -5,7 +7,7 @@ module Modis
5
7
  base.instance_eval do
6
8
  class << self
7
9
  attr_reader :sti_child
8
- alias_method :sti_child?, :sti_child
10
+ alias sti_child? sti_child
9
11
  end
10
12
  end
11
13
  end
@@ -32,10 +34,10 @@ module Modis
32
34
 
33
35
  def namespace
34
36
  @namespace ||= if sti_child?
35
- "#{sti_parent.namespace}:#{name.split('::').last.underscore}"
36
- else
37
- name.split('::').map(&:underscore).join(':')
38
- end
37
+ "#{sti_parent.namespace}:#{name.split('::').last.underscore}"
38
+ else
39
+ name.split('::').map(&:underscore).join(':')
40
+ end
39
41
  end
40
42
 
41
43
  def namespace=(value)
@@ -71,7 +73,6 @@ module Modis
71
73
  model
72
74
  end
73
75
 
74
- YAML_MARKER = '---'.freeze
75
76
  def deserialize(record)
76
77
  values = record.values
77
78
  values = MessagePack.unpack(msgpack_array_header(values.size) + values.join)
@@ -79,20 +80,8 @@ module Modis
79
80
  values.each_with_index { |v, i| record[keys[i]] = v }
80
81
  record
81
82
  rescue MessagePack::MalformedFormatError
82
- found_yaml = false
83
-
84
83
  record.each do |k, v|
85
- if v.start_with?(YAML_MARKER)
86
- found_yaml = true
87
- record[k] = YAML.load(v)
88
- else
89
- record[k] = MessagePack.unpack(v)
90
- end
91
- end
92
-
93
- if found_yaml
94
- id = record['id']
95
- STDERR.puts "#{self}(id: #{id}) contains attributes serialized as YAML. As of Modis 1.4.0, YAML is no longer used as the serialization format. To improve performance loading this record, you can force the record to new serialization format (MessagePack) with: #{self}.find(#{id}).save!(yaml_sucks: true)"
84
+ record[k] = MessagePack.unpack(v)
96
85
  end
97
86
 
98
87
  record
@@ -177,7 +166,7 @@ module Modis
177
166
 
178
167
  def create_or_update(args = {})
179
168
  validate(args)
180
- future = persist(args[:yaml_sucks])
169
+ future = persist
181
170
 
182
171
  if future && (future == :unchanged || future.value == 'OK')
183
172
  reset_changes
@@ -194,7 +183,8 @@ module Modis
194
183
  raise Modis::RecordInvalid, errors.full_messages.join(', ')
195
184
  end
196
185
 
197
- def persist(persist_all)
186
+ # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity
187
+ def persist
198
188
  future = nil
199
189
  set_id if new_record?
200
190
  callback = new_record? ? :create : :update
@@ -203,7 +193,7 @@ module Modis
203
193
  run_callbacks :save do
204
194
  run_callbacks callback do
205
195
  redis.pipelined do
206
- attrs = coerced_attributes(persist_all)
196
+ attrs = coerced_attributes
207
197
  key = self.class.sti_child? ? self.class.sti_base_key_for(id) : self.class.key_for(id)
208
198
  future = attrs.any? ? redis.hmset(key, attrs) : :unchanged
209
199
 
@@ -222,10 +212,10 @@ module Modis
222
212
  future
223
213
  end
224
214
 
225
- def coerced_attributes(persist_all)
215
+ def coerced_attributes
226
216
  attrs = []
227
217
 
228
- if new_record? || persist_all
218
+ if new_record?
229
219
  attributes.each do |k, v|
230
220
  if (self.class.attributes[k][:default] || nil) != v
231
221
  attrs << k << coerce_for_persistence(v)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Modis
2
4
  module Transaction
3
5
  def self.included(base)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Modis
2
- VERSION = '1.4.2'
4
+ VERSION = '2.0.0'
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
4
  if ENV['TRAVIS']
3
5
  namespace :spec do
@@ -16,7 +18,7 @@ begin
16
18
  end
17
19
 
18
20
  namespace :spec do
19
- task cane: %w(spec cane_quality)
21
+ task cane: %w[spec cane_quality]
20
22
  end
21
23
  end
22
24
  rescue LoadError
@@ -37,5 +39,5 @@ rescue LoadError
37
39
  end
38
40
 
39
41
  namespace :spec do
40
- task quality: %w(cane rubocop)
42
+ task quality: %w[cane rubocop]
41
43
  end
@@ -10,7 +10,8 @@ Gem::Specification.new do |gem|
10
10
  gem.email = ["port001@gmail.com"]
11
11
  gem.description = "ActiveModel + Redis"
12
12
  gem.summary = "ActiveModel + Redis"
13
- gem.homepage = ""
13
+ gem.homepage = "https://github.com/ileitch/modis"
14
+ gem.license = "MIT"
14
15
 
15
16
  gem.files = `git ls-files`.split($/)
16
17
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module AttributeSpec
@@ -11,7 +13,7 @@ module AttributeSpec
11
13
  attribute :flag, :boolean
12
14
  attribute :array, :array
13
15
  attribute :hash, :hash
14
- attribute :string_or_hash, [:string, :hash]
16
+ attribute :string_or_hash, %i[string hash]
15
17
  end
16
18
  end
17
19
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module ErrorsSpec
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module FindersSpec
@@ -126,7 +128,7 @@ describe Modis::Finder do
126
128
  end
127
129
 
128
130
  it 'does not find an instance of a sibling' do
129
- consumer = FindersSpec::Consumer.create!(name: 'Kyle')
131
+ FindersSpec::Consumer.create!(name: 'Kyle')
130
132
  producer = FindersSpec::Producer.create!(name: 'Tanya')
131
133
  expect do
132
134
  FindersSpec::Consumer.find(producer.id)
@@ -142,10 +144,10 @@ describe Modis::Finder do
142
144
 
143
145
  it 'inherits attributes from the parent' do
144
146
  producer = FindersSpec::Producer.create!(name: 'Kyle', consumed: true)
145
- expect(producer.attributes.keys.sort).to eq(%w(age child_default id name parent_default type))
147
+ expect(producer.attributes.keys.sort).to eq(%w[age child_default id name parent_default type])
146
148
 
147
149
  worker = FindersSpec::Worker.create!(name: 'Max')
148
- expect(worker.attributes.keys.sort).to eq(%w(age child_default id name parent_default type))
150
+ expect(worker.attributes.keys.sort).to eq(%w[age child_default id name parent_default type])
149
151
  end
150
152
 
151
153
  it 'inherits default attribute values from the parent' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module IndexSpec
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module PersistenceSpec
@@ -294,26 +296,4 @@ describe Modis::Persistence do
294
296
  expect(model.update_attributes(name: nil)).to be false
295
297
  end
296
298
  end
297
-
298
- describe 'YAML backward compatability' do
299
- it 'loads a YAML serialized value' do
300
- Modis.with_connection do |redis|
301
- model.save!
302
- key = model.class.key_for(model.id)
303
- record = redis.hgetall(key)
304
- record['age'] = YAML.dump(30)
305
- redis.hmset(key, *record.to_a)
306
- record = redis.hgetall(key)
307
-
308
- expect(record['age']).to eq("--- 30\n...\n")
309
-
310
- model.reload
311
- expect(model.age).to eq(30)
312
-
313
- model.save!(yaml_sucks: true)
314
- record = redis.hgetall(key)
315
- expect(record['age']).to eq("\x1E")
316
- end
317
- end
318
- end
319
299
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  unless ENV['TRAVIS']
2
4
  begin
3
5
  require './spec/support/simplecov_helper'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'simplecov'
2
4
  require './spec/support/simplecov_quality_formatter'
3
5
 
@@ -17,7 +19,7 @@ module SimpleCovHelper
17
19
  end
18
20
  end
19
21
 
20
- formatter SimpleCov::Formatter::MultiFormatter[*formatters]
22
+ formatter SimpleCov::Formatter::MultiFormatter.new(*formatters)
21
23
  end
22
24
  end
23
25
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SimpleCov
2
4
  module Formatter
3
5
  class QualityFormatter
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module TransactionSpec
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe 'validations' do
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: 1.4.2
4
+ version: 2.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-05 00:00:00.000000000 Z
11
+ date: 2017-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -107,7 +107,6 @@ files:
107
107
  - ".ruby-version"
108
108
  - ".travis.yml"
109
109
  - Gemfile
110
- - Gemfile.lock
111
110
  - LICENSE.txt
112
111
  - README.md
113
112
  - Rakefile
@@ -137,8 +136,9 @@ files:
137
136
  - spec/support/simplecov_quality_formatter.rb
138
137
  - spec/transaction_spec.rb
139
138
  - spec/validations_spec.rb
140
- homepage: ''
141
- licenses: []
139
+ homepage: https://github.com/ileitch/modis
140
+ licenses:
141
+ - MIT
142
142
  metadata: {}
143
143
  post_install_message:
144
144
  rdoc_options: []
@@ -1,96 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- modis (1.4.1)
5
- activemodel (>= 3.0)
6
- activesupport (>= 3.0)
7
- connection_pool (>= 2)
8
- hiredis (>= 0.5)
9
- msgpack (>= 0.5)
10
- redis (>= 3.0)
11
-
12
- GEM
13
- remote: https://rubygems.org/
14
- specs:
15
- activemodel (4.2.3)
16
- activesupport (= 4.2.3)
17
- builder (~> 3.1)
18
- activesupport (4.2.3)
19
- i18n (~> 0.7)
20
- json (~> 1.7, >= 1.7.7)
21
- minitest (~> 5.1)
22
- thread_safe (~> 0.3, >= 0.3.4)
23
- tzinfo (~> 1.1)
24
- ast (2.0.0)
25
- astrolabe (1.3.0)
26
- parser (>= 2.2.0.pre.3, < 3.0)
27
- builder (3.2.2)
28
- cane (2.6.2)
29
- parallel
30
- codeclimate-test-reporter (0.4.7)
31
- simplecov (>= 0.7.1, < 1.0.0)
32
- connection_pool (2.2.0)
33
- diff-lcs (1.2.5)
34
- docile (1.1.5)
35
- hiredis (0.6.0)
36
- hiredis (0.6.0-java)
37
- i18n (0.7.0)
38
- json (1.8.3)
39
- json (1.8.3-java)
40
- minitest (5.7.0)
41
- msgpack (0.6.0)
42
- msgpack (0.6.0-java)
43
- parallel (1.6.0)
44
- parser (2.2.2.5)
45
- ast (>= 1.1, < 3.0)
46
- powerpack (0.1.1)
47
- rainbow (2.0.0)
48
- rake (10.4.2)
49
- redis (3.2.1)
50
- rspec (3.3.0)
51
- rspec-core (~> 3.3.0)
52
- rspec-expectations (~> 3.3.0)
53
- rspec-mocks (~> 3.3.0)
54
- rspec-core (3.3.1)
55
- rspec-support (~> 3.3.0)
56
- rspec-expectations (3.3.0)
57
- diff-lcs (>= 1.2.0, < 2.0)
58
- rspec-support (~> 3.3.0)
59
- rspec-mocks (3.3.1)
60
- diff-lcs (>= 1.2.0, < 2.0)
61
- rspec-support (~> 3.3.0)
62
- rspec-support (3.3.0)
63
- rubocop (0.32.1)
64
- astrolabe (~> 1.3)
65
- parser (>= 2.2.2.5, < 3.0)
66
- powerpack (~> 0.1)
67
- rainbow (>= 1.99.1, < 3.0)
68
- ruby-progressbar (~> 1.4)
69
- ruby-progressbar (1.7.5)
70
- simplecov (0.10.0)
71
- docile (~> 1.1.0)
72
- json (~> 1.8)
73
- simplecov-html (~> 0.10.0)
74
- simplecov-html (0.10.0)
75
- stackprof (0.2.7)
76
- thread_safe (0.3.5)
77
- thread_safe (0.3.5-java)
78
- tzinfo (1.2.2)
79
- thread_safe (~> 0.1)
80
-
81
- PLATFORMS
82
- java
83
- ruby
84
-
85
- DEPENDENCIES
86
- cane
87
- codeclimate-test-reporter
88
- modis!
89
- rake
90
- rspec
91
- rubocop
92
- simplecov
93
- stackprof
94
-
95
- BUNDLED WITH
96
- 1.10.5