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 +4 -4
- data/README.md +9 -8
- data/app/models/active_flags/flag.rb +6 -0
- data/lib/active_flags.rb +1 -1
- data/lib/active_flags/version.rb +1 -1
- data/lib/utils/value_stringifier.rb +10 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c45ce9a931f85cd77d1f988795270597a0277f4433be52a07b5b3e033690bc82
|
4
|
+
data.tar.gz: 0fd586a0f683c6e3c44f595be67856e661f698c5cefac4dd4e873d3941f06a80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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:
|
90
|
+
user = User.create!(flags: { visible: true })
|
89
91
|
|
90
92
|
User.flagged_as_visible
|
91
|
-
#
|
93
|
+
# #<ActiveRecord::Relation [#<User id: 1>]>
|
92
94
|
|
93
95
|
User.flagged_as_visible(false)
|
94
|
-
#
|
96
|
+
# #<ActiveRecord::Relation []>
|
95
97
|
|
96
98
|
User.flagged_as_intelligent
|
97
|
-
#
|
99
|
+
# #<ActiveRecord::Relation []>
|
98
100
|
|
99
101
|
user.update!(flags: { intelligent: true })
|
100
102
|
User.flagged_as_intelligent
|
101
|
-
#
|
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
|
-
#
|
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
|
-
#
|
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
|
data/lib/active_flags.rb
CHANGED
@@ -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.
|
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
|
data/lib/active_flags/version.rb
CHANGED
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
|
+
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-
|
11
|
+
date: 2019-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|