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: 7cf0b1b44b4a7dcbf307fa34a85e743942e2eebc2cc6b52e5ccdd8d5ac60d208
4
- data.tar.gz: 3ef45a67a92b232404f54904d1773a2e8d39c6b2289dc298a981d5d08fef4c3e
3
+ metadata.gz: '09314c0aa23ebba5f883831c62f545fe457545724a66a2716d0dd4f907cfac92'
4
+ data.tar.gz: 521b98bf484b4fc2da12a040329d6f9ec24b1c461a485bf99674de0e466f573c
5
5
  SHA512:
6
- metadata.gz: 1a0d3e2b1f1cfd24b673312d51469458dce1c9c2f79e22928246241e5404374dc1fcf2cc026b1f40c15c48bc6f8ef3ff587f52bdea9d2bd43aace9d874440bbb
7
- data.tar.gz: 98d22e582b2f07afc0e6abde125a72bdbb1f28c6f9a0ef1c7865f3600c72e2282e4ccf2ebb2a5aef9fe0ca6c39c6e7a964bd87393ae40ee0939cedbee3df67c9
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
- if value.present? && value <= Date.today
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
- if value.present? && value >= Date.today
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
@@ -82,7 +82,6 @@ module Commonbase
82
82
  log_message(level, "Request body:", request.body&.read)
83
83
  end
84
84
 
85
- private
86
85
  def log_message(level, message, data = nil)
87
86
  return unless level.present?
88
87
 
@@ -1,3 +1,3 @@
1
1
  module Commonbase
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: commonbase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan