can_has_validations 0.3.1 → 0.4.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.
data/README.md CHANGED
@@ -115,6 +115,7 @@ Always skips over nil values; use `:presence` to validate those.
115
115
  validates :start_at, before: :finish_at
116
116
  validates :finish_at, after: [:start_at, :alt_start_at]
117
117
  validates :start_at, presence: true, before: :finish_at
118
+ validates :finish_at, after: ->(r){ Time.current }
118
119
 
119
120
  # Long versions, if you need to add extra validation options:
120
121
  validates :start_at, before: {value_of: :finish_at, message: "..." }
@@ -9,9 +9,10 @@
9
9
  module ActiveModel::Validations
10
10
  class BeforeValidator < ActiveModel::EachValidator
11
11
  def validate_each(record, attribute, value)
12
- compare_to = Array(options[:value_of] || options[:values_of] || options[:in] || options[:with])
12
+ compare_to = Array.wrap(options[:value_of] || options[:values_of] || options[:in] || options[:with])
13
13
  compare_to.each do |attr_name|
14
- greater = record.send attr_name
14
+ greater = attr_name.call(record) if attr_name.respond_to?(:call)
15
+ greater ||= record.send attr_name
15
16
  next unless value && greater
16
17
  unless value < greater
17
18
  attr2 = record.class.human_attribute_name attr_name
@@ -22,9 +23,10 @@ module ActiveModel::Validations
22
23
  end
23
24
  class AfterValidator < ActiveModel::EachValidator
24
25
  def validate_each(record, attribute, value)
25
- compare_to = Array(options[:value_of] || options[:values_of] || options[:in] || options[:with])
26
+ compare_to = Array.wrap(options[:value_of] || options[:values_of] || options[:in] || options[:with])
26
27
  compare_to.each do |attr_name|
27
- lesser = record.send attr_name
28
+ lesser = attr_name.call(record) if attr_name.respond_to?(:call)
29
+ lesser ||= record.send attr_name
28
30
  next unless value && lesser
29
31
  unless value > lesser
30
32
  attr2 = record.class.human_attribute_name attr_name
@@ -1,3 +1,3 @@
1
1
  module CanHasValidations
2
- VERSION = "0.3.1"
2
+ VERSION = '0.4.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: can_has_validations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-10 00:00:00.000000000 Z
12
+ date: 2014-01-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -114,7 +114,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
114
114
  version: '0'
115
115
  segments:
116
116
  - 0
117
- hash: 2495871614076405699
117
+ hash: 1561707028780801012
118
118
  required_rubygems_version: !ruby/object:Gem::Requirement
119
119
  none: false
120
120
  requirements:
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  version: '0'
124
124
  segments:
125
125
  - 0
126
- hash: 2495871614076405699
126
+ hash: 1561707028780801012
127
127
  requirements: []
128
128
  rubyforge_project:
129
129
  rubygems_version: 1.8.25