mongoid_enumerable 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +21 -0
- data/Gemfile +3 -1
- data/Gemfile.lock +19 -1
- data/Guardfile +2 -30
- data/README.md +6 -6
- data/Rakefile +5 -1
- data/bin/console +1 -0
- data/lib/mongoid_enumerable.rb +11 -11
- data/lib/mongoid_enumerable/version.rb +3 -1
- data/mongoid_enumerable.gemspec +9 -7
- metadata +35 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eea7a8187ca0baa94f1a246cad4ba93500e46177176da71d250e548bf344dc19
|
4
|
+
data.tar.gz: f4f94d1bb5eb15077d7681a8a475b444ca16ced8a09034f4d953ac5151702912
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42eb07241e7d9211d929fe1cbc107020f87e8f48e5c1f1c08ec3ffac1690a479123659b25ee44e0e97fcf85a516d851df6f106ee69db2ce139dbf05ceda65883
|
7
|
+
data.tar.gz: f094c1e7ed54b3ede3a725f3c3cf55cf4b9fd4c50e726ee2d0e78879c576125d0f0c0b8da0f543ae638c15bfc9461de091af41863f004fbe501fe2750aa70f43
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
AllCops:
|
2
|
+
NewCops: disable
|
3
|
+
|
4
|
+
Style/StringLiterals:
|
5
|
+
EnforcedStyle: double_quotes
|
6
|
+
|
7
|
+
Style/Documentation:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Metrics/BlockLength:
|
11
|
+
Exclude:
|
12
|
+
- 'spec/**/*'
|
13
|
+
|
14
|
+
Metrics/ParameterLists:
|
15
|
+
Max: 7
|
16
|
+
|
17
|
+
Layout/LineLength:
|
18
|
+
Max: 120
|
19
|
+
|
20
|
+
Metrics/MethodLength:
|
21
|
+
Max: 16
|
data/Gemfile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source "https://rubygems.org"
|
2
4
|
|
3
|
-
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
5
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
6
|
|
5
7
|
# Specify your gem's dependencies in mongoid_enumerable.gemspec
|
6
8
|
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
mongoid_enumerable (0.4.
|
4
|
+
mongoid_enumerable (0.4.2)
|
5
5
|
mongoid (>= 4.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -15,6 +15,7 @@ GEM
|
|
15
15
|
minitest (~> 5.1)
|
16
16
|
tzinfo (~> 1.1)
|
17
17
|
zeitwerk (~> 2.2)
|
18
|
+
ast (2.4.0)
|
18
19
|
bson (4.8.2)
|
19
20
|
byebug (11.1.1)
|
20
21
|
coderay (1.1.2)
|
@@ -39,6 +40,7 @@ GEM
|
|
39
40
|
rspec (>= 2.99.0, < 4.0)
|
40
41
|
i18n (1.8.2)
|
41
42
|
concurrent-ruby (~> 1.0)
|
43
|
+
jaro_winkler (1.5.4)
|
42
44
|
listen (3.2.1)
|
43
45
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
44
46
|
rb-inotify (~> 0.9, >= 0.9.10)
|
@@ -54,13 +56,18 @@ GEM
|
|
54
56
|
notiffany (0.1.3)
|
55
57
|
nenv (~> 0.1)
|
56
58
|
shellany (~> 0.0)
|
59
|
+
parallel (1.19.1)
|
60
|
+
parser (2.7.1.2)
|
61
|
+
ast (~> 2.4.0)
|
57
62
|
pry (0.13.1)
|
58
63
|
coderay (~> 1.1)
|
59
64
|
method_source (~> 1.0)
|
65
|
+
rainbow (3.0.0)
|
60
66
|
rake (13.0.1)
|
61
67
|
rb-fsevent (0.10.3)
|
62
68
|
rb-inotify (0.10.1)
|
63
69
|
ffi (~> 1.0)
|
70
|
+
rexml (3.2.4)
|
64
71
|
rspec (3.9.0)
|
65
72
|
rspec-core (~> 3.9.0)
|
66
73
|
rspec-expectations (~> 3.9.0)
|
@@ -77,6 +84,15 @@ GEM
|
|
77
84
|
rspec (>= 3)
|
78
85
|
terminal-notifier (>= 1.4)
|
79
86
|
rspec-support (3.9.2)
|
87
|
+
rubocop (0.82.0)
|
88
|
+
jaro_winkler (~> 1.5.1)
|
89
|
+
parallel (~> 1.10)
|
90
|
+
parser (>= 2.7.0.1)
|
91
|
+
rainbow (>= 2.2.2, < 4.0)
|
92
|
+
rexml
|
93
|
+
ruby-progressbar (~> 1.7)
|
94
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
95
|
+
ruby-progressbar (1.10.1)
|
80
96
|
shellany (0.0.1)
|
81
97
|
simplecov (0.18.5)
|
82
98
|
docile (~> 1.1)
|
@@ -87,6 +103,7 @@ GEM
|
|
87
103
|
thread_safe (0.3.6)
|
88
104
|
tzinfo (1.2.7)
|
89
105
|
thread_safe (~> 0.1)
|
106
|
+
unicode-display_width (1.7.0)
|
90
107
|
zeitwerk (2.3.0)
|
91
108
|
|
92
109
|
PLATFORMS
|
@@ -102,6 +119,7 @@ DEPENDENCIES
|
|
102
119
|
rake (~> 13.0)
|
103
120
|
rspec (~> 3.0)
|
104
121
|
rspec-nc
|
122
|
+
rubocop
|
105
123
|
simplecov
|
106
124
|
|
107
125
|
BUNDLED WITH
|
data/Guardfile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# A sample Guardfile
|
2
4
|
# More info at https://github.com/guard/guard#readme
|
3
5
|
|
@@ -28,8 +30,6 @@ guard :rspec, cmd: "bundle exec rspec --format Nc --format documentation" do
|
|
28
30
|
require "guard/rspec/dsl"
|
29
31
|
dsl = Guard::RSpec::Dsl.new(self)
|
30
32
|
|
31
|
-
# Feel free to open issues for suggestions and improvements
|
32
|
-
|
33
33
|
# RSpec files
|
34
34
|
rspec = dsl.rspec
|
35
35
|
watch(rspec.spec_helper) { rspec.spec_dir }
|
@@ -39,32 +39,4 @@ guard :rspec, cmd: "bundle exec rspec --format Nc --format documentation" do
|
|
39
39
|
# Ruby files
|
40
40
|
ruby = dsl.ruby
|
41
41
|
dsl.watch_spec_files_for(ruby.lib_files)
|
42
|
-
|
43
|
-
# Rails files
|
44
|
-
rails = dsl.rails(view_extensions: %w(erb haml slim))
|
45
|
-
dsl.watch_spec_files_for(rails.app_files)
|
46
|
-
dsl.watch_spec_files_for(rails.views)
|
47
|
-
|
48
|
-
watch(rails.controllers) do |m|
|
49
|
-
[
|
50
|
-
rspec.spec.call("routing/#{m[1]}_routing"),
|
51
|
-
rspec.spec.call("controllers/#{m[1]}_controller"),
|
52
|
-
rspec.spec.call("acceptance/#{m[1]}")
|
53
|
-
]
|
54
|
-
end
|
55
|
-
|
56
|
-
# Rails config changes
|
57
|
-
watch(rails.spec_helper) { rspec.spec_dir }
|
58
|
-
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
|
59
|
-
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
|
60
|
-
|
61
|
-
# Capybara features specs
|
62
|
-
watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
|
63
|
-
watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
|
64
|
-
|
65
|
-
# Turnip features and steps
|
66
|
-
watch(%r{^spec/acceptance/(.+)\.feature$})
|
67
|
-
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
|
68
|
-
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
|
69
|
-
end
|
70
42
|
end
|
data/README.md
CHANGED
@@ -37,7 +37,7 @@ class Task
|
|
37
37
|
include Mongoid::Document
|
38
38
|
include MongoidEnumerable
|
39
39
|
|
40
|
-
enumerable :status, %w
|
40
|
+
enumerable :status, %w[completed running failed waiting], default: "waiting"
|
41
41
|
end
|
42
42
|
```
|
43
43
|
|
@@ -57,13 +57,13 @@ task.waiting? # false
|
|
57
57
|
#### Default
|
58
58
|
Defines which value is the default for new documents. If not specified the first value is used as default.
|
59
59
|
```ruby
|
60
|
-
enumerable :status, %w
|
60
|
+
enumerable :status, %w[completed running failed waiting], default: "waiting"
|
61
61
|
```
|
62
62
|
#### Prefix
|
63
63
|
You can define a prefix for your methods that could be useful if you have more than one enumerable with the same values.
|
64
64
|
```ruby
|
65
|
-
enumerable :build_status, %w
|
66
|
-
enumerable :deploy_status, %w
|
65
|
+
enumerable :build_status, %w[completed running failed waiting], default: "waiting", prefix: "build_"
|
66
|
+
enumerable :deploy_status, %w[completed running failed waiting], default: "waiting", prefix: "deploy_"
|
67
67
|
|
68
68
|
task.build_completed?
|
69
69
|
task.build_failed!
|
@@ -82,7 +82,7 @@ class Task
|
|
82
82
|
include Mongoid::Document
|
83
83
|
include MongoidEnumerable
|
84
84
|
|
85
|
-
enumerable :status, %w
|
85
|
+
enumerable :status, %w[completed running failed waiting], default: "waiting", before_change: :can_status_change?
|
86
86
|
|
87
87
|
def can_status_change?(old_value, new_value)
|
88
88
|
new_value != "waiting"
|
@@ -108,7 +108,7 @@ class Task
|
|
108
108
|
include Mongoid::Document
|
109
109
|
include MongoidEnumerable
|
110
110
|
|
111
|
-
enumerable :status, %w
|
111
|
+
enumerable :status, %w[completed running failed waiting],
|
112
112
|
default: "waiting",
|
113
113
|
after_change: :status_changed
|
114
114
|
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
data/lib/mongoid_enumerable.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "mongoid_enumerable/version"
|
2
4
|
require "mongoid"
|
3
5
|
|
@@ -6,8 +8,6 @@ module MongoidEnumerable
|
|
6
8
|
define_enumerable_methods(model)
|
7
9
|
end
|
8
10
|
|
9
|
-
private
|
10
|
-
|
11
11
|
def self.define_enumerable_methods(model)
|
12
12
|
model.define_singleton_method :enumerable do |field_name, values, options = {}|
|
13
13
|
MongoidEnumerable.define_enumerable_method(
|
@@ -48,24 +48,24 @@ module MongoidEnumerable
|
|
48
48
|
value_before = send(field_name)
|
49
49
|
value_after = value
|
50
50
|
|
51
|
-
callback_result = run_callback(
|
52
|
-
|
51
|
+
callback_result = run_callback(callback_method_name: before_change,
|
52
|
+
value_before: value_before, value_after: value_after)
|
53
53
|
|
54
54
|
if callback_result
|
55
55
|
update!(field_name => value)
|
56
|
-
run_callback(
|
57
|
-
|
56
|
+
run_callback(callback_method_name: after_change,
|
57
|
+
value_before: value_before, value_after: value_after)
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
define_method("#{method_name}?") do
|
61
|
+
model.define_method("#{method_name}?") do
|
62
62
|
send(field_name) == value
|
63
63
|
end
|
64
64
|
|
65
65
|
model.scope method_name, -> { where(field_name => value) }
|
66
66
|
end
|
67
67
|
|
68
|
-
def run_callback(
|
68
|
+
def run_callback(callback_method_name:, value_before:, value_after:)
|
69
69
|
if callback_method_name
|
70
70
|
callback_method = method(callback_method_name)
|
71
71
|
validate_callback_method(method: callback_method)
|
@@ -77,8 +77,8 @@ module MongoidEnumerable
|
|
77
77
|
end
|
78
78
|
|
79
79
|
def validate_callback_method(method:)
|
80
|
-
if method.arity
|
81
|
-
|
82
|
-
|
80
|
+
return if method.arity == 2 || method.arity.negative?
|
81
|
+
|
82
|
+
raise "Method #{method.name} must receive two parameters: old_value and new_value"
|
83
83
|
end
|
84
84
|
end
|
data/mongoid_enumerable.gemspec
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
|
-
lib = File.expand_path("
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require "mongoid_enumerable/version"
|
5
6
|
|
@@ -9,8 +10,8 @@ Gem::Specification.new do |spec|
|
|
9
10
|
spec.authors = ["Douglas Lise"]
|
10
11
|
spec.email = ["douglaslise@gmail.com"]
|
11
12
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
13
|
+
spec.summary = "Mongoid Enumerable"
|
14
|
+
spec.description = "Mongoid Enumerable"
|
14
15
|
spec.homepage = "https://github.com/douglaslise/mongoid_enumerable"
|
15
16
|
|
16
17
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
@@ -21,13 +22,14 @@ Gem::Specification.new do |spec|
|
|
21
22
|
spec.require_paths = ["lib"]
|
22
23
|
|
23
24
|
spec.add_development_dependency "bundler"
|
24
|
-
spec.add_development_dependency "rake", "~> 13.0"
|
25
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
-
spec.add_development_dependency "rspec-nc"
|
27
|
-
spec.add_development_dependency "mongoid"
|
28
25
|
spec.add_development_dependency "byebug"
|
29
26
|
spec.add_development_dependency "guard"
|
30
27
|
spec.add_development_dependency "guard-rspec"
|
28
|
+
spec.add_development_dependency "mongoid"
|
29
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
30
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
31
|
+
spec.add_development_dependency "rspec-nc"
|
32
|
+
spec.add_development_dependency "rubocop"
|
31
33
|
spec.add_dependency "mongoid", ">= 4.0"
|
32
34
|
spec.add_development_dependency "simplecov"
|
33
35
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_enumerable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Douglas Lise
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -25,35 +25,35 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: byebug
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
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: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: guard
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name: rspec
|
56
|
+
name: guard-rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -81,21 +81,35 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: rake
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
89
|
+
version: '13.0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
96
|
+
version: '13.0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec-nc
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
100
114
|
requirements:
|
101
115
|
- - ">="
|
@@ -109,7 +123,7 @@ dependencies:
|
|
109
123
|
- !ruby/object:Gem::Version
|
110
124
|
version: '0'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
126
|
+
name: rubocop
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
114
128
|
requirements:
|
115
129
|
- - ">="
|
@@ -159,6 +173,7 @@ extra_rdoc_files: []
|
|
159
173
|
files:
|
160
174
|
- ".gitignore"
|
161
175
|
- ".rspec"
|
176
|
+
- ".rubocop.yml"
|
162
177
|
- ".travis.yml"
|
163
178
|
- Gemfile
|
164
179
|
- Gemfile.lock
|