mongoid_time_field 0.2.9 → 0.3.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.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/README.rdoc +0 -0
- data/lib/mongoid_time_field.rb +6 -0
- data/lib/mongoid_time_field/validator.rb +14 -0
- data/lib/mongoid_time_field/value.rb +14 -0
- data/lib/mongoid_time_field/version.rb +1 -1
- data/spec/spec_helper.rb +0 -0
- data/spec/support/dummy_hhmm.rb +6 -0
- data/spec/support/dummy_time.rb +0 -0
- data/spec/v1_spec.rb +0 -0
- data/spec/v2_spec.rb +27 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b650d7bcdd423e0ebffe2899b18dbd171d4cc80
|
4
|
+
data.tar.gz: 97248e826c2dff4f57d3f8da3ecf053d3e425ead
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce9ca402375d3a586947fe46ffcb94761270efe95bf622f1cb539f446c727f20c07a92fd345f3c86546b55133bd2f56a7da7533019654b28a9626c543dd747c3
|
7
|
+
data.tar.gz: 1ce4f7fd8a957637379c9160ccdd0c03e32c0ffc9af7eddd6095ce805ab69f40033f2347b5c522b2d45b1750bf8db3274480cbff4ead98689c0c66a732a5ee96
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.0-
|
1
|
+
2.0.0-p353
|
data/README.rdoc
CHANGED
File without changes
|
data/lib/mongoid_time_field.rb
CHANGED
@@ -9,6 +9,12 @@ module Mongoid
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
+
if Object.const_defined?("TimeValidator")
|
13
|
+
puts "[WARN] Mongoid Time Field: TimeValidator is already defined, not loading ours"
|
14
|
+
else
|
15
|
+
require "mongoid_time_field/validator"
|
16
|
+
end
|
17
|
+
|
12
18
|
if Object.const_defined?("RailsAdmin")
|
13
19
|
require 'rails_admin/adapters/mongoid'
|
14
20
|
require 'rails_admin/config/fields/types/text'
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class TimeValidator < ActiveModel::EachValidator
|
2
|
+
def validate_each(record, attribute, value)
|
3
|
+
unless options[:less_than].blank?
|
4
|
+
unless value < Mongoid::TimeField::Value.new(options[:less_than], value.format)
|
5
|
+
record.errors.add attribute, (options[:message] || "должно быть меньше #{options[:less_than]}")
|
6
|
+
end
|
7
|
+
end
|
8
|
+
unless options[:greater_than].blank?
|
9
|
+
unless value > Mongoid::TimeField::Value.new(options[:greater_than], value.format)
|
10
|
+
record.errors.add attribute, (options[:message] || "должно быть больше #{options[:greater_than]}")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -18,6 +18,10 @@ module Mongoid::TimeField
|
|
18
18
|
seconds.__bson_dump__(io, key)
|
19
19
|
end
|
20
20
|
|
21
|
+
def format
|
22
|
+
@options[:format].dup
|
23
|
+
end
|
24
|
+
|
21
25
|
def to_s
|
22
26
|
if @seconds.nil?
|
23
27
|
nil
|
@@ -73,6 +77,16 @@ module Mongoid::TimeField
|
|
73
77
|
'"' + to_s + '"'
|
74
78
|
end
|
75
79
|
|
80
|
+
def >(x)
|
81
|
+
raise ArgumentError, 'Argument is not Mongoid::TimeField::Value' unless x.is_a? Mongoid::TimeField::Value
|
82
|
+
@seconds > x.seconds
|
83
|
+
end
|
84
|
+
|
85
|
+
def <(x)
|
86
|
+
raise ArgumentError, 'Argument is not Mongoid::TimeField::Value' unless x.is_a? Mongoid::TimeField::Value
|
87
|
+
@seconds < x.seconds
|
88
|
+
end
|
89
|
+
|
76
90
|
def coerce(something)
|
77
91
|
[self, something]
|
78
92
|
end
|
data/spec/spec_helper.rb
CHANGED
File without changes
|
data/spec/support/dummy_time.rb
CHANGED
File without changes
|
data/spec/v1_spec.rb
CHANGED
File without changes
|
data/spec/v2_spec.rb
CHANGED
@@ -260,4 +260,31 @@ describe Mongoid::TimeField do
|
|
260
260
|
dummy.save.should eq true
|
261
261
|
end
|
262
262
|
end
|
263
|
+
|
264
|
+
describe 'HH:MM' do
|
265
|
+
it 'stores properly' do
|
266
|
+
h = DummyHhmm.create!(t: '12:30')
|
267
|
+
h.t.should eq '12:30'
|
268
|
+
h.t.to_i.should eq ( (12 * 60) + 30) * 60
|
269
|
+
h.reload
|
270
|
+
h.t.should eq '12:30'
|
271
|
+
h.t.to_i.should eq ( (12 * 60) + 30) * 60
|
272
|
+
end
|
273
|
+
|
274
|
+
it 'validates' do
|
275
|
+
h = DummyHhmm.new(t: '24:30')
|
276
|
+
h.valid?.should be_false
|
277
|
+
h = DummyHhmm.new(t: '23:30')
|
278
|
+
h.valid?.should be_true
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
describe 'Value' do
|
283
|
+
it 'does compare' do
|
284
|
+
opt = {format: 'mm:SS'}
|
285
|
+
Mongoid::TimeField::Value.new(120, opt).to_s.should eq '2:00'
|
286
|
+
(Mongoid::TimeField::Value.new(120, opt) > Mongoid::TimeField::Value.new(119, opt)).should be_true
|
287
|
+
end
|
288
|
+
|
289
|
+
end
|
263
290
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_time_field
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- glebtv
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|
@@ -113,11 +113,13 @@ files:
|
|
113
113
|
- lib/mongoid_time_field.rb
|
114
114
|
- lib/mongoid_time_field/class_methods.rb
|
115
115
|
- lib/mongoid_time_field/time_field.rb
|
116
|
+
- lib/mongoid_time_field/validator.rb
|
116
117
|
- lib/mongoid_time_field/value.rb
|
117
118
|
- lib/mongoid_time_field/version.rb
|
118
119
|
- mongoid_time_field.gemspec
|
119
120
|
- spec/spec_helper.rb
|
120
121
|
- spec/support/dummy_duration.rb
|
122
|
+
- spec/support/dummy_hhmm.rb
|
121
123
|
- spec/support/dummy_time.rb
|
122
124
|
- spec/support/dummy_v2.rb
|
123
125
|
- spec/support/dummy_validate.rb
|
@@ -144,13 +146,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
146
|
version: '0'
|
145
147
|
requirements: []
|
146
148
|
rubyforge_project:
|
147
|
-
rubygems_version: 2.
|
149
|
+
rubygems_version: 2.1.11
|
148
150
|
signing_key:
|
149
151
|
specification_version: 4
|
150
152
|
summary: Time field for Mongoid
|
151
153
|
test_files:
|
152
154
|
- spec/spec_helper.rb
|
153
155
|
- spec/support/dummy_duration.rb
|
156
|
+
- spec/support/dummy_hhmm.rb
|
154
157
|
- spec/support/dummy_time.rb
|
155
158
|
- spec/support/dummy_v2.rb
|
156
159
|
- spec/support/dummy_validate.rb
|