active_regulation 1.0.1 → 2.0.0
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 +2 -0
- data/config/locales/en.yml +3 -0
- data/lib/active_regulation/expiration.rb +43 -0
- data/lib/active_regulation/version.rb +1 -1
- data/lib/active_regulation.rb +2 -6
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7cef39fde264232e7c9723d60183673070de40d
|
4
|
+
data.tar.gz: 787fbeb99b2635db51e839cac45051c38609eb8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8492e2e8155375852ddc3c40ebba7a4e834e3079f661db5400652ba71facc59fac51cabe1e9f1789a42c92759c641a50001c3da8e9837c12b6b880968718879
|
7
|
+
data.tar.gz: 288b7210b6f155c0e230381222907dee71a7cebc6fdaa98a1fd6b373c59fd77b069397e70dbea62740e05ee674bd55d1f92c1f7f76877e270c7bf5c82bb69d6b
|
data/README.md
CHANGED
data/config/locales/en.yml
CHANGED
@@ -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
|
data/lib/active_regulation.rb
CHANGED
@@ -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
|
-
|
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:
|
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
|