mongoid_time_field 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.rdoc +8 -8
- data/lib/mongoid_time_field/time_field.rb +10 -6
- data/lib/mongoid_time_field/version.rb +1 -1
- data/spec/support/dummy_validate.rb +7 -0
- data/spec/v2_spec.rb +21 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16e4a3ef8e112fe1e01003ef243967c0a31146cd
|
4
|
+
data.tar.gz: 1e3348992eb14c4ad2b3450b30eee9b354bcd918
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4f9f7bab1adef22a450867915a1f3745c590dc77487ade1ac0cdee9dc27e21822fe6d0573c97c48794b4ef3ff3f2a13730b8da56871f577ab3406c8575b2d02
|
7
|
+
data.tar.gz: 90abaa8ef9a927e4c72a682133f6d2248cf5d8f253e88d0ef1718d3d28e4caf0556306758e3b564fe7dc4a7e5fb777a1f0fa17c99c167f4d2a7426abbd2fd2e3
|
data/Gemfile.lock
CHANGED
data/README.rdoc
CHANGED
@@ -10,13 +10,13 @@ Include the gem in your Gemfile
|
|
10
10
|
|
11
11
|
== Usage
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
class DummyTime
|
14
|
+
include Mongoid::Document
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
field :worktime, type: TimeField.new(format: 'HH:MM')
|
17
|
+
field :time_of_day, type: TimeField.new(format: 'HH:MM:SS')
|
18
|
+
field :duration, type: TimeField.new(format: 'mm:SS')
|
19
|
+
end
|
20
20
|
|
21
21
|
== Format tokens:
|
22
22
|
|
@@ -31,11 +31,11 @@ Include the gem in your Gemfile
|
|
31
31
|
|
32
32
|
Leftmost value in format is of arbitrary length (i.e. format 'HH:MM' is not limited to 24 hours, 'mm:SS' is not limited to 60 minutes and should not overflow)
|
33
33
|
|
34
|
+
All time values are converted and stored in mongodb as seconds (integer field).
|
35
|
+
|
34
36
|
== changes since v.0.1.0
|
35
37
|
Default format for deprecated time_field syntax is 'mm:SS' for compatibility (If you stored HH:MM with 0.1.0 it should still just keep working with 'mm:SS' format, with seconds stored in DB, but if you change to new syntax and use 'HH:MM' format, you need to multiply all stored values by 60)
|
36
38
|
|
37
|
-
All time values are converted and stored in mongodb as seconds.
|
38
|
-
|
39
39
|
== Contributing to mongoid_time_field
|
40
40
|
|
41
41
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
@@ -26,14 +26,18 @@ class TimeField
|
|
26
26
|
nil
|
27
27
|
else
|
28
28
|
match = @options[:regexp].match(value)
|
29
|
-
|
30
|
-
|
29
|
+
if match.nil?
|
30
|
+
nil
|
31
|
+
else
|
32
|
+
seconds = 0
|
33
|
+
names = match.names
|
31
34
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
+
seconds += match['s'].to_i if names.include?('s')
|
36
|
+
seconds += match['m'].to_i * 60 if names.include?('m')
|
37
|
+
seconds += match['h'].to_i * 3600 if names.include?('h')
|
35
38
|
|
36
|
-
|
39
|
+
Mongoid::TimeField::Value.new(seconds, @options)
|
40
|
+
end
|
37
41
|
end
|
38
42
|
end
|
39
43
|
|
data/spec/v2_spec.rb
CHANGED
@@ -186,4 +186,25 @@ describe Mongoid::TimeField do
|
|
186
186
|
dummy.def.should eq '2:03'
|
187
187
|
end
|
188
188
|
end
|
189
|
+
|
190
|
+
describe 'validation' do
|
191
|
+
it 'validates presence' do
|
192
|
+
dummy = DummyValidate.new
|
193
|
+
dummy.should_not be_valid
|
194
|
+
dummy.errors.count.should eq 1
|
195
|
+
dummy.errors.messages[:def][0].should eq "can't be blank"
|
196
|
+
dummy.save.should eq false
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'validates numericality' do
|
200
|
+
dummy = DummyValidate.new
|
201
|
+
dummy.should_not be_valid
|
202
|
+
dummy.errors.count.should eq 1
|
203
|
+
dummy.errors.messages[:def][0].should eq "can't be blank"
|
204
|
+
dummy.def = '10:00'
|
205
|
+
dummy.should be_valid
|
206
|
+
dummy.errors.count.should eq 0
|
207
|
+
dummy.save.should eq true
|
208
|
+
end
|
209
|
+
end
|
189
210
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_time_field
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- glebtv
|
@@ -120,6 +120,7 @@ files:
|
|
120
120
|
- spec/support/dummy_duration.rb
|
121
121
|
- spec/support/dummy_time.rb
|
122
122
|
- spec/support/dummy_v2.rb
|
123
|
+
- spec/support/dummy_validate.rb
|
123
124
|
- spec/support/mongoid.yml
|
124
125
|
- spec/v1_spec.rb
|
125
126
|
- spec/v2_spec.rb
|
@@ -152,6 +153,7 @@ test_files:
|
|
152
153
|
- spec/support/dummy_duration.rb
|
153
154
|
- spec/support/dummy_time.rb
|
154
155
|
- spec/support/dummy_v2.rb
|
156
|
+
- spec/support/dummy_validate.rb
|
155
157
|
- spec/support/mongoid.yml
|
156
158
|
- spec/v1_spec.rb
|
157
159
|
- spec/v2_spec.rb
|