pencil_pusher 0.0.9 → 0.0.10
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1170aa5c409739d57c8602666eaceaf607e92f0d
|
4
|
+
data.tar.gz: c23c1d241b4debfbc1ee6972286969415e9c7857
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 09cd33cfe465e5eb5937f943a88286bdb2c5faa963701edaf88c29013eeab9f7e7b43b36e09138f7882965995624206676198801cb71d6df0868345f80e3e901
|
7
|
+
data.tar.gz: f9e374990db0487ebf63175adf108b4000ac0776eb97cdb24c60d30afa3c808b75ac884332f33481c111e1f273a491cba35de60c395d622039b585ec41e27354
|
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'pencil_pusher/validations/date_time_validator'
|
2
|
+
require 'pencil_pusher/validations/optional_date_time_validator'
|
3
|
+
require 'pencil_pusher/validations/optional_time_validator'
|
2
4
|
require 'pencil_pusher/validations/time_validator'
|
3
5
|
require 'pencil_pusher/virtus/coercer/date_time'
|
4
6
|
require 'pencil_pusher/virtus/coercer/time'
|
@@ -21,6 +23,19 @@ module PencilPusher
|
|
21
23
|
}
|
22
24
|
end
|
23
25
|
|
26
|
+
def optional_date_time_field(options={})
|
27
|
+
field_name = options.fetch(:field_name)
|
28
|
+
format = options.fetch(:format)
|
29
|
+
|
30
|
+
attribute field_name, PencilPusher::Virtus::Coercer::DateTime, format: format
|
31
|
+
|
32
|
+
validates field_name,
|
33
|
+
'pencil_pusher/validations/optional_date_time' => {
|
34
|
+
format: format,
|
35
|
+
messages: {invalid: options.fetch(:invalid_message)}
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
24
39
|
def required_time_field(options={})
|
25
40
|
field_name = options.fetch(:field_name)
|
26
41
|
format = options.fetch(:format)
|
@@ -36,5 +51,18 @@ module PencilPusher
|
|
36
51
|
}
|
37
52
|
}
|
38
53
|
end
|
54
|
+
|
55
|
+
def optional_time_field(options={})
|
56
|
+
field_name = options.fetch(:field_name)
|
57
|
+
format = options.fetch(:format)
|
58
|
+
|
59
|
+
attribute field_name, PencilPusher::Virtus::Coercer::Time, format: format
|
60
|
+
|
61
|
+
validates field_name,
|
62
|
+
'pencil_pusher/validations/optional_time' => {
|
63
|
+
format: format,
|
64
|
+
messages: {invalid: options.fetch(:invalid_message)}
|
65
|
+
}
|
66
|
+
end
|
39
67
|
end
|
40
68
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module PencilPusher
|
2
|
+
module Validations
|
3
|
+
class OptionalTimeValidator < ActiveModel::EachValidator
|
4
|
+
def validate_each(model, attribute, value)
|
5
|
+
@model = model
|
6
|
+
@attribute = attribute
|
7
|
+
|
8
|
+
return if blank?(value)
|
9
|
+
coerce_time(value)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
attr_reader :model, :attribute
|
15
|
+
|
16
|
+
def messages
|
17
|
+
@messages ||= options.fetch(:messages)
|
18
|
+
end
|
19
|
+
|
20
|
+
def coerce_time(value)
|
21
|
+
Time.strptime(value, options.fetch(:format))
|
22
|
+
rescue ArgumentError
|
23
|
+
append_invalid_message
|
24
|
+
end
|
25
|
+
|
26
|
+
def blank?(value)
|
27
|
+
value.nil? || value.strip == ''
|
28
|
+
end
|
29
|
+
|
30
|
+
def append_invalid_message
|
31
|
+
model.errors[attribute] << messages.fetch(:invalid)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pencil_pusher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Myles Megyesi
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-07
|
12
|
+
date: 2014-08-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- lib/pencil_pusher/spec_helpers.rb
|
106
106
|
- lib/pencil_pusher/validations/date_time_validator.rb
|
107
107
|
- lib/pencil_pusher/validations/optional_date_time_validator.rb
|
108
|
+
- lib/pencil_pusher/validations/optional_time_validator.rb
|
108
109
|
- lib/pencil_pusher/validations/time_validator.rb
|
109
110
|
- lib/pencil_pusher/virtus/coercer/date_time.rb
|
110
111
|
- lib/pencil_pusher/virtus/coercer/time.rb
|