active_regulation 2.2.5 → 2.2.6
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 +0 -5
- data/lib/active_regulation/activation.rb +4 -27
- data/lib/active_regulation/containment.rb +4 -27
- data/lib/active_regulation/expiration.rb +8 -27
- data/lib/active_regulation/version.rb +1 -1
- data/lib/active_regulation/visibility.rb +4 -27
- data/lib/active_regulation.rb +0 -1
- metadata +1 -2
- data/lib/active_regulation/base.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33792242a23654c0acd0e9eaafc2097f4480955c
|
4
|
+
data.tar.gz: 2fdaa474fef2d46740bb7ed129775f3e8bf664d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9888c1dd1393df50466a2e73784298d69ddafe461b7ebfa9cbea5e1d9abcb993652c8c8b206394b6b24259a8f3c226194ea471558a128f32fe95b2959dde8377
|
7
|
+
data.tar.gz: ab9c5874e9eb7acb3b85f1dd079eb3e78e1f74d8470c8d63e29cf8203fc093cbb2447e7ffd8f68d88ed7660757b218ef269b16ffc46f45dcf65bd0cc0f62ebcd
|
data/README.md
CHANGED
@@ -49,16 +49,11 @@ class User < ActiveRecord::Base
|
|
49
49
|
|
50
50
|
include ActiveRegulation::Containment
|
51
51
|
|
52
|
-
# A virtual attribute is generated for
|
53
|
-
# easy use with forms and models
|
54
|
-
|
55
52
|
end
|
56
53
|
```
|
57
54
|
|
58
55
|
## Usage
|
59
56
|
```ruby
|
60
|
-
user = User.create!(activation: 1)
|
61
|
-
|
62
57
|
user.active? #=> true
|
63
58
|
user.inactive? #=> false
|
64
59
|
|
@@ -1,14 +1,8 @@
|
|
1
1
|
module ActiveRegulation
|
2
2
|
module Activation
|
3
3
|
extend ActiveSupport::Concern
|
4
|
-
include ActiveRegulation::Base
|
5
4
|
|
6
5
|
included do
|
7
|
-
attr_accessor :activation, :raw_activation
|
8
|
-
|
9
|
-
before_save :record_activation!
|
10
|
-
after_initialize :set_activation!
|
11
|
-
|
12
6
|
scope :active, -> { where(inactivated_at: nil) }
|
13
7
|
scope :inactive, -> { where.not(inactivated_at: nil) }
|
14
8
|
end
|
@@ -29,29 +23,12 @@ module ActiveRegulation
|
|
29
23
|
!active?
|
30
24
|
end
|
31
25
|
|
32
|
-
def
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
def record_activation!
|
39
|
-
unless raw_activation.nil?
|
40
|
-
false_value = FALSE_VALUES.include?(activation)
|
41
|
-
true_value = TRUE_VALUES.include?(activation)
|
42
|
-
|
43
|
-
if false_value || true_value
|
44
|
-
self.inactivated_at = (false_value ? Time.now : nil)
|
45
|
-
else
|
46
|
-
raise ArgumentError,
|
47
|
-
"Unknown boolean: #{activation.inspect}. Must be a valid boolean."
|
48
|
-
end
|
49
|
-
end
|
26
|
+
def inactivated_at_or_time
|
27
|
+
active? ? Time.now : inactivated_at
|
50
28
|
end
|
51
29
|
|
52
|
-
def
|
53
|
-
|
54
|
-
self.activation = active? if activation.nil?
|
30
|
+
def to_activation
|
31
|
+
I18n.t("active_regulation.activation.#{active? ? :active : :inactive}")
|
55
32
|
end
|
56
33
|
|
57
34
|
end
|
@@ -1,14 +1,8 @@
|
|
1
1
|
module ActiveRegulation
|
2
2
|
module Containment
|
3
3
|
extend ActiveSupport::Concern
|
4
|
-
include ActiveRegulation::Base
|
5
4
|
|
6
5
|
included do
|
7
|
-
attr_accessor :containment, :raw_containment
|
8
|
-
|
9
|
-
before_save :record_containment!
|
10
|
-
after_initialize :set_containment!
|
11
|
-
|
12
6
|
scope :contained, -> { where.not(contained_at: nil) }
|
13
7
|
scope :uncontained, -> { where(contained_at: nil) }
|
14
8
|
end
|
@@ -29,29 +23,12 @@ module ActiveRegulation
|
|
29
23
|
contained_at.nil?
|
30
24
|
end
|
31
25
|
|
32
|
-
def
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
def record_containment!
|
39
|
-
unless raw_containment.nil?
|
40
|
-
false_value = FALSE_VALUES.include?(containment)
|
41
|
-
true_value = TRUE_VALUES.include?(containment)
|
42
|
-
|
43
|
-
if false_value || true_value
|
44
|
-
self.contained_at = (false_value ? nil : Time.now)
|
45
|
-
else
|
46
|
-
raise ArgumentError,
|
47
|
-
"Unknown boolean: #{containment.inspect}. Must be a valid boolean."
|
48
|
-
end
|
49
|
-
end
|
26
|
+
def contained_at_or_time
|
27
|
+
uncontained? ? Time.now : contained_at
|
50
28
|
end
|
51
29
|
|
52
|
-
def
|
53
|
-
|
54
|
-
self.containment = contained? if containment.nil?
|
30
|
+
def to_containment
|
31
|
+
I18n.t("active_regulation.containment.#{uncontained? ? :uncontained : :contained}")
|
55
32
|
end
|
56
33
|
|
57
34
|
end
|
@@ -3,14 +3,8 @@ require 'date'
|
|
3
3
|
module ActiveRegulation
|
4
4
|
module Expiration
|
5
5
|
extend ActiveSupport::Concern
|
6
|
-
include ActiveRegulation::Base
|
7
6
|
|
8
7
|
included do
|
9
|
-
attr_accessor :expiration, :raw_expiration
|
10
|
-
|
11
|
-
before_save :record_expiration!
|
12
|
-
after_initialize :set_expiration!
|
13
|
-
|
14
8
|
scope :expired, -> { where("expires_at IS NULL OR expires_at < ?", Time.now) }
|
15
9
|
scope :unexpired, -> { where("expires_at IS NOT NULL AND expires_at >= ?", Time.now) }
|
16
10
|
end
|
@@ -20,7 +14,7 @@ module ActiveRegulation
|
|
20
14
|
end
|
21
15
|
|
22
16
|
def extend!(amount=nil)
|
23
|
-
update(expires_at: (amount
|
17
|
+
update(expires_at: extension_date(amount))
|
24
18
|
end
|
25
19
|
|
26
20
|
def unexpire!
|
@@ -35,33 +29,20 @@ module ActiveRegulation
|
|
35
29
|
expires_at.nil? ? false : (Time.now < expires_at)
|
36
30
|
end
|
37
31
|
|
32
|
+
def expires_at_or_time(amount=nil)
|
33
|
+
expired? ? extension_date(amount) : expires_at
|
34
|
+
end
|
35
|
+
|
38
36
|
def to_expiration
|
39
37
|
I18n.t("active_regulation.expiration.#{expired? ? :expired : :unexpired}")
|
40
38
|
end
|
41
39
|
|
42
40
|
private
|
43
41
|
|
44
|
-
def extension_date(
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
def record_expiration!
|
49
|
-
unless raw_expiration.nil?
|
50
|
-
false_value = FALSE_VALUES.include?(expiration)
|
51
|
-
true_value = TRUE_VALUES.include?(expiration)
|
52
|
-
|
53
|
-
if false_value || true_value
|
54
|
-
self.expires_at = (false_value ? extension_date : nil)
|
55
|
-
else
|
56
|
-
raise ArgumentError,
|
57
|
-
"Unknown boolean: #{expiration.inspect}. Must be a valid boolean."
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
42
|
+
def extension_date(time=nil)
|
43
|
+
time = 30 if time.nil?
|
61
44
|
|
62
|
-
|
63
|
-
self.raw_expiration = expiration
|
64
|
-
self.expiration = expired? if expiration.nil?
|
45
|
+
time.is_a?(Integer) ? (DateTime.now + time) : time
|
65
46
|
end
|
66
47
|
|
67
48
|
end
|
@@ -1,14 +1,8 @@
|
|
1
1
|
module ActiveRegulation
|
2
2
|
module Visibility
|
3
3
|
extend ActiveSupport::Concern
|
4
|
-
include ActiveRegulation::Base
|
5
4
|
|
6
5
|
included do
|
7
|
-
attr_accessor :visibility, :raw_visibility
|
8
|
-
|
9
|
-
before_save :record_visibility!
|
10
|
-
after_initialize :set_visibility!
|
11
|
-
|
12
6
|
scope :visible, -> { where(invisible_at: nil) }
|
13
7
|
scope :invisible, -> { where.not(invisible_at: nil) }
|
14
8
|
end
|
@@ -29,29 +23,12 @@ module ActiveRegulation
|
|
29
23
|
invisible_at.nil?
|
30
24
|
end
|
31
25
|
|
32
|
-
def
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
def record_visibility!
|
39
|
-
unless raw_visibility.nil?
|
40
|
-
false_value = FALSE_VALUES.include?(visibility)
|
41
|
-
true_value = TRUE_VALUES.include?(visibility)
|
42
|
-
|
43
|
-
if false_value || true_value
|
44
|
-
self.invisible_at = (false_value ? Time.now : nil)
|
45
|
-
else
|
46
|
-
raise ArgumentError,
|
47
|
-
"Unknown boolean: #{visibility.inspect}. Must be a valid boolean."
|
48
|
-
end
|
49
|
-
end
|
26
|
+
def invisible_at_or_time
|
27
|
+
visible? ? Time.now : invisible_at
|
50
28
|
end
|
51
29
|
|
52
|
-
def
|
53
|
-
|
54
|
-
self.visibility = visible? if visibility.nil?
|
30
|
+
def to_visibility
|
31
|
+
I18n.t("active_regulation.visibility.#{visible? ? :visible : :invisible}")
|
55
32
|
end
|
56
33
|
|
57
34
|
end
|
data/lib/active_regulation.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_regulation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Gomez
|
@@ -144,7 +144,6 @@ files:
|
|
144
144
|
- config/locales/en.yml
|
145
145
|
- lib/active_regulation.rb
|
146
146
|
- lib/active_regulation/activation.rb
|
147
|
-
- lib/active_regulation/base.rb
|
148
147
|
- lib/active_regulation/containment.rb
|
149
148
|
- lib/active_regulation/expiration.rb
|
150
149
|
- lib/active_regulation/version.rb
|