active_regulation 2.2.1 → 2.2.2

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
  SHA1:
3
- metadata.gz: 9193646ae5638300783c8e74d14d9c9b26be1f5d
4
- data.tar.gz: 08c8f65c9e89aebf3a195a4dd38e943b345e8b77
3
+ metadata.gz: 12f514676ae36c6222f132a5ec056f016f7ec936
4
+ data.tar.gz: 6b8394db7172bfd2e56a0ef2b26b940b6784f92c
5
5
  SHA512:
6
- metadata.gz: 93dc8b891314c208e22dc122232a12cd0a8aa322ff028540e9c9facb230f0bab40b40e2960c60e598efce19978c94afc7215b4aeefe696cf177bf9099e6576f8
7
- data.tar.gz: 96485317de452795768aa794420c8fdb16963254a5998e969ef70d5e0d97d83a7460ab9a6ff63734f1c97ba3170b852b320f7a522d2a919ffa60706069a79a71
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
@@ -1,3 +1,3 @@
1
1
  module ActiveRegulation
2
- VERSION = "2.2.1"
2
+ VERSION = "2.2.2"
3
3
  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.1
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-08-31 00:00:00.000000000 Z
11
+ date: 2015-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord