commonbase 0.2.0 → 0.2.1
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09314c0aa23ebba5f883831c62f545fe457545724a66a2716d0dd4f907cfac92'
|
4
|
+
data.tar.gz: 521b98bf484b4fc2da12a040329d6f9ec24b1c461a485bf99674de0e466f573c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 183a8500985b7c4b0618ac5b56b0301de02283319e82fa3b487f86ad08acff40f82ca5eca08c0485c485970bc2838872441c16a964f7a3aeefa8d6eb1a7029fa
|
7
|
+
data.tar.gz: 1f97167fc68097c15f3752b6edd3cb78e3372f4cfab48b0f41dd0972dc671dc93feb9a04eacb782e9c9601b0b8d68e9231e4592393bf279c9a5c6f19631eeb44
|
@@ -1,5 +1,5 @@
|
|
1
|
-
module Commonbase
|
2
|
-
class ApplicationRecord < ActiveRecord::Base
|
3
|
-
self.abstract_class = true
|
4
|
-
end
|
5
|
-
end
|
1
|
+
module Commonbase
|
2
|
+
class ApplicationRecord < ActiveRecord::Base
|
3
|
+
self.abstract_class = true
|
4
|
+
end
|
5
|
+
end
|
@@ -3,17 +3,27 @@ module Commonbase
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
class_methods do
|
6
|
+
# Validate if a date is in future. By default today is invalid. Set include_today to true to include today.
|
6
7
|
def validate_future_date(attribute, options = {})
|
7
8
|
validates_each attribute do |record, attr, value|
|
8
|
-
|
9
|
+
next unless value.present?
|
10
|
+
|
11
|
+
include_today = options[:include_today] || false
|
12
|
+
|
13
|
+
if value < Date.today || (value == Date.today && include_today.equal?(false))
|
9
14
|
record.errors.add(attr, options[:message] || "must be in the future")
|
10
15
|
end
|
11
16
|
end
|
12
17
|
end
|
13
18
|
|
19
|
+
# Validate if a date is in the past. By default today is invalid. Set include_today to true to include today.
|
14
20
|
def validate_past_date(attribute, options = {})
|
15
21
|
validates_each attribute do |record, attr, value|
|
16
|
-
|
22
|
+
next unless value.present?
|
23
|
+
|
24
|
+
include_today = options[:include_today] || false
|
25
|
+
|
26
|
+
if value > Date.today || (value == Date.today && include_today.equal?(false))
|
17
27
|
record.errors.add(attr, options[:message] || "must be in the past")
|
18
28
|
end
|
19
29
|
end
|
data/lib/commonbase/version.rb
CHANGED