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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c45ce9a931f85cd77d1f988795270597a0277f4433be52a07b5b3e033690bc82
4
- data.tar.gz: 0fd586a0f683c6e3c44f595be67856e661f698c5cefac4dd4e873d3941f06a80
3
+ metadata.gz: 714938aa39fae0199c5739e87be506f232d4cb349cc608f5a3de7b5d0e7adec5
4
+ data.tar.gz: 15e6c6147ecacacd4ca849e8e732d513a06008c3cb28967d369e92a72c98b86a
5
5
  SHA512:
6
- metadata.gz: 76278b47e78467575b32bb903a445086b031e833c07aa2997d8b8eed8afd65636c96b4a03fd990df19868a2346bec023b44680eda53e43e9fdf9106c2970c72e
7
- data.tar.gz: 53defe812363a6ae685ab1a4308984b2df806e692aa4ed1f5443d6bdba92805515a9e05abe041788a381a7faeb45f862c85b822833b699a319eecc539de3cc0f
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::Flags collection with the `flags_as_collection` method.
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::Flags` instance returned by flags_as_collection, to retrieved your 'true' or 'false' value as a boolean.
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
@@ -1,3 +1,3 @@
1
1
  module ActiveFlags
2
- VERSION = '0.3.5'
2
+ VERSION = '0.3.8'
3
3
  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.5
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: 2019-03-15 00:00:00.000000000 Z
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: 1.3.6
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: 1.3.6
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.1
91
+ rubygems_version: 3.0.3
92
92
  signing_key:
93
93
  specification_version: 4
94
94
  summary: Easily declare flags for your models.