active_regulation 2.2.5 → 2.2.6

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: f3ca84f273ae42c7a002d385e2d49735ef7466a9
4
- data.tar.gz: 41728d8e805a20925354cf5e23b32d5b9b99070a
3
+ metadata.gz: 33792242a23654c0acd0e9eaafc2097f4480955c
4
+ data.tar.gz: 2fdaa474fef2d46740bb7ed129775f3e8bf664d4
5
5
  SHA512:
6
- metadata.gz: abda366e0fc97cf382d195eced91de5aa8dc0bf0ddd9e81eb79311b62f0865300da6a984a2cc3d464634fa08f549c540675051c449365ae4e7190f6bf1b96cc8
7
- data.tar.gz: d43dcf2b5d9b229bec79ea3eeda3ea743dd4660b76785a9c09be054f962c9d16ea5aacdd572b98b21b1b2a40e64c20311944615b1b280fa41485675e69fd7eb0
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 to_activation
33
- I18n.t("active_regulation.activation.#{active? ? :active : :inactive}")
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 set_activation!
53
- self.raw_activation = activation
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 to_containment
33
- I18n.t("active_regulation.containment.#{uncontained? ? :uncontained : :contained}")
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 set_containment!
53
- self.raw_containment = containment
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.nil? ? extension_date : 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(days=30)
45
- DateTime.now + days
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
- def set_expiration!
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,3 +1,3 @@
1
1
  module ActiveRegulation
2
- VERSION = "2.2.5"
2
+ VERSION = "2.2.6"
3
3
  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 to_visibility
33
- I18n.t("active_regulation.visibility.#{visible? ? :visible : :invisible}")
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 set_visibility!
53
- self.raw_visibility = visibility
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
@@ -1,5 +1,4 @@
1
1
  require "active_regulation/version"
2
- require "active_regulation/base"
3
2
  require "active_regulation/activation"
4
3
  require "active_regulation/containment"
5
4
  require "active_regulation/expiration"
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.5
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
@@ -1,8 +0,0 @@
1
- module ActiveRegulation
2
- module Base
3
-
4
- FALSE_VALUES = [false, 0, '0', 'f', 'F', 'false', 'FALSE']
5
- TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE']
6
-
7
- end
8
- end