act_with_flags 3.1.0 → 3.1.2

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
  SHA256:
3
- metadata.gz: 4e2b18cdaf7777bddb191c830bc942a6fd7c377a4267c8e7beae3b2ace3552e9
4
- data.tar.gz: 1aed1f1e86fdbdd1cff793c0296c1b6e23c7400dc43f7df17ad8e13c3b1998d0
3
+ metadata.gz: c6f3af684df146594e5adbebc473d3a46c789f4a27021421e4831ca10a893ab9
4
+ data.tar.gz: 9ea6c4313f83e3ab4e3811540e7bbb14a63b98c2a9bc9536136b9682bcb1f067
5
5
  SHA512:
6
- metadata.gz: 11154bcaf21ff519f34863fdb847ffefd1e9a2fb493cfcdd8d0e015de42b601a9b3bf20d9e914d0e8681f39e321194ba3a27048a74fb43ce3972b9844cf0f14c
7
- data.tar.gz: 4471f2dc9a7b48654fa9ea689e4f51e660f6eacb0012fc1ea75c43fd2cb9c91149c49243e24a78e4527407d4c75dd51e7b0066095efebb14f007eb3dda36a839
6
+ metadata.gz: 6e64f4c29f48415f5c9dc42239269ffae1668d3f0b270c722959db78d4206b4192f0c9b25283ae6494d5349bf428d98183c1e36803acfbbfd9f4ea4ef9063e93
7
+ data.tar.gz: 4ba44b4047ba9ddb283e85497bc2c6662b4341fb2a9e2955c81164cfcebf16aedc9c0b42a8447788e3ed9a6fcb83ac1fec465b7d11c4678ddc6c75ac08f89e1a
@@ -0,0 +1,14 @@
1
+ name: Lint
2
+ on: push
3
+ jobs:
4
+ lint:
5
+ runs-on: ubuntu-latest
6
+ steps:
7
+ - name: Checkout code
8
+ uses: actions/checkout@v2
9
+ - name: Set up Ruby
10
+ uses: ruby/setup-ruby@v1
11
+ with:
12
+ bundler-cache: true
13
+ - name: Run Standard
14
+ run: bundle exec standardrb
@@ -1,8 +1,7 @@
1
1
  # see also https://github.com/whitequark/parser/blob/master/.github/workflows/test.yml
2
2
  name: Rake
3
3
 
4
- #on: [push, pull_request]
5
- on: [push]
4
+ on: push
6
5
 
7
6
  jobs:
8
7
  test:
@@ -13,7 +12,7 @@ jobs:
13
12
  os: [ubuntu-latest]
14
13
  # Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
15
14
  # ruby: [2.5, 2.6, 2.7, '3.0', head, jruby, jruby-head, truffleruby, truffleruby-head]
16
- ruby: ["2.7.2", "3.0.1", "3.1.2"]
15
+ ruby: ["2.7.2", 3.0.1, head]
17
16
  test_command: ["bundle exec rake test"]
18
17
  runs-on: ${{ matrix.os }}
19
18
 
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-3.1.2
1
+ ruby-3.1.3
data/.watchr CHANGED
@@ -33,23 +33,23 @@ end
33
33
  def run_matching_files(base)
34
34
  base = base.split("_").first
