active_flags 0.3.5 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/app/models/active_flags/flag.rb +16 -0
- data/lib/active_flags/handler/flag_builder.rb +1 -1
- data/lib/active_flags/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 714938aa39fae0199c5739e87be506f232d4cb349cc608f5a3de7b5d0e7adec5
|
4
|
+
data.tar.gz: 15e6c6147ecacacd4ca849e8e732d513a06008c3cb28967d369e92a72c98b86a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf78a1bad08cb4e58ce47e5aff8028125c60aea3b3efc9b1a385206e05b45cb8475336b1a443924f1aa74052daa0ae282e03fd30cbb9640efd7b89ca3687679b
|
7
|
+
data.tar.gz: 26a223bb2bc02d6d7d4033542b26f636a7a94551a3117862b6676171a36d291661a70c4369fb26f8846e9d63ab63e9eb7e001c6229dcecf4ba029eaf107d623a
|
data/README.md
CHANGED
@@ -74,9 +74,9 @@ user.update!(flags: { visible: true, active: true, diet: 'vegan', power: 'super
|
|
74
74
|
```
|
75
75
|
|
76
76
|
To access your flags, you now have 2 ways.
|
77
|
-
Either as a hash, with the `flags` method or as an ActiveFlag::
|
77
|
+
Either as a hash, with the `flags` method or as an ActiveFlag::Flag collection with the `flags_as_collection` method.
|
78
78
|
|
79
|
-
Note: You can call `converted_value` on an `ActiveFlag::
|
79
|
+
Note: You can call `converted_value` on an `ActiveFlag::Flag` instance returned by flags_as_collection, to retrieved your 'true' or 'false' value as a boolean.
|
80
80
|
|
81
81
|
## Flags as scopes
|
82
82
|
|
@@ -7,6 +7,22 @@ module ActiveFlags
|
|
7
7
|
validates :subject, :key, :value, presence: true
|
8
8
|
validates :key, uniqueness: { scope: :subject }
|
9
9
|
|
10
|
+
def removing_duplicated_needed?
|
11
|
+
ActiveFlags::Flag.where(subject: subject, key: key).any?
|
12
|
+
end
|
13
|
+
|
14
|
+
def removing_duplicated_flags!
|
15
|
+
return false unless removing_duplicated_needed?
|
16
|
+
grouped = ActiveFlags::Flag
|
17
|
+
.where(subject_id: subject_id, subject_type: subject_type, key: key)
|
18
|
+
.group_by { |model| [model.key, model.subject_id, model.subject_type] }
|
19
|
+
grouped.values.each do |duplicates|
|
20
|
+
duplicates.shift
|
21
|
+
duplicates.each(&:destroy)
|
22
|
+
end
|
23
|
+
true
|
24
|
+
end
|
25
|
+
|
10
26
|
def converted_value
|
11
27
|
self.value = unstringify(value)
|
12
28
|
end
|
@@ -8,8 +8,8 @@ module ActiveFlags
|
|
8
8
|
|
9
9
|
def save
|
10
10
|
flag = ActiveFlags::Flag.find_or_initialize_by(subject: @resource, key: @flag_attributes[:key])
|
11
|
+
flag.removing_duplicated_flags!
|
11
12
|
flag.update!(value: @flag_attributes[:value])
|
12
|
-
|
13
13
|
@resource.flags_as_collection << flag
|
14
14
|
end
|
15
15
|
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.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Huberty
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: sqlite3
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: '0'
|
41
41
|
description: Easily declare flags for your models.
|
42
42
|
email:
|
43
43
|
- nathan.huberty@orange.fr
|
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
requirements: []
|
91
|
-
rubygems_version: 3.0.
|
91
|
+
rubygems_version: 3.0.3
|
92
92
|
signing_key:
|
93
93
|
specification_version: 4
|
94
94
|
summary: Easily declare flags for your models.
|