active_flags 0.3.4 → 0.3.5

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: a5e9e8a7d28e9b72164485acc16beb6e5e41fe28bb47fb80d98d2a9337d17b99
4
- data.tar.gz: 53926a68eff6f2ecf294fd076ec0616c159f57fe4137d785999a5a831d165275
3
+ metadata.gz: c45ce9a931f85cd77d1f988795270597a0277f4433be52a07b5b3e033690bc82
4
+ data.tar.gz: 0fd586a0f683c6e3c44f595be67856e661f698c5cefac4dd4e873d3941f06a80
5
5
  SHA512:
6
- metadata.gz: 32cae899f8cfb2f64f2ba25b868c981b2e36bf1bf947303a7bc27375b5efbf6cff22c11c2ec37cd73d43694922ad6bbb392c85d971c8dd89f4360ee84c24df8f
7
- data.tar.gz: 554eeb7c3c1973e1b56e31ee6d362e4dcb837a5b97b4fcbc59e34589ec1295966a208fcd4d7b302d3da22cee4208874b5a45b8bbc56c7d2404af677d8de0b984
6
+ metadata.gz: 76278b47e78467575b32bb903a445086b031e833c07aa2997d8b8eed8afd65636c96b4a03fd990df19868a2346bec023b44680eda53e43e9fdf9106c2970c72e
7
+ data.tar.gz: 53defe812363a6ae685ab1a4308984b2df806e692aa4ed1f5443d6bdba92805515a9e05abe041788a381a7faeb45f862c85b822833b699a319eecc539de3cc0f
data/README.md CHANGED
@@ -76,6 +76,8 @@ user.update!(flags: { visible: true, active: true, diet: 'vegan', power: 'super
76
76
  To access your flags, you now have 2 ways.
77
77
  Either as a hash, with the `flags` method or as an ActiveFlag::Flags collection with the `flags_as_collection` method.
78
78
 
79
+ Note: You can call `converted_value` on an `ActiveFlag::Flags` instance returned by flags_as_collection, to retrieved your 'true' or 'false' value as a boolean.
80
+
79
81
  ## Flags as scopes
80
82
 
81
83
  When you develop an app without active_flags, you will generally query the equivalent of flags as simple booleans.
@@ -85,35 +87,34 @@ ActiveFlags gives you a clean and simple way to query your model based on define
85
87
  Any flag can be queried as a scope using the `flagged_as` method
86
88
 
87
89
  ```ruby
88
- user = User.create!(flags: { visible: true })
90
+ user = User.create!(flags: { visible: true })
89
91
 
90
92
  User.flagged_as_visible
91
- # #<ActiveRecord::Relation [#<User id: 1>]>
93
+ # #<ActiveRecord::Relation [#<User id: 1>]>
92
94
 
93
95
  User.flagged_as_visible(false)
94
- # #<ActiveRecord::Relation []>
96
+ # #<ActiveRecord::Relation []>
95
97
 
96
98
  User.flagged_as_intelligent
97
- # #<ActiveRecord::Relation []>
99
+ # #<ActiveRecord::Relation []>
98
100
 
99
101
  user.update!(flags: { intelligent: true })
100
102
  User.flagged_as_intelligent
101
- # #<ActiveRecord::Relation [#<User id: 1>]>
103
+ # #<ActiveRecord::Relation [#<User id: 1>]>
102
104
 
103
105
  user.update!(flags: { intelligent: 'a bit' })
104
106
  User.flagged_as_intelligent('a_bit')
105
- # #<ActiveRecord::Relation [#<User id: 1>]>
107
+ # #<ActiveRecord::Relation [#<User id: 1>]>
106
108
  ```
107
109
 
108
110
  To query flags the other way around you can use the `not_flagged_as` method
109
111
 
110
112
  ```ruby
111
113
  User.not_flagged_as_intelligent
112
- # or with value
114
+ # or with value
113
115
  User.not_flagged_as_intelligent('a bit')
114
116
  ```
115
117
 
116
-
117
118
  ## Contributing
118
119
  https://github.com/FidMe/active_flags
119
120
 
@@ -1,8 +1,14 @@
1
+ require 'utils/value_stringifier'
2
+
1
3
  module ActiveFlags
2
4
  class Flag < ApplicationRecord
3
5
  belongs_to :subject, polymorphic: true
4
6
 
5
7
  validates :subject, :key, :value, presence: true
6
8
  validates :key, uniqueness: { scope: :subject }
9
+
10
+ def converted_value
11
+ self.value = unstringify(value)
12
+ end
7
13
  end
8
14
  end
@@ -21,7 +21,7 @@ module ActiveFlags
21
21
  define_method(:flags) do
22
22
  hash_of_flags = {}
23
23
  flags_as_collection.each do |flag|
24
- hash_of_flags[flag.key.to_sym] = flag.value
24
+ hash_of_flags[flag.key.to_sym] = flag.converted_value
25
25
  end
26
26
  hash_of_flags.with_indifferent_access
27
27
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveFlags
2
- VERSION = '0.3.4'
2
+ VERSION = '0.3.5'
3
3
  end
@@ -7,3 +7,13 @@ def stringify(value)
7
7
  value
8
8
  end
9
9
  end
10
+
11
+ def unstringify(value)
12
+ if value == 't' || value == 'true'
13
+ true
14
+ elsif value == 'f' || value == 'false' || value == nil
15
+ false
16
+ else
17
+ value
18
+ end
19
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_flags
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Huberty
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-14 00:00:00.000000000 Z
11
+ date: 2019-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails