act_with_flags 0.0.4 → 0.0.6

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: 764b0dadf19a5ee7278da0a985cfa7e7484bac02bbc22dfce2fa7b50234f652c
4
- data.tar.gz: 6b4b11c64ded7579b17a152a9927afe8fe4488fe71f1099186097ef14ee9c732
3
+ metadata.gz: e8fcd67cda48d6e4cfd196f207c0e75e900ecfbfbf1e1272e4ea1d6f615c5887
4
+ data.tar.gz: 1832f914f676278b466214b52b06b6025df3769cb3d6c03841ca39a0e2eaa642
5
5
  SHA512:
6
- metadata.gz: fcf79af0016d1143daff843c18e9397656e09fad8afec300a1a9588c20371df8237515bf0104390b40bece385a3fc3e24cd72dc30f38de54c89c1550d8cb4c0c
7
- data.tar.gz: 822850d797a7d1f9134e9ba6150fa6455d4a065c54b9653e7931d41336490d42e98d4fd77660ebf8dfcf57286e797e20c351ea396893b17a54effa7a7d56713e
6
+ metadata.gz: aa1a7850e27c943c06699bf2a57f214877813ab24fe2609f7c309884e7b4b0fe85b30f3072e244c6ecde5c7e1455c5993157904151733d325105ef1ca4db2276
7
+ data.tar.gz: 349513493947bde629f6e913af605394408ca18315822f4f0e05ab55b6b5a63854ac42c79477637b05599c3c22f21cccba83202ed5af0348732053a4a38719aa
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ .bundle/
2
+ coverage/
3
+
4
+ *.gem
5
+ *.log
6
+ *.lock
7
+ *.sqlite3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- act_with_flags (0.0.3)
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.5.3)
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
+ [![Gem Version](https://badge.fury.io/rb/act_with_flags.png)](http://badge.fury.io/rb/act_with_flags)
3
+ [![Build Status](https://travis-ci.org/matique/act_with_flags.png?branch=master)](https://travis-ci.org/matique/act_with_flags)
2
4
 
3
-
5
+ Required by key.matique.
4
6
 
5
7
  ## Installation
6
8
 
@@ -12,7 +12,7 @@ class ActWithFlags::Admin
12
12
  @origin = :flags
13
13
  @map = {}
14
14
  @delete_mask = 0
15
- @max_position = 128 - 1
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
- !( self.#{origin} & #{mask} ).zero?
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
- self.#{origin} ||= 0
18
- if self.class.act_with_flags.to_boolean(value)
19
- self.#{origin} |= #{mask}
20
- true
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
- self.#{origin} &= ~#{mask}
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
@@ -6,7 +6,7 @@ class ActWithFlags::Admin
6
6
  def to_s
7
7
  res = []
8
8
  res << title('Variables')
9
- res << variables(:origin, :max_position, :boolean_hash)
9
+ res << variables(:origin, :boolean_hash)
10
10
  res << variables(:delete_mask)
11
11
 
12
12
  res << title('Flags sorted alfabetically')
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActWithFlags
4
- VERSION = '0.0.4' # 2019-03-03
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
@@ -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
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-03 00:00:00.000000000 Z
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