active_flags 0.1.0 → 0.2.0
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/README.md +3 -0
- data/lib/active_flags.rb +9 -1
- data/lib/active_flags/handler/flag_builder.rb +1 -1
- data/lib/active_flags/version.rb +1 -1
- 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: 37e82dc8c41afadca68b93d26556c7306fe4cd85ea13dc1ec0186ea616d3df7d
|
4
|
+
data.tar.gz: 54afcdf0ee74fce3c33b7b87fd5321f35e1e0e5d6a2c2a85945fc1a86a764585
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8576103bbda00fadd4a9e3a3c0a0c6c251008e5ba5d04500d83385dd824602a3cf2db16f8f53102d21aab958f7b5231835a2162d1a33f334fec885ad865a8ee7
|
7
|
+
data.tar.gz: d68b0707f7c9b53546333dcd4e25dd6bd3f8dfc478e815c0fba3cca49495414afcb57d3c9afa6f5724fac3618a0a140afc0150e86c6a579499cad84fe1df3657
|
data/README.md
CHANGED
@@ -68,6 +68,9 @@ And then you can declare as much flags as you want with no restriction:
|
|
68
68
|
user.update!(flags: { visible: 'true', active: 'true', diet: 'vegan', power: 'super saiyan' })
|
69
69
|
```
|
70
70
|
|
71
|
+
To access your flags, you now have 2 ways.
|
72
|
+
Either as a hash, with the `flags` method or as an ActiveFlag::Flags collection with the `flags_as_collection` method.
|
73
|
+
|
71
74
|
## Contributing
|
72
75
|
https://github.com/FidMe/active_flags
|
73
76
|
|
data/lib/active_flags.rb
CHANGED
@@ -7,13 +7,21 @@ module ActiveFlags
|
|
7
7
|
|
8
8
|
class_methods do
|
9
9
|
def has_flags(*authorized_flags)
|
10
|
-
has_many :
|
10
|
+
has_many :flags_as_collection, class_name: 'ActiveFlags::Flag', as: :subject
|
11
11
|
|
12
12
|
define_method(:flags=) do |flags|
|
13
13
|
Handler::FlagMapper.remap(authorized_flags, flags.symbolize_keys).each do |flag_attributes|
|
14
14
|
Handler::FlagBuilder.new(self, flag_attributes).save
|
15
15
|
end
|
16
16
|
end
|
17
|
+
|
18
|
+
define_method(:flags) do
|
19
|
+
hash_of_flags = {}
|
20
|
+
flags_as_collection.each do |flag|
|
21
|
+
hash_of_flags[flag.key.to_sym] = flag.value
|
22
|
+
end
|
23
|
+
hash_of_flags.with_indifferent_access
|
24
|
+
end
|
17
25
|
end
|
18
26
|
end
|
19
27
|
end
|
@@ -7,7 +7,7 @@ module ActiveFlags
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def save
|
10
|
-
@resource.
|
10
|
+
@resource.flags_as_collection << ActiveFlags::Flag.find_or_initialize_by(subject: @resource, key: @flag_attributes[:key]) do |flag_to_create|
|
11
11
|
flag_to_create.value = @flag_attributes[:value]
|
12
12
|
end
|
13
13
|
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.
|
4
|
+
version: 0.2.0
|
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-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|