active_regulation 1.0.1 → 2.0.0

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: 7ef7ba31e8505dfe2f38a1558575937b1270be8c
4
- data.tar.gz: cc42e6569e855c5401613de9f91dd353a7530442
3
+ metadata.gz: f7cef39fde264232e7c9723d60183673070de40d
4
+ data.tar.gz: 787fbeb99b2635db51e839cac45051c38609eb8a
5
5
  SHA512:
6
- metadata.gz: f3807e8e3e4196186919a81ed6ab1deb67e375f4a651dd316af12815c53fcdda224cc68929974f04bed3b199547e32e3f1c81c2eeef8e22927a8ace5ad2b64f8
7
- data.tar.gz: 024dce23a2b0c64209a5fc522ed48e350f6e819e1a846b67e1f3ce80b3dcf4216fdb1c52bc9b1bd40d91ea9f2c7d093ff59c69cb1c82d3bb433ea29548fdf98f
6
+ metadata.gz: c8492e2e8155375852ddc3c40ebba7a4e834e3079f661db5400652ba71facc59fac51cabe1e9f1789a42c92759c641a50001c3da8e9837c12b6b880968718879
7
+ data.tar.gz: 288b7210b6f155c0e230381222907dee71a7cebc6fdaa98a1fd6b373c59fd77b069397e70dbea62740e05ee674bd55d1f92c1f7f76877e270c7bf5c82bb69d6b
data/README.md CHANGED
@@ -32,11 +32,13 @@ Or install it yourself as:
32
32
  **Modules:**
33
33
  * activation
34
34
  * containment
35
+ * expiration
35
36
  * visibility
36
37
 
37
38
  **Attributes:**
38
39
  * :inactivated_at
39
40
  * :contained_at
41
+ * :expires_at
40
42
  * :invisible_at
41
43
 
42
44
  ```ruby
@@ -6,6 +6,9 @@ en:
6
6
  containment:
7
7
  contained: "Contained"
8
8
  uncontained: "Uncontained"
9
+ expiration:
10
+ expired: "Expired"
11
+ unexpired: "Unexpired"
9
12
  visibility:
10
13
  invisible: "Invisible"
11
14
  visible: "Visible"
@@ -0,0 +1,43 @@
1
+ require 'date'
2
+
3
+ module ActiveRegulation
4
+ module Expiration
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ scope :expired, -> { where("expires_at IS NULL OR expires_at < ?", Time.now) }
9
+ scope :unexpired, -> { where("expires_at IS NOT NULL AND expires_at >= ?", Time.now) }
10
+ end
11
+
12
+ def expire!
13
+ update(expires_at: nil) unless expires_at.nil?
14
+ end
15
+
16
+ def extend!(amount=nil)
17
+ update(expires_at: (amount.nil? ? extension_date : amount))
18
+ end
19
+
20
+ def unexpire!
21
+ update(expires_at: extension_date) if expires_at.nil?
22
+ end
23
+
24
+ def expired?
25
+ expires_at.nil? ? true : (Time.now >= expires_at)
26
+ end
27
+
28
+ def unexpired?
29
+ expires_at.nil? ? false : (Time.now < expires_at)
30
+ end
31
+
32
+ def to_expiration
33
+ I18n.t("active_regulation.expiration.#{expired? ? :expired : :unexpired}")
34
+ end
35
+
36
+ private
37
+
38
+ def extension_date(days=30)
39
+ DateTime.now + days
40
+ end
41
+
42
+ end
43
+ end
@@ -1,3 +1,3 @@
1
1
  module ActiveRegulation
2
- VERSION = "1.0.1"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -1,6 +1,7 @@
1
1
  require "active_regulation/version"
2
2
  require "active_regulation/activation"
3
3
  require "active_regulation/containment"
4
+ require "active_regulation/expiration"
4
5
  require "active_regulation/visibility"
5
6
 
6
7
  if defined?(Rails)
@@ -11,7 +12,7 @@ if defined?(Rails)
11
12
 
12
13
  initializer 'active_regulation' do |app|
13
14
  ActiveRegulation::Railtie.instance_eval do
14
- locales_from(app.config.i18n.available_locales).each do |locale|
15
+ [app.config.i18n.available_locales].each do |locale|
15
16
  (I18n.load_path << path(locale)) if File.file?(path(locale))
16
17
  end
17
18
  end
@@ -23,11 +24,6 @@ if defined?(Rails)
23
24
  File.expand_path("../../config/locales/#{locale}.yml", __FILE__)
24
25
  end
25
26
 
26
- def self.locales_from(args)
27
- array = Array(args || [])
28
- array.blank? ? [] : array
29
- end
30
-
31
27
  end
32
28
  end
33
29
  end
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: 1.0.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
@@ -145,6 +145,7 @@ files:
145
145
  - lib/active_regulation.rb
146
146
  - lib/active_regulation/activation.rb
147
147
  - lib/active_regulation/containment.rb
148
+ - lib/active_regulation/expiration.rb
148
149
  - lib/active_regulation/version.rb
149
150
  - lib/active_regulation/visibility.rb
150
151
  homepage: https://github.com/drexed/active_regulation