pencil_pusher 0.0.3 → 0.0.4
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: 07c4fe56c3dc8d165527f6a247bb2ec518508f79
|
4
|
+
data.tar.gz: 3b9b5d4f2286f3fb6a0b3924a0c9a762a920da8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e353c05beb2c569ac6e0a1b18907eaa470f4126ab95b7654731b60ecc45d91451a65c6050e64406ccfc42eec48a7dc73f4cb946113efd4d28c0b6b26cc12a9ff
|
7
|
+
data.tar.gz: d3b979cabb34f948811b8f5885e998af582641cfca70c1d5b894f1a84e9453a3b6c3f6b14441161127a88f39d710f60521820fe1665d51d60b14ff55b615f08a
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'pencil_pusher/validations/date_time_validator'
|
2
|
+
require 'pencil_pusher/virtus/coercer/date_time'
|
3
|
+
|
4
|
+
module PencilPusher
|
5
|
+
module DateTimeFields
|
6
|
+
def required_date_time_field(options={})
|
7
|
+
field_name = options.fetch(:field_name)
|
8
|
+
format = options.fetch(:format)
|
9
|
+
|
10
|
+
attribute field_name, PencilPusher::Virtus::Coercer::DateTime, format: format
|
11
|
+
|
12
|
+
validates field_name,
|
13
|
+
'pencil_pusher/validations/date_time' => {
|
14
|
+
format: format,
|
15
|
+
messages: {
|
16
|
+
blank: options.fetch(:blank_message),
|
17
|
+
invalid: options.fetch(:invalid_message)
|
18
|
+
}
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -5,8 +5,8 @@ module PencilPusher
|
|
5
5
|
@model = model
|
6
6
|
@attribute = attribute
|
7
7
|
|
8
|
-
if value
|
9
|
-
|
8
|
+
if blank?(value)
|
9
|
+
append_blank_message
|
10
10
|
else
|
11
11
|
coerce_date(value)
|
12
12
|
end
|
@@ -16,14 +16,26 @@ module PencilPusher
|
|
16
16
|
|
17
17
|
attr_reader :model, :attribute
|
18
18
|
|
19
|
+
def messages
|
20
|
+
@messages ||= options.fetch(:messages)
|
21
|
+
end
|
22
|
+
|
19
23
|
def coerce_date(value)
|
20
24
|
Date.strptime(value, options.fetch(:format))
|
21
25
|
rescue ArgumentError
|
22
|
-
|
26
|
+
append_invalid_message
|
27
|
+
end
|
28
|
+
|
29
|
+
def blank?(value)
|
30
|
+
value.nil? || value.strip == ''
|
31
|
+
end
|
32
|
+
|
33
|
+
def append_blank_message
|
34
|
+
model.errors[attribute] << messages.fetch(:blank)
|
23
35
|
end
|
24
36
|
|
25
|
-
def
|
26
|
-
model.errors[attribute] <<
|
37
|
+
def append_invalid_message
|
38
|
+
model.errors[attribute] << messages.fetch(:invalid)
|
27
39
|
end
|
28
40
|
end
|
29
41
|
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.4
|
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: 2013-10-
|
12
|
+
date: 2013-10-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- lib/pencil_pusher/validations/date_time_validator.rb
|
103
103
|
- lib/pencil_pusher/shared_fields.rb
|
104
104
|
- lib/pencil_pusher/have_required_float_field.rb
|
105
|
+
- lib/pencil_pusher/date_time_fields.rb
|
105
106
|
- lib/pencil_pusher/form.rb
|
106
107
|
- lib/pencil_pusher/have_required_int_field.rb
|
107
108
|
homepage:
|