act_with_flags 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +7 -0
- data/Gemfile.lock +2 -2
- data/README.md +3 -1
- data/lib/act_with_flags/admin.rb +1 -1
- data/lib/act_with_flags/define.rb +17 -7
- data/lib/act_with_flags/print.rb +1 -1
- data/lib/act_with_flags/version.rb +3 -1
- data/test/string_test.rb +26 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8fcd67cda48d6e4cfd196f207c0e75e900ecfbfbf1e1272e4ea1d6f615c5887
|
4
|
+
data.tar.gz: 1832f914f676278b466214b52b06b6025df3769cb3d6c03841ca39a0e2eaa642
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa1a7850e27c943c06699bf2a57f214877813ab24fe2609f7c309884e7b4b0fe85b30f3072e244c6ecde5c7e1455c5993157904151733d325105ef1ca4db2276
|
7
|
+
data.tar.gz: 349513493947bde629f6e913af605394408ca18315822f4f0e05ab55b6b5a63854ac42c79477637b05599c3c22f21cccba83202ed5af0348732053a4a38719aa
|
data/.gitignore
ADDED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
act_with_flags (0.0.
|
4
|
+
act_with_flags (0.0.6)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -56,7 +56,7 @@ GEM
|
|
56
56
|
erubi (1.8.0)
|
57
57
|
globalid (0.4.2)
|
58
58
|
activesupport (>= 4.2.0)
|
59
|
-
i18n (1.
|
59
|
+
i18n (1.6.0)
|
60
60
|
concurrent-ruby (~> 1.0)
|
61
61
|
json (2.2.0)
|
62
62
|
loofah (2.2.3)
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# ActWithFlags
|
2
|
+
[](http://badge.fury.io/rb/act_with_flags)
|
3
|
+
[](https://travis-ci.org/matique/act_with_flags)
|
2
4
|
|
3
|
-
|
5
|
+
Required by key.matique.
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
data/lib/act_with_flags/admin.rb
CHANGED
@@ -12,7 +12,7 @@ class ActWithFlags::Admin
|
|
12
12
|
@origin = :flags
|
13
13
|
@map = {}
|
14
14
|
@delete_mask = 0
|
15
|
-
@max_position =
|
15
|
+
@max_position = 512 - 1
|
16
16
|
@boolean_hash = {}
|
17
17
|
[true, 'true', 1, '1'].each { |x| @boolean_hash[x] = true }
|
18
18
|
[false, 'false', 0, '0'].each { |x| @boolean_hash[x] = false }
|
@@ -10,18 +10,28 @@ class ActWithFlags::Admin
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def #{accessor}?
|
13
|
-
|
13
|
+
if #{origin}.is_a?(String)
|
14
|
+
flags = self.#{origin}.to_i
|
15
|
+
!( flags & #{mask} ).zero?
|
16
|
+
else
|
17
|
+
!( self.#{origin} & #{mask} ).zero?
|
18
|
+
end
|
14
19
|
end
|
15
20
|
|
16
21
|
def #{accessor}=(value)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
22
|
+
is_a_string = #{origin}.is_a?(String)
|
23
|
+
flags = is_a_string ? self.#{origin}.to_i : self.#{origin}
|
24
|
+
flags ||= 0
|
25
|
+
|
26
|
+
result = self.class.act_with_flags.to_boolean(value)
|
27
|
+
if result
|
28
|
+
flags |= #{mask}
|
21
29
|
else
|
22
|
-
|
23
|
-
false
|
30
|
+
flags &= ~#{mask}
|
24
31
|
end
|
32
|
+
self.#{origin} = is_a_string ? flags.to_s : flags
|
33
|
+
|
34
|
+
result
|
25
35
|
end
|
26
36
|
)
|
27
37
|
end
|
data/lib/act_with_flags/print.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module ActWithFlags
|
4
|
-
VERSION = '0.0.
|
4
|
+
VERSION = '0.0.6' # 2019-03-08
|
5
|
+
# VERSION = '0.0.5' # 2019-03-05
|
6
|
+
# VERSION = '0.0.4' # 2019-03-03
|
5
7
|
# VERSION = '0.0.3' # 2019-03-01
|
6
8
|
# VERSION = '0.0.2' # 2019-02-28
|
7
9
|
# VERSION = '0.0.1' # 2019-02-24
|
data/test/string_test.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# rubocop:disable all
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
describe 'String Flag' do
|
5
|
+
let(:order) { Order.new }
|
6
|
+
|
7
|
+
def setup
|
8
|
+
reset_order
|
9
|
+
order.update bigflags: '0'
|
10
|
+
Order.add_to_flags a: 1000, origin: :bigflags
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'set and reset flag' do
|
14
|
+
assert order.bigflags.is_a?(String)
|
15
|
+
order.a = true
|
16
|
+
assert order.bigflags.is_a?(String)
|
17
|
+
assert_equal true, order.a
|
18
|
+
assert_equal true, order.a?
|
19
|
+
|
20
|
+
order.a = 'false'
|
21
|
+
assert order.bigflags.is_a?(String)
|
22
|
+
assert_equal false, order.a
|
23
|
+
assert_equal false, order.a?
|
24
|
+
end
|
25
|
+
|
26
|
+
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: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dittmar Krall
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -45,6 +45,7 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
+
- ".gitignore"
|
48
49
|
- ".rubocop.yml"
|
49
50
|
- ".ruby-gemset"
|
50
51
|
- ".ruby-version"
|
@@ -75,6 +76,7 @@ files:
|
|
75
76
|
- test/origin_test.rb
|
76
77
|
- test/remove_from_test.rb
|
77
78
|
- test/reset_test.rb
|
79
|
+
- test/string_test.rb
|
78
80
|
- test/test_helper.rb
|
79
81
|
homepage: http://matique.de
|
80
82
|
licenses:
|
@@ -113,4 +115,5 @@ test_files:
|
|
113
115
|
- test/origin_test.rb
|
114
116
|
- test/remove_from_test.rb
|
115
117
|
- test/reset_test.rb
|
118
|
+
- test/string_test.rb
|
116
119
|
- test/test_helper.rb
|