active_regulation 2.2.1 → 2.2.2
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 +4 -1
- data/lib/active_regulation/activation.rb +14 -0
- data/lib/active_regulation/containment.rb +14 -0
- data/lib/active_regulation/expiration.rb +12 -0
- data/lib/active_regulation/version.rb +1 -1
- data/lib/active_regulation/visibility.rb +14 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12f514676ae36c6222f132a5ec056f016f7ec936
|
4
|
+
data.tar.gz: 6b8394db7172bfd2e56a0ef2b26b940b6784f92c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abae79023d6627ccc2dee86abe7a30d29a57e5428caa98d3cc3bdde1eccd1961fdbd936bb25bf38355b082ecde287b79f27346d283ebe71aa50473c9d0cdbbcb
|
7
|
+
data.tar.gz: 527cdb67dce25592dfdcff43069edc8b0ba551e43b54c1315db9c5bf5432b58323162180d320ff7dc777b59d6bee4cc1ccc2d4b3abb5815da90a446556dbe888
|
data/README.md
CHANGED
@@ -49,12 +49,15 @@ 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
|
+
|
52
55
|
end
|
53
56
|
```
|
54
57
|
|
55
58
|
## Usage
|
56
59
|
```ruby
|
57
|
-
user = User.create!
|
60
|
+
user = User.create!(activation: 1)
|
58
61
|
|
59
62
|
user.active? #=> true
|
60
63
|
user.inactive? #=> false
|
@@ -3,6 +3,14 @@ module ActiveRegulation
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
included do
|
6
|
+
attr_accessor :activation
|
7
|
+
|
8
|
+
validates :activation, inclusion: { in: 0..1 },
|
9
|
+
allow_blank: true,
|
10
|
+
allow_nil: true
|
11
|
+
|
12
|
+
before_save :record_activation!
|
13
|
+
|
6
14
|
scope :active, -> { where(inactivated_at: nil) }
|
7
15
|
scope :inactive, -> { where.not(inactivated_at: nil) }
|
8
16
|
end
|
@@ -27,5 +35,11 @@ module ActiveRegulation
|
|
27
35
|
I18n.t("active_regulation.activation.#{active? ? :active : :inactive}")
|
28
36
|
end
|
29
37
|
|
38
|
+
private
|
39
|
+
|
40
|
+
def record_activation!
|
41
|
+
self.inactivated_at = (activation.zero? ? Time.now : nil) unless activation.blank?
|
42
|
+
end
|
43
|
+
|
30
44
|
end
|
31
45
|
end
|
@@ -3,6 +3,14 @@ module ActiveRegulation
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
included do
|
6
|
+
attr_accessor :containment
|
7
|
+
|
8
|
+
validates :containment, inclusion: { in: 0..1 },
|
9
|
+
allow_blank: true,
|
10
|
+
allow_nil: true
|
11
|
+
|
12
|
+
before_save :record_containment!
|
13
|
+
|
6
14
|
scope :contained, -> { where.not(contained_at: nil) }
|
7
15
|
scope :uncontained, -> { where(contained_at: nil) }
|
8
16
|
end
|
@@ -27,5 +35,11 @@ module ActiveRegulation
|
|
27
35
|
I18n.t("active_regulation.containment.#{uncontained? ? :uncontained : :contained}")
|
28
36
|
end
|
29
37
|
|
38
|
+
private
|
39
|
+
|
40
|
+
def record_containment!
|
41
|
+
self.contained_at = (containment.zero? ? nil : Time.now) unless containment.blank?
|
42
|
+
end
|
43
|
+
|
30
44
|
end
|
31
45
|
end
|
@@ -5,6 +5,14 @@ module ActiveRegulation
|
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
7
|
included do
|
8
|
+
attr_accessor :expiration
|
9
|
+
|
10
|
+
validates :expiration, inclusion: { in: 0..1 },
|
11
|
+
allow_blank: true,
|
12
|
+
allow_nil: true
|
13
|
+
|
14
|
+
before_save :record_expiration!
|
15
|
+
|
8
16
|
scope :expired, -> { where("expires_at IS NULL OR expires_at < ?", Time.now) }
|
9
17
|
scope :unexpired, -> { where("expires_at IS NOT NULL AND expires_at >= ?", Time.now) }
|
10
18
|
end
|
@@ -39,5 +47,9 @@ module ActiveRegulation
|
|
39
47
|
DateTime.now + days
|
40
48
|
end
|
41
49
|
|
50
|
+
def record_expiration!
|
51
|
+
self.expires_at = (expiration.zero? ? extension_date : nil) unless expiration.blank?
|
52
|
+
end
|
53
|
+
|
42
54
|
end
|
43
55
|
end
|
@@ -3,6 +3,14 @@ module ActiveRegulation
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
included do
|
6
|
+
attr_accessor :visibility
|
7
|
+
|
8
|
+
validates :visibility, inclusion: { in: 0..1 },
|
9
|
+
allow_blank: true,
|
10
|
+
allow_nil: true
|
11
|
+
|
12
|
+
before_save :record_visibility!
|
13
|
+
|
6
14
|
scope :visible, -> { where(invisible_at: nil) }
|
7
15
|
scope :invisible, -> { where.not(invisible_at: nil) }
|
8
16
|
end
|
@@ -27,5 +35,11 @@ module ActiveRegulation
|
|
27
35
|
I18n.t("active_regulation.visibility.#{visible? ? :visible : :invisible}")
|
28
36
|
end
|
29
37
|
|
38
|
+
private
|
39
|
+
|
40
|
+
def record_visibility!
|
41
|
+
self.invisible_at = (visibility.zero? ? Time.now : nil) unless visibility.blank?
|
42
|
+
end
|
43
|
+
|
30
44
|
end
|
31
45
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Gomez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|