35
35
  TESTING.each { |type|
36
- files = Dir["#{type}/**/*.rb"].select { |file| file =~ /#{base}_.*\.rb/ }
36
+ files = Dir["#{type}/**/*.rb"].select { |file| file =~ /#{base}_.*.rb/ }
37
37
  run_it type, files.join(" ") unless files.empty?
38
38
  }
39
39
  end
40
40
 
41
41
  TESTING.each { |type|
42
- watch("#{type}/#{type}_helper\.rb") { run_all_tests }
43
- watch("lib/.*\.rb") { run_all_tests }
44
- watch("#{type}/.*/*_#{type}\.rb") { |match| run_it type, match[0] }
45
- watch("#{type}/data/(.*)\.rb") { |match|
42
+ watch("#{type}/#{type}_helper.rb") { run_all_tests }
43
+ watch("lib/.*.rb") { run_all_tests }
44
+ watch("#{type}/.*/*_#{type}.rb") { |match| run_it type, match[0] }
45
+ watch("#{type}/data/(.*).rb") { |match|
46
46
  m1 = match[1]
47
47
  run_matching_files("#{type}/#{m1}/#{m1}_#{type}.rb")
48
48
  }
49
49
  }
50
50
 
51
51
  %w[rb erb haml slim].each { |type|
52
- watch("app/.*/(.*)\.#{type}") { |match|
52
+ watch("app/.*/(.*).#{type}") { |match|
53
53
  run_matching_files(match[1])
54
54
  }
55
55
  }
data/Gemfile CHANGED
@@ -4,9 +4,9 @@ gemspec
4
4
  gem "rails"
5
5
 
6
6
  group :test do
7
- gem "observr"
8
- gem "standardrb", require: false
9
- gem "simplecov", require: false
10
7
  gem "benchmark-ips"
8
+ gem "observr"
11
9
  gem "ricecream"
10
+ gem "simplecov", require: false
11
+ gem "standard", require: false
12
12
  end
data/Gemfile.lock CHANGED
@@ -1,72 +1,72 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- act_with_flags (3.1.0)
4
+ act_with_flags (3.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- actioncable (7.0.3.1)
10
- actionpack (= 7.0.3.1)
11
- activesupport (= 7.0.3.1)
9
+ actioncable (7.0.4)
10
+ actionpack (= 7.0.4)
11
+ activesupport (= 7.0.4)
12
12
  nio4r (~> 2.0)
13
13
  websocket-driver (>= 0.6.1)
14
- actionmailbox (7.0.3.1)
15
- actionpack (= 7.0.3.1)
16
- activejob (= 7.0.3.1)
17
- activerecord (= 7.0.3.1)
18
- activestorage (= 7.0.3.1)
19
- activesupport (= 7.0.3.1)
14
+ actionmailbox (7.0.4)
15
+ actionpack (= 7.0.4)
16
+ activejob (= 7.0.4)
17
+ activerecord (= 7.0.4)
18
+ activestorage (= 7.0.4)
19
+ activesupport (= 7.0.4)
20
20
  mail (>= 2.7.1)
21
21
  net-imap
22
22
  net-pop
23
23
  net-smtp
24
- actionmailer (7.0.3.1)
25
- actionpack (= 7.0.3.1)
26
- actionview (= 7.0.3.1)
27
- activejob (= 7.0.3.1)
28
- activesupport (= 7.0.3.1)
24
+ actionmailer (7.0.4)
25
+ actionpack (= 7.0.4)
26
+ actionview (= 7.0.4)
27
+ activejob (= 7.0.4)
28
+ activesupport (= 7.0.4)
29
29
  mail (~> 2.5, >= 2.5.4)
30
30
  net-imap
31
31
  net-pop
32
32
  net-smtp
33
33
  rails-dom-testing (~> 2.0)
34
- actionpack (7.0.3.1)
35
- actionview (= 7.0.3.1)
36
- activesupport (= 7.0.3.1)
34
+ actionpack (7.0.4)
35
+ actionview (= 7.0.4)
36
+ activesupport (= 7.0.4)
37
37
  rack (~> 2.0, >= 2.2.0)
38
38
  rack-test (>= 0.6.3)
39
39
  rails-dom-testing (~> 2.0)
40
40
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
41
- actiontext (7.0.3.1)
42
- actionpack (= 7.0.3.1)
43
- activerecord (= 7.0.3.1)
44
- activestorage (= 7.0.3.1)
45
- activesupport (= 7.0.3.1)
41
+ actiontext (7.0.4)
42
+ actionpack (= 7.0.4)
43
+ activerecord (= 7.0.4)
44
+ activestorage (= 7.0.4)
45
+ activesupport (= 7.0.4)
46
46
  globalid (>= 0.6.0)
47
47
  nokogiri (>= 1.8.5)
48
- actionview (7.0.3.1)
49
- activesupport (= 7.0.3.1)
48
+ actionview (7.0.4)
49
+ activesupport (= 7.0.4)
50
50
  builder (~> 3.1)
51
51
  erubi (~> 1.4)
52
52
  rails-dom-testing (~> 2.0)
53
53
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
54
- activejob (7.0.3.1)
55
- activesupport (= 7.0.3.1)
54
+ activejob (7.0.4)
55
+ activesupport (= 7.0.4)
56
56
  globalid (>= 0.3.6)
57
- activemodel (7.0.3.1)
58
- activesupport (= 7.0.3.1)
59
- activerecord (7.0.3.1)
60
- activemodel (= 7.0.3.1)
61
- activesupport (= 7.0.3.1)
62
- activestorage (7.0.3.1)
63
- actionpack (= 7.0.3.1)
64
- activejob (= 7.0.3.1)
65
- activerecord (= 7.0.3.1)
66
- activesupport (= 7.0.3.1)
57
+ activemodel (7.0.4)
58
+ activesupport (= 7.0.4)
59
+ activerecord (7.0.4)
60
+ activemodel (= 7.0.4)
61
+ activesupport (= 7.0.4)
62
+ activestorage (7.0.4)
63
+ actionpack (= 7.0.4)
64
+ activejob (= 7.0.4)
65
+ activerecord (= 7.0.4)
66
+ activesupport (= 7.0.4)
67
67
  marcel (~> 1.0)
68
68
  mini_mime (>= 1.1.0)
69
- activesupport (7.0.3.1)
69
+ activesupport (7.0.4)
70
70
  concurrent-ruby (~> 1.0, >= 1.0.2)
71
71
  i18n (>= 1.6, < 2)
72
72
  minitest (>= 5.1)
@@ -84,92 +84,91 @@ GEM
84
84
  thor (>= 0.14.6)
85
85
  concurrent-ruby (1.1.10)
86
86
  crass (1.0.6)
87
- digest (3.1.0)
87
+ date (3.3.1)
88
88
  docile (1.4.0)
89
89
  erubi (1.11.0)
90
90
  globalid (1.0.0)
91
91
  activesupport (>= 5.0)
92
92
  i18n (1.12.0)
93
93
  concurrent-ruby (~> 1.0)
94
- json (2.6.2)
95
- loofah (2.18.0)
94
+ json (2.6.3)
95
+ language_server-protocol (3.17.0.2)
96
+ loofah (2.19.0)
96
97
  crass (~> 1.0.2)
97
98
  nokogiri (>= 1.5.9)
98
- mail (2.7.1)
99
+ mail (2.8.0)
99
100
  mini_mime (>= 0.1.1)
101
+ net-imap
102
+ net-pop
103
+ net-smtp
100
104
  marcel (1.0.2)
101
105
  method_source (1.0.0)
102
106
  mini_mime (1.1.2)
103
107
  minitest (5.16.3)
104
- net-imap (0.2.3)
105
- digest
108
+ net-imap (0.3.2)
109
+ date
106
110
  net-protocol
107
- strscan
108
- net-pop (0.1.1)
109
- digest
111
+ net-pop (0.1.2)
110
112
  net-protocol
113
+ net-protocol (0.2.1)
111
114
  timeout
112
- net-protocol (0.1.3)
113
- timeout
114
- net-smtp (0.3.1)
115
- digest
115
+ net-smtp (0.3.3)
116
116
  net-protocol
117
- timeout
118
117
  nio4r (2.5.8)
119
- nokogiri (1.13.8-x86_64-linux)
118
+ nokogiri (1.13.10-x86_64-linux)
120
119
  racc (~> 1.4)
121
120
  observr (1.0.5)
122
121
  parallel (1.22.1)
123
- parser (3.1.2.1)
122
+ parser (3.1.3.0)
124
123
  ast (~> 2.4.1)
125
- racc (1.6.0)
124
+ racc (1.6.1)
126
125
  rack (2.2.4)
127
126
  rack-test (2.0.2)
128
127
  rack (>= 1.3)
129
- rails (7.0.3.1)
130
- actioncable (= 7.0.3.1)
131
- actionmailbox (= 7.0.3.1)
132
- actionmailer (= 7.0.3.1)
133
- actionpack (= 7.0.3.1)
134
- actiontext (= 7.0.3.1)
135
- actionview (= 7.0.3.1)
136
- activejob (= 7.0.3.1)
137
- activemodel (= 7.0.3.1)
138
- activerecord (= 7.0.3.1)
139
- activestorage (= 7.0.3.1)
140
- activesupport (= 7.0.3.1)
128
+ rails (7.0.4)
129
+ actioncable (= 7.0.4)
130
+ actionmailbox (= 7.0.4)
131
+ actionmailer (= 7.0.4)
132
+ actionpack (= 7.0.4)
133
+ actiontext (= 7.0.4)
134
+ actionview (= 7.0.4)
135
+ activejob (= 7.0.4)
136
+ activemodel (= 7.0.4)
137
+ activerecord (= 7.0.4)
138
+ activestorage (= 7.0.4)
139
+ activesupport (= 7.0.4)
141
140
  bundler (>= 1.15.0)
142
- railties (= 7.0.3.1)
141
+ railties (= 7.0.4)
143
142
  rails-dom-testing (2.0.3)
144
143
  activesupport (>= 4.2.0)
145
144
  nokogiri (>= 1.6)
146
145
  rails-html-sanitizer (1.4.3)
147
146
  loofah (~> 2.3)
148
- railties (7.0.3.1)
149
- actionpack (= 7.0.3.1)
150
- activesupport (= 7.0.3.1)
147
+ railties (7.0.4)
148
+ actionpack (= 7.0.4)
149
+ activesupport (= 7.0.4)
151
150
  method_source
152
151
  rake (>= 12.2)
153
152
  thor (~> 1.0)
154
153
  zeitwerk (~> 2.5)
155
154
  rainbow (3.1.1)
156
155
  rake (13.0.6)
157
- regexp_parser (2.5.0)
156
+ regexp_parser (2.6.1)
158
157
  rexml (3.2.5)
159
158
  ricecream (0.2.1)
160
- rubocop (1.35.0)
159
+ rubocop (1.39.0)
161
160
  json (~> 2.3)
162
161
  parallel (~> 1.10)
163
162
  parser (>= 3.1.2.1)
164
163
  rainbow (>= 2.2.2, < 4.0)
165
164
  regexp_parser (>= 1.8, < 3.0)
166
165
  rexml (>= 3.2.5, < 4.0)
167
- rubocop-ast (>= 1.20.1, < 2.0)
166
+ rubocop-ast (>= 1.23.0, < 2.0)
168
167
  ruby-progressbar (~> 1.7)
169
168
  unicode-display_width (>= 1.4.0, < 3.0)
170
- rubocop-ast (1.21.0)
169
+ rubocop-ast (1.24.0)
171
170
  parser (>= 3.1.1.0)
172
- rubocop-performance (1.14.3)
171
+ rubocop-performance (1.15.1)
173
172
  rubocop (>= 1.7.0, < 2.0)
174
173
  rubocop-ast (>= 0.4.0)
175
174
  ruby-progressbar (1.11.0)
@@ -179,22 +178,20 @@ GEM
179
178
  simplecov_json_formatter (~> 0.1)
180
179
  simplecov-html (0.12.3)
181
180
  simplecov_json_formatter (0.1.4)
182
- sqlite3 (1.4.4)
183
- standard (1.16.0)
184
- rubocop (= 1.35.0)
185
- rubocop-performance (= 1.14.3)
186
- standardrb (1.0.1)
187
- standard
188
- strscan (3.0.4)
181
+ sqlite3 (1.5.4-x86_64-linux)
182
+ standard (1.19.1)
183
+ language_server-protocol (~> 3.17.0.2)
184
+ rubocop (= 1.39.0)
185
+ rubocop-performance (= 1.15.1)
189
186
  thor (1.2.1)
190
- timeout (0.3.0)
187
+ timeout (0.3.1)
191
188
  tzinfo (2.0.5)
192
189
  concurrent-ruby (~> 1.0)
193
- unicode-display_width (2.2.0)
190
+ unicode-display_width (2.3.0)
194
191
  websocket-driver (0.7.5)
195
192
  websocket-extensions (>= 0.1.0)
196
193
  websocket-extensions (0.1.5)
197
- zeitwerk (2.6.0)
194
+ zeitwerk (2.6.6)
198
195
 
199
196
  PLATFORMS
200
197
  x86_64-linux
@@ -212,7 +209,7 @@ DEPENDENCIES
212
209
  ricecream
213
210
  simplecov
214
211
  sqlite3
215
- standardrb
212
+ standard
216
213
 
217
214
  BUNDLED WITH
218
- 2.3.14
215
+ 2.3.26
data/README.md CHANGED
@@ -23,9 +23,50 @@ $ gem install act_with_flags
23
23
  ```
24
24
 
25
25
 
26
- ## Version 3.1.x
26
+ ## Version 3.1.1
27
27
 
28
- Added option "range" limiting the position of booleans.
28
+ Option "range" can be specified just once for all
29
+ "add_to_flags" for a specific "origin".
30
+
31
+ For example:
32
+ ~~~ruby
33
+ Order.add_to_flags range: ..0
34
+ ...
35
+ Order.add_to_flags :a
36
+ ~~~
37
+
38
+ Same as:
39
+ ~~~ruby
40
+ Order.add_to_flags :a
41
+ ...
42
+ Order.add_to_flags range: ..0
43
+ ~~~
44
+
45
+ or:
46
+ ~~~ruby
47
+ Order.add_to_flags :a, range: ..0
48
+ ~~~
49
+
50
+ Examples for "range":
51
+ ~~~ruby
52
+ Order.add_to_flags range: 0..17 # legal flag position from 0 to 17
53
+ Order.add_to_flags range: ..17 # legal flag position from 0 to 17
54
+ Order.add_to_flags range: nil..17 # legal flag position from 0 to 17
55
+ Order.add_to_flags range: 3.. # legal flag position from 3 to big_number
56
+ Order.add_to_flags range: 3..nil # legal flag position from 3 to big_number
57
+ ~~~
58
+
59
+ Invalid ranges:
60
+ ~~~ruby
61
+ Order.add_to_flags range: -1..17 # range starting with a negative position
62
+ Order.add_to_flags range: :a..:z # invalid range
63
+ Order.add_to_flags range: "a".."z" # invalid range
64
+ ~~~
65
+
66
+
67
+ ## Version 3.1.0
68
+
69
+ Added option "range" limiting the position of flags.
29
70
 
30
71
  An example:
31
72
  ```ruby
@@ -84,6 +125,7 @@ Further reading:
84
125
  - [gem active_flag](https://github.com/kenn/active_flag)
85
126
  - [gem has-bit-field](https://github.com/pjb3/has-bit-field)
86
127
  - [gem bitfield_attribute](https://github.com/gzigzigzeo/bitfield_attribute)
128
+ - [gem bitwise](https://github.com/kenn/bitwise)
87
129
 
88
130
 
89
131
  ## License MIT
@@ -1,11 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ActWithFlags::Admin
4
- attr_reader :model
4
+ attr_reader :model, :ranges
5
5
 
6
6
  def initialize(model)
7
7
  @locations = {}
8
8
  @clears = {}
9
+ @ranges = {}
9
10
  @model = model
10
11
  @boolean_hash = {}
11
12
  [true, "true", 1, "1"].each { |x| @boolean_hash[x] = true }
@@ -5,7 +5,6 @@ class ActWithFlags::Admin
5
5
  res = []
6
6
  res << title("Variables")
7
7
  res << variables(:boolean_hash)
8
- res << variables(:delete_mask)
9
8
 
10
9
  res << blk("Flags sorted alfabetically") { |key, loc|
11
10
  "#{key} #{loc}"
@@ -17,6 +16,8 @@ class ActWithFlags::Admin
17
16
  "FLAG_#{key.upcase} = #{sprintf("0x%08X", mask(key))}"
18
17
  }
19
18
 
19
+ res << title("@ranges")
20
+ res << @ranges
20
21
  res << title("@locations")
21
22
  res << @locations
22
23
  res.flatten.join("\n")
@@ -1,19 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ActWithFlags::Admin
4
- def add_flag(name, pos, origin, range)
4
+ def add_flag(name, pos, origin)
5
+ range = ranges[origin]
5
6
  accessor = name.to_sym
6
7
  validate_accessor accessor, "#{accessor}?", "#{accessor}="
7
8
 
8
9
  pos = check_pos(model, origin, pos)
10
+ msg = "Invalid position <#{pos}>"
11
+ raise(ArgumentError, msg) unless pos.is_a?(Integer)
12
+ raise(ArgumentError, msg) unless pos >= 0
9
13
  loc = Location.new(model, origin, pos)
10
14
  add_to_locations accessor, loc
11
15
 
12
- unless range.nil?
13
- unless range.cover?(pos)
14
- raise RangeError, "Position <#{loc.position}> out of range <#{range}>"
15
- end
16
- end
16
+ validate_position(range, pos)
17
17
 
18
18
  mask = mask(accessor)
19
19
  add_accessors(accessor, origin, mask)
@@ -50,6 +50,14 @@ class ActWithFlags::Admin
50
50
  reset_model model
51
51
  end
52
52
 
53
+ def validate_position(range, position)
54
+ return if range.nil?
55
+ return if range.cover?(position)
56
+
57
+ msg = "Position #{position} out of range #{range}"
58
+ raise RangeError, msg
59
+ end
60
+
53
61
  private
54
62
 
55
63
  def validate_accessor(*names)
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActWithFlags
4
- VERSION = "3.1.0" # 2022-08-29
4
+ VERSION = "3.1.2" # 2022-12-12
5
+ # VERSION = "3.1.1" # 2022-09-01
6
+ # VERSION = "3.1.0" # 2022-08-29
5
7
  # VERSION = "3.0.1" # 2022-08-07
6
8
  # VERSION = "3.0.0" # 2022-07-27
7
9
  # VERSION = "0.2.4" # 2021-06-21
@@ -14,13 +14,11 @@ module ActWithFlags
14
14
  attr_reader :act_with_flags
15
15
 
16
16
  def add_to_flags(*flags, origin: :flags, range: nil, **hash)
17
- unless @act_with_flags
18
- @act_with_flags ||= ActWithFlags::Admin.new self
19
- @act_with_flags.add_mask_et_all origin
20
- end
17
+ origin = origin.to_sym
18
+ init(origin, range)
21
19
 
22
- flags.each { |name| @act_with_flags.add_flag(name, nil, origin, range) }
23
- hash.each { |name, pos| @act_with_flags.add_flag(name, pos, origin, range) }
20
+ flags.each { |name| @act_with_flags.add_flag(name, nil, origin) }
21
+ hash.each { |name, pos| @act_with_flags.add_flag(name, pos, origin) }
24
22
 
25
23
  @act_with_flags
26
24
  end
@@ -32,6 +30,45 @@ module ActWithFlags
32
30
  def clear_flags_at_save(*flags)
33
31
  @act_with_flags.clear_at_save(*flags)
34
32
  end
33
+
34
+ private
35
+
36
+ def init(origin, range)
37
+ unless @act_with_flags
38
+ @act_with_flags ||= ActWithFlags::Admin.new self
39
+ @act_with_flags.add_mask_et_all origin
40
+ end
41
+
42
+ unless range.nil?
43
+ validate_range_value range.begin
44
+ validate_range_value range.end
45
+ end
46
+
47
+ rng = @act_with_flags.ranges[origin]
48
+ unless range.nil? || (range == rng)
49
+ msg = "incompatible ranges #{range} - #{rng}"
50
+ raise ArgumentError, msg unless rng.nil?
51
+ @act_with_flags.ranges[origin] = range if range
52
+ validate_previous_positions(origin, range)
53
+ end
54
+ end
55
+
56
+ def validate_previous_positions(origin, range)
57
+ return if range.nil?
58
+
59
+ @act_with_flags.locations.each do |name, location|
60
+ next unless location.origin == origin
61
+
62
+ @act_with_flags.validate_position(range, location.position)
63
+ end
64
+ end
65
+
66
+ def validate_range_value(range_value)
67
+ return if range_value.nil?
68
+ return if range_value.is_a?(Integer) && range_value >= 0
69
+
70
+ raise RangeError, "Invalid range value #{range_value}"
71
+ end
35
72
  end
36
73
  end
37
74
 
@@ -1,7 +1,7 @@
1
1
  require "test_helper"
2
2
 
3
3
  describe "any? all? and none?" do
4
- let(:order) { Order.create }
4
+ let(:order) { Order.new }
5
5
 
6
6
  def setup
7
7
  reset_order
@@ -6,8 +6,8 @@ require "benchmark"
6
6
  require "benchmark/ips"
7
7
  # ENV["MORE"] = "true"
8
8
 
9
- describe "Internal timings flag" do
10
- let(:order) { Order.create }
9
+ describe "Internal timings" do
10
+ let(:order) { Order.new }
11
11
 
12
12
  def setup
13
13
  reset_order
@@ -30,7 +30,7 @@ describe "Internal timings flag" do
30
30
  end
31
31
 
32
32
  describe "Internal timings mask" do
33
- let(:order) { Order.create }
33
+ let(:order) { Order.new }
34
34
  let(:admin) { Order.act_with_flags }
35
35
 
36
36
  def setup
@@ -62,7 +62,7 @@ class BenchFoo < Minitest::Benchmark
62
62
  n = 100_000
63
63
  n = 10_000
64
64
  Order.add_to_flags :blocked2
65
- order = Order.create
65
+ order = Order.new
66
66
  assert_performance_constant do |input|
67
67
  n.times do
68
68
  order.blocked2 = true
@@ -1,14 +1,14 @@
1
1
  require "test_helper"
2
2
 
3
- describe "Internal check add flag" do
4
- let(:order) { Order.create }
3
+ describe "Internal check add_to_" do
4
+ let(:order) { Order.new }
5
5
 
6
6
  def setup
7
7
  reset_order
8
8
  Order.add_to_flags a: 1, b: 7
9
9
  end
10
10
 
11
- it "skip reserved position" do
11
+ it "skips reserved position" do
12
12
  Order.add_to_flags :xx
13
13
  order.xx = true
14
14
  assert_equal 0x100, order.flags
@@ -1,7 +1,7 @@
1
1
  require "test_helper"
2
2
 
3
3
  describe "Coverage" do
4
- let(:order) { Order.create }
4
+ let(:order) { Order.new }
5
5
 
6
6
  def setup
7
7
  reset_order
@@ -8,7 +8,7 @@ describe "Internal Null" do
8
8
  Order.add_to_flags
9
9
  end
10
10
 
11
- it "respond to act_with_flags" do
11
+ it "respond to act_with_" do
12
12
  assert Order.respond_to?(:act_with_flags)
13
13
  refute_nil Order.act_with_flags
14
14
  end
@@ -10,14 +10,14 @@ describe "Internal One Flag" do
10
10
  Order.add_to_flags flag
11
11
  end
12
12
 
13
- it "test order.act_with_flags" do
13
+ it "test order.act_with_" do
14
14
  refute_nil admin
15
15
  assert_equal admin, order.class.act_with_flags
16
16
  assert_equal admin, order.act_with_flags
17
17
  assert_equal admin, Order.act_with_flags
18
18
  end
19
19
 
20
- it "checks definition of methods for flag" do
20
+ it "checks definition of methods" do
21
21
  msg = "method '#{flag}' not defined"
22
22
  assert order.respond_to?(flag.to_s), msg
23
23
  assert order.respond_to?("#{flag}?"), msg
data/test/legacy_test.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  require "test_helper"
2
2
 
3
3
  describe "Legacy Flag" do
4
- let(:order) { Order.create }
4
+ let(:order) { Order.new }
5
5
 
6
6
  def setup
7
7
  reset_order
8
- Order.add_to_flags a: 1, b: 7, c: 3
8
+ Order.add_to_flags a: 1, c: 3, b: 7
9
9
  end
10
10
 
11
11
  it "set true" do
data/test/null_test.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require "test_helper"
2
2
 
3
3
  describe "No Flags" do
4
+ let(:order) { Order.new }
5
+
4
6
  def setup
5
7
  reset_order
6
8
  Order.add_to_flags
@@ -12,4 +14,11 @@ describe "No Flags" do
12
14
  assert Order.respond_to?(:clear_flags_at_save)
13
15
  assert Order.respond_to?(:act_with_flags)
14
16
  end
17
+
18
+ it "checks mask et all; no parameters" do
19
+ assert_equal 0, order.flags_mask
20
+ refute order.flags_any?
21
+ assert order.flags_all?
22
+ assert order.flags_none?
23
+ end
15
24
  end
data/test/one_test.rb CHANGED
@@ -2,14 +2,20 @@ require "test_helper"
2
2
 
3
3
  describe "One Flag" do
4
4
  let(:flag) { :blocked }
5
- let(:order) { Order.create }
5
+ let(:order) { Order.new }
6
6
 
7
7
  def setup
8
8
  reset_order
9
9
  Order.add_to_flags flag
10
10
  end
11
11
 
12
- it "set flag (:blocked)" do
12
+ it "checks defaults" do
13
+ refute_equal true, order.blocked
14
+ assert_equal false, order.blocked
15
+ assert_equal false, order.blocked?
16
+ end
17
+
18
+ it "set :blocked" do
13
19
  order.blocked = true
14
20
  assert_equal true, order.blocked
15
21
  assert_equal true, order.blocked?
@@ -0,0 +1,59 @@
1
+ require "test_helper"
2
+
3
+ describe "range #2" do
4
+ def setup
5
+ reset_order
6
+ end
7
+
8
+ it "succeeds specifying just a range" do
9
+ Order.add_to_flags range: 0...0
10
+ end
11
+
12
+ it "succeeds specifying just a (same) range with an origin" do
13
+ Order.add_to_flags range: 0..0
14
+ Order.add_to_flags range: 0..0, origin: :dummy
15
+ end
16
+
17
+ it "rejects more than one range specification" do
18
+ Order.add_to_flags range: 0..0
19
+ assert_raises(ArgumentError) { Order.add_to_flags range: 1..1 }
20
+ end
21
+
22
+ it "succeeds validation (pre specification of range)" do
23
+ Order.add_to_flags range: ..0
24
+ Order.add_to_flags :a
25
+ end
26
+
27
+ it "succeeds validation (post specification of range)" do
28
+ Order.add_to_flags :a
29
+ Order.add_to_flags range: ..0
30
+ end
31
+
32
+ it "fails validation (pre specification of range)" do
33
+ Order.add_to_flags range: (1..)
34
+ assert_raises(RangeError) { Order.add_to_flags :a }
35
+ end
36
+
37
+ it "fails validation (post specification of range)" do
38
+ Order.add_to_flags :b, origin: :hugo
39
+ Order.add_to_flags :a
40
+ assert_raises(RangeError) { Order.add_to_flags range: 1.. }
41
+ end
42
+
43
+ it "succeeds validation for two flags (post specification of range)" do
44
+ Order.add_to_flags :a, :b # bits 0 & 1
45
+ Order.add_to_flags range: ..1
46
+ end
47
+
48
+ it "rejects validation for two flags (post specification of range)" do
49
+ Order.add_to_flags :a, :b # bits 0 & 1
50
+ # :a (bit 0) triggers an exception on the validation of range
51
+ assert_raises(RangeError) { Order.add_to_flags range: 1.. }
52
+ end
53
+
54
+ it "rejects post validation" do
55
+ Order.add_to_flags :a, :b # bits 0 & 1
56
+ # :b (bit 1) triggers an exception on the validation of range
57
+ assert_raises(RangeError) { Order.add_to_flags range: ..0 }
58
+ end
59
+ end
@@ -0,0 +1,37 @@
1
+ require "test_helper"
2
+
3
+ describe "range #3" do
4
+ def setup
5
+ reset_order
6
+ end
7
+
8
+ it "accepts an integer as position" do
9
+ Order.add_to_flags a: 0
10
+ Order.add_to_flags b: 1
11
+ Order.add_to_flags c: 2
12
+ Order.add_to_flags d: 100
13
+
14
+ msk = Order.add_to_flags.mask(:a, :b, :c)
15
+ assert 0x07, msk
16
+
17
+ msk = Order.add_to_flags.mask(:d)
18
+ assert 0x10000000000000000000000000, msk
19
+ end
20
+
21
+ it "rejects ivalid position" do
22
+ assert_raises(ArgumentError) { Order.add_to_flags a: -1 }
23
+ assert_raises(ArgumentError) { Order.add_to_flags a: :a_symbol }
24
+ end
25
+
26
+ [0..0, 0..1, ..0, 1.., 100..100, 0...1, ...1, 1..., ...100].each do |range|
27
+ it "checks valid range #{range}" do
28
+ Order.add_to_flags range: range
29
+ end
30
+ end
31
+
32
+ [-1..0, :a..:z, "a".."z"].each do |range|
33
+ it "rejects invalid range #{range}" do
34
+ assert_raises(RangeError) { Order.add_to_flags range: range }
35
+ end
36
+ end
37
+ end
data/test/range_test.rb CHANGED
@@ -47,43 +47,4 @@ describe "range" do
47
47
  it "tests range ...0 no position" do
48
48
  assert_raises(RangeError) { Order.add_to_flags :a, range: ...0 }
49
49
  end
50
-
51
- # YAGNI
52
- # # includes range: ( .. 3 ) equivalent to range: ..3
53
- # n = 100
54
- # (0..n).each do |i|
55
- # rng = ..i
56
- #
57
- # (0..i).each do |j|
58
- # it "tests range ..#{i} with position #{j}" do
59
- # Order.add_to_flags a: j, range: rng
60
- # end
61
- # end
62
- #
63
- # it "fails range ..#{i} with position overflow" do
64
- # assert_raises(RangeError) { Order.add_to_flags b: (i + 1), range: rng }
65
- # end
66
- # end
67
- #
68
- # it "runs ii plus" do
69
- # ii = 0
70
- # (0..2).each { |íí|
71
- # sym = "x#{ii}".to_sym
72
- # j = f(ii, ii + 1) # filler
73
- # rand j
74
- # Order.add_to_flags :range => ii..f(íí, íí), sym => (ii += 1)
75
- # orden = Order.new
76
- # refute orden.send("#{sym}?") # checks that accessor is active
77
- # orden.x0 = true # checks that first accessor is still there
78
- # assert orden.x0?
79
- # }
80
- # end
81
- #
82
- # private
83
- #
84
- # def f(x, y)
85
- # return y + 1 if x == 0
86
- # return f(x - 1, 1) if y == 0
87
- # f(x - 1, f(x, y - 1))
88
- # end
89
50
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: act_with_flags
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dittmar Krall
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-29 00:00:00.000000000 Z
11
+ date: 2022-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -101,6 +101,7 @@ executables: []
101
101
  extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
+ - ".github/workflows/lint.yml"
104
105
  - ".github/workflows/rake.yml"
105
106
  - ".gitignore"
106
107
  - ".ruby-gemset"
@@ -151,6 +152,8 @@ files:
151
152
  - test/one_test.rb
152
153
  - test/origin_test.rb
153
154
  - test/origins_test.rb
155
+ - test/range2_test.rb
156
+ - test/range3_test.rb
154
157
  - test/range_test.rb
155
158
  - test/remove_from_test.rb
156
159
  - test/string_test.rb
@@ -175,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
178
  - !ruby/object:Gem::Version
176
179
  version: '0'
177
180
  requirements: []
178
- rubygems_version: 3.3.7
181
+ rubygems_version: 3.3.26
179
182
  signing_key:
180
183
  specification_version: 4
181
184
  summary: act_with_flags gem