mutations 0.7.2 → 0.8.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 +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +1 -0
- data/.travis.yml +4 -0
- data/CHANGELOG.md +8 -0
- data/Gemfile +0 -6
- data/Rakefile +5 -4
- data/lib/mutations.rb +3 -0
- data/lib/mutations/array_filter.rb +2 -2
- data/lib/mutations/date_filter.rb +2 -2
- data/lib/mutations/integer_filter.rb +6 -1
- data/lib/mutations/string_filter.rb +7 -3
- data/lib/mutations/time_filter.rb +54 -0
- data/lib/mutations/version.rb +1 -1
- data/mutations.gemspec +1 -1
- data/spec/additional_filter_spec.rb +17 -0
- data/spec/date_filter_spec.rb +3 -4
- data/spec/integer_filter_spec.rb +13 -0
- data/spec/string_filter_spec.rb +58 -0
- data/spec/time_filter_spec.rb +130 -0
- metadata +43 -27
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 67b3c3f2b9a7980e259b2d220f0677988b83694b
|
4
|
+
data.tar.gz: eb4d1d4f79f74dfe470878984773729807ae167a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 80a6dabcd0a2e745faba5dbb053a1aec47844c88ade1500850b2006216782f115c7c1272aa9ee39f18e358ee1d49b005679820b32f03b34fb69cf0954a67763a
|
7
|
+
data.tar.gz: 559db59b1b5cd6281e32e9f39fd03b5d281b18d56b44afcc3c2ad8636e5fcdfe2064a47a3db73fb5008a54395fa4c54a0a5856c1db1ff5deb310c270019a5e8a
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data.tar.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
��j�>��g��Ibӟ3��exֶ���ێ0��:�.��jdsH瞰�'��ojv�����П���?�Q���UQ�Iז!�����ìV�;�G���ӵ�O�q���[��τ��8,�Fp��3�8���N Q&N5y�$�D)�?�\��9t������o ���3��~D�-oV�+K�Ke�'XFf[[&m7<T(r�q��ևҎWL�Ǘ����z�@#
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
0.8.0
|
2
|
+
-----------
|
3
|
+
- Add Time filter: ```time :start_time```
|
4
|
+
- Remove unprintable characters from `string` by default.
|
5
|
+
- Add bigdecimal and float as non-strict string input options
|
6
|
+
- Additonal filters that are used in arrays can now have block arguments
|
7
|
+
- Add `empty_is_nil` option to integer filter.
|
8
|
+
|
1
9
|
0.7.2
|
2
10
|
-----------
|
3
11
|
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
require
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
2
3
|
Rake::TestTask.new(:test) do |test|
|
3
|
-
test.libs <<
|
4
|
+
test.libs << "spec"
|
4
5
|
# test.warning = true # Wow that outputs a lot of shit
|
5
|
-
test.pattern =
|
6
|
+
test.pattern = "spec/**/*_spec.rb"
|
6
7
|
end
|
7
8
|
|
8
|
-
task :default => :test
|
9
|
+
task :default => :test
|
data/lib/mutations.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'active_support/core_ext/hash/indifferent_access'
|
2
2
|
require 'active_support/core_ext/string/inflections'
|
3
3
|
require 'date'
|
4
|
+
require 'time'
|
5
|
+
require 'bigdecimal'
|
4
6
|
|
5
7
|
require 'mutations/version'
|
6
8
|
require 'mutations/exception'
|
@@ -13,6 +15,7 @@ require 'mutations/float_filter'
|
|
13
15
|
require 'mutations/boolean_filter'
|
14
16
|
require 'mutations/duck_filter'
|
15
17
|
require 'mutations/date_filter'
|
18
|
+
require 'mutations/time_filter'
|
16
19
|
require 'mutations/file_filter'
|
17
20
|
require 'mutations/model_filter'
|
18
21
|
require 'mutations/array_filter'
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module Mutations
|
2
2
|
class ArrayFilter < InputFilter
|
3
3
|
def self.register_additional_filter(type_class, type_name)
|
4
|
-
define_method(type_name) do | *args |
|
4
|
+
define_method(type_name) do | *args, &block |
|
5
5
|
options = args[0] || {}
|
6
|
-
@element_filter = type_class.new(options)
|
6
|
+
@element_filter = type_class.new(options, &block)
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
@@ -2,7 +2,7 @@ module Mutations
|
|
2
2
|
class DateFilter < AdditionalFilter
|
3
3
|
@default_options = {
|
4
4
|
:nils => false, # true allows an explicit nil to be valid. Overrides any other options
|
5
|
-
:format => nil, # If nil, Date.parse will be used for
|
5
|
+
:format => nil, # If nil, Date.parse will be used for coercion. If something like "%Y-%m-%d", Date.strptime is used
|
6
6
|
:after => nil, # A date object, representing the minimum date allowed, inclusive
|
7
7
|
:before => nil # A date object, representing the maximum date allowed, inclusive
|
8
8
|
}
|
@@ -15,7 +15,7 @@ module Mutations
|
|
15
15
|
end
|
16
16
|
|
17
17
|
# Now check if it's empty:
|
18
|
-
return [data, :empty] if
|
18
|
+
return [data, :empty] if "" == data
|
19
19
|
|
20
20
|
if data.is_a?(Date) # Date and DateTime
|
21
21
|
actual_date = data
|
@@ -2,6 +2,7 @@ module Mutations
|
|
2
2
|
class IntegerFilter < AdditionalFilter
|
3
3
|
@default_options = {
|
4
4
|
:nils => false, # true allows an explicit nil to be valid. Overrides any other options
|
5
|
+
:empty_is_nil => false, # if true, treat empty string as if it were nil
|
5
6
|
:min => nil, # lowest value, inclusive
|
6
7
|
:max => nil, # highest value, inclusive
|
7
8
|
:in => nil, # Can be an array like %w(3 4 5)
|
@@ -9,12 +10,16 @@ module Mutations
|
|
9
10
|
|
10
11
|
def filter(data)
|
11
12
|
|
13
|
+
if options[:empty_is_nil] && data == ""
|
14
|
+
data = nil
|
15
|
+
end
|
16
|
+
|
12
17
|
# Handle nil case
|
13
18
|
if data.nil?
|
14
19
|
return [nil, nil] if options[:nils]
|
15
20
|
return [nil, :nils]
|
16
21
|
end
|
17
|
-
|
22
|
+
|
18
23
|
# Now check if it's empty:
|
19
24
|
return [data, :empty] if data == ""
|
20
25
|
|
@@ -9,7 +9,8 @@ module Mutations
|
|
9
9
|
:max_length => nil, # Can be a number like 10, meaning that at most 10 codepoints are permitted
|
10
10
|
:matches => nil, # Can be a regexp
|
11
11
|
:in => nil, # Can be an array like %w(red blue green)
|
12
|
-
:discard_empty => false
|
12
|
+
:discard_empty => false, # If the param is optional, discard_empty: true drops empty fields.
|
13
|
+
:allow_control_characters => false # false removes unprintable characters from the string
|
13
14
|
}
|
14
15
|
|
15
16
|
def filter(data)
|
@@ -21,12 +22,15 @@ module Mutations
|
|
21
22
|
end
|
22
23
|
|
23
24
|
# At this point, data is not nil. If it's not a string, convert it to a string for some standard classes
|
24
|
-
data = data.to_s if !options[:strict] && [TrueClass, FalseClass, Fixnum, Symbol].include?(data.class)
|
25
|
+
data = data.to_s if !options[:strict] && [TrueClass, FalseClass, Fixnum, Float, BigDecimal, Symbol].include?(data.class)
|
25
26
|
|
26
27
|
# Now ensure it's a string:
|
27
28
|
return [data, :string] unless data.is_a?(String)
|
28
29
|
|
29
|
-
# At this point, data is a string.
|
30
|
+
# At this point, data is a string. Now remove unprintable characters from the string:
|
31
|
+
data = data.gsub(/[^[:print:]\t\r\n]+/, ' ') unless options[:allow_control_characters]
|
32
|
+
|
33
|
+
# Transform it using strip:
|
30
34
|
data = data.strip if options[:strip]
|
31
35
|
|
32
36
|
# Now check if it's blank:
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Mutations
|
2
|
+
class TimeFilter < AdditionalFilter
|
3
|
+
@default_options = {
|
4
|
+
:nils => false, # true allows an explicit nil to be valid. Overrides any other options
|
5
|
+
:format => nil, # If nil, Time.parse will be used for coercion, otherwise we will use Time.strptime
|
6
|
+
:after => nil, # A Time object, representing the minimum time allowed, inclusive
|
7
|
+
:before => nil # A Time object, representing the maximum time allowed, inclusive
|
8
|
+
}
|
9
|
+
|
10
|
+
def filter(data)
|
11
|
+
# Handle nil case
|
12
|
+
if data.nil?
|
13
|
+
return [nil, nil] if options[:nils]
|
14
|
+
return [nil, :nils]
|
15
|
+
end
|
16
|
+
|
17
|
+
# Now check if it's empty:
|
18
|
+
return [data, :empty] if '' == data
|
19
|
+
|
20
|
+
if data.is_a?(Time) # Time
|
21
|
+
actual_time = data
|
22
|
+
elsif data.is_a?(String)
|
23
|
+
begin
|
24
|
+
actual_time = if options[:format]
|
25
|
+
Time.strptime(data, options[:format])
|
26
|
+
else
|
27
|
+
Time.parse(data)
|
28
|
+
end
|
29
|
+
rescue ArgumentError
|
30
|
+
return [nil, :time]
|
31
|
+
end
|
32
|
+
elsif data.respond_to?(:to_time) # Date, DateTime
|
33
|
+
actual_time = data.to_time
|
34
|
+
else
|
35
|
+
return [nil, :time]
|
36
|
+
end
|
37
|
+
|
38
|
+
if options[:after]
|
39
|
+
if actual_time <= options[:after]
|
40
|
+
return [nil, :after]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
if options[:before]
|
45
|
+
if actual_time >= options[:before]
|
46
|
+
return [nil, :before]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# We win, it's valid!
|
51
|
+
[actual_time, nil]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/mutations/version.rb
CHANGED
data/mutations.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.test_files = `git ls-files test`.split("\n")
|
13
13
|
s.require_path = 'lib'
|
14
14
|
|
15
|
-
s.add_dependency
|
15
|
+
s.add_dependency "activesupport"
|
16
16
|
s.add_development_dependency 'minitest', '~> 4'
|
17
17
|
s.add_development_dependency 'rake'
|
18
18
|
end
|
@@ -125,5 +125,22 @@ describe "Mutations::AdditionalFilter" do
|
|
125
125
|
assert_equal true, TestCommandUsingBlockArgument.run!(:foo => 'bar')
|
126
126
|
end
|
127
127
|
|
128
|
+
class TestCommandUsingBlockArgumentInAnArray < Mutations::Command
|
129
|
+
required do
|
130
|
+
array :some_array do
|
131
|
+
additional_with_block do
|
132
|
+
should_be_called
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def execute
|
138
|
+
true
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
it "It can have a block constructor when used in an array" do
|
143
|
+
assert_equal true, TestCommandUsingBlockArgumentInAnArray.run!(:some_array => ['bar'])
|
144
|
+
end
|
128
145
|
end
|
129
146
|
end
|
data/spec/date_filter_spec.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'stringio'
|
3
|
-
require 'tempfile'
|
4
2
|
|
5
3
|
describe "Mutations::DateFilter" do
|
6
4
|
it "takes a date object" do
|
@@ -19,7 +17,7 @@ describe "Mutations::DateFilter" do
|
|
19
17
|
assert_equal nil, errors
|
20
18
|
end
|
21
19
|
|
22
|
-
it "takes a Time object and
|
20
|
+
it "takes a Time object and converts it to a date" do
|
23
21
|
time = Time.now
|
24
22
|
f = Mutations::DateFilter.new
|
25
23
|
filtered, errors = f.filter(time)
|
@@ -61,7 +59,7 @@ describe "Mutations::DateFilter" do
|
|
61
59
|
assert_equal nil, errors
|
62
60
|
end
|
63
61
|
|
64
|
-
it "gives errors when the given date is after the
|
62
|
+
it "gives errors when the given date is after the before date" do
|
65
63
|
date = Date.new(2005, 1, 1)
|
66
64
|
before_date = Date.new(2000, 1, 1)
|
67
65
|
f = Mutations::DateFilter.new(:before => before_date)
|
@@ -130,6 +128,7 @@ describe "Mutations::DateFilter" do
|
|
130
128
|
it "considers empty strings to be empty" do
|
131
129
|
f = Mutations::DateFilter.new
|
132
130
|
filtered, errors = f.filter("")
|
131
|
+
assert_equal "", filtered
|
133
132
|
assert_equal :empty, errors
|
134
133
|
end
|
135
134
|
|
data/spec/integer_filter_spec.rb
CHANGED
@@ -51,6 +51,19 @@ describe "Mutations::IntegerFilter" do
|
|
51
51
|
assert_equal :empty, errors
|
52
52
|
end
|
53
53
|
|
54
|
+
it "considers empty strings to be nil if empty_is_nil option is used" do
|
55
|
+
f = Mutations::IntegerFilter.new(:empty_is_nil => true)
|
56
|
+
filtered, errors = f.filter("")
|
57
|
+
assert_equal :nils, errors
|
58
|
+
end
|
59
|
+
|
60
|
+
it "returns empty strings as nil if empty_is_nil option is used" do
|
61
|
+
f = Mutations::IntegerFilter.new(:empty_is_nil => true, :nils => true)
|
62
|
+
filtered, errors = f.filter("")
|
63
|
+
assert_equal nil, filtered
|
64
|
+
assert_equal nil, errors
|
65
|
+
end
|
66
|
+
|
54
67
|
it "considers low numbers invalid" do
|
55
68
|
f = Mutations::IntegerFilter.new(:min => 10)
|
56
69
|
filtered, errors = f.filter(3)
|
data/spec/string_filter_spec.rb
CHANGED
@@ -80,6 +80,13 @@ describe "Mutations::StringFilter" do
|
|
80
80
|
assert_equal :empty, errors
|
81
81
|
end
|
82
82
|
|
83
|
+
it "considers strings that contain only unprintable characters to be invalid" do
|
84
|
+
sf = Mutations::StringFilter.new(:empty => false)
|
85
|
+
filtered, errors = sf.filter("\u0000\u0000")
|
86
|
+
assert_equal "", filtered
|
87
|
+
assert_equal :empty, errors
|
88
|
+
end
|
89
|
+
|
83
90
|
it "considers long strings to be invalid" do
|
84
91
|
sf = Mutations::StringFilter.new(:max_length => 5)
|
85
92
|
filtered, errors = sf.filter("123456")
|
@@ -150,6 +157,20 @@ describe "Mutations::StringFilter" do
|
|
150
157
|
assert_equal nil, errors
|
151
158
|
end
|
152
159
|
|
160
|
+
it "converts bigdecimals to strings" do
|
161
|
+
sf = Mutations::StringFilter.new(:strict => false)
|
162
|
+
filtered, errors = sf.filter(BigDecimal.new("0.0001"))
|
163
|
+
assert_equal "0.1E-3", filtered
|
164
|
+
assert_equal nil, errors
|
165
|
+
end
|
166
|
+
|
167
|
+
it "converts floats to strings" do
|
168
|
+
sf = Mutations::StringFilter.new(:strict => false)
|
169
|
+
filtered, errors = sf.filter(0.0001)
|
170
|
+
assert_equal "0.0001", filtered
|
171
|
+
assert_equal nil, errors
|
172
|
+
end
|
173
|
+
|
153
174
|
it "converts booleans to strings" do
|
154
175
|
sf = Mutations::StringFilter.new(:strict => false)
|
155
176
|
filtered, errors = sf.filter(true)
|
@@ -171,10 +192,47 @@ describe "Mutations::StringFilter" do
|
|
171
192
|
assert_equal :string, errors
|
172
193
|
end
|
173
194
|
|
195
|
+
it "disallows bigdecimals" do
|
196
|
+
sf = Mutations::StringFilter.new(:strict => true)
|
197
|
+
big_decimal = BigDecimal.new("0.0001")
|
198
|
+
filtered, errors = sf.filter(big_decimal)
|
199
|
+
assert_equal big_decimal, filtered
|
200
|
+
assert_equal :string, errors
|
201
|
+
end
|
202
|
+
|
203
|
+
it "disallows floats" do
|
204
|
+
sf = Mutations::StringFilter.new(:strict => true)
|
205
|
+
filtered, errors = sf.filter(0.0001)
|
206
|
+
assert_equal 0.0001, filtered
|
207
|
+
assert_equal :string, errors
|
208
|
+
end
|
209
|
+
|
174
210
|
it "disallows booleans" do
|
175
211
|
sf = Mutations::StringFilter.new(:strict => true)
|
176
212
|
filtered, errors = sf.filter(true)
|
177
213
|
assert_equal true, filtered
|
178
214
|
assert_equal :string, errors
|
179
215
|
end
|
216
|
+
|
217
|
+
it "removes unprintable characters" do
|
218
|
+
sf = Mutations::StringFilter.new(:allow_control_characters => false)
|
219
|
+
filtered, errors = sf.filter("Hello\u0000\u0000World!")
|
220
|
+
assert_equal "Hello World!", filtered
|
221
|
+
assert_equal nil, errors
|
222
|
+
end
|
223
|
+
|
224
|
+
it "doesn't remove unprintable characters" do
|
225
|
+
sf = Mutations::StringFilter.new(:allow_control_characters => true)
|
226
|
+
filtered, errors = sf.filter("Hello\u0000\u0000World!")
|
227
|
+
assert_equal "Hello\u0000\u0000World!", filtered
|
228
|
+
assert_equal nil, errors
|
229
|
+
end
|
230
|
+
|
231
|
+
it "doesn't remove tabs, spaces and line breaks" do
|
232
|
+
sf = Mutations::StringFilter.new(:allow_control_characters => false)
|
233
|
+
filtered, errors = sf.filter("Hello,\tWorld !\r\nNew Line")
|
234
|
+
assert_equal "Hello,\tWorld !\r\nNew Line", filtered
|
235
|
+
assert_equal nil, errors
|
236
|
+
end
|
237
|
+
|
180
238
|
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Mutations::TimeFilter" do
|
4
|
+
|
5
|
+
it "takes a Time object" do
|
6
|
+
time = Time.now
|
7
|
+
f = Mutations::TimeFilter.new
|
8
|
+
filtered, errors = f.filter(time)
|
9
|
+
assert_equal time, filtered
|
10
|
+
assert_equal nil, errors
|
11
|
+
end
|
12
|
+
|
13
|
+
it "takes a Date object and converts it to a time" do
|
14
|
+
date = Date.new
|
15
|
+
f = Mutations::TimeFilter.new
|
16
|
+
filtered, errors = f.filter(date)
|
17
|
+
assert_equal date.to_time, filtered
|
18
|
+
assert_equal nil, errors
|
19
|
+
end
|
20
|
+
|
21
|
+
it "takes a DateTime object and converts it to a time" do
|
22
|
+
date = DateTime.new
|
23
|
+
f = Mutations::TimeFilter.new
|
24
|
+
filtered, errors = f.filter(date)
|
25
|
+
assert_equal date.to_time, filtered
|
26
|
+
assert_equal nil, errors
|
27
|
+
end
|
28
|
+
|
29
|
+
it "checks if the given time is after a certain time" do
|
30
|
+
time = Time.now
|
31
|
+
f = Mutations::TimeFilter.new(:after => time - 1)
|
32
|
+
filtered, errors = f.filter(time)
|
33
|
+
assert_equal time, filtered
|
34
|
+
assert_equal nil, errors
|
35
|
+
end
|
36
|
+
|
37
|
+
it "gives errors when the given time is before the after time" do
|
38
|
+
time = Time.now
|
39
|
+
f = Mutations::TimeFilter.new(:after => time + 1)
|
40
|
+
filtered, errors = f.filter(time)
|
41
|
+
assert_equal nil, filtered
|
42
|
+
assert_equal :after, errors
|
43
|
+
end
|
44
|
+
|
45
|
+
it "checks if the given time is before a certain time" do
|
46
|
+
time = Time.now
|
47
|
+
f = Mutations::TimeFilter.new(:before => time + 1)
|
48
|
+
filtered, errors = f.filter(time)
|
49
|
+
assert_equal time, filtered
|
50
|
+
assert_equal nil, errors
|
51
|
+
end
|
52
|
+
|
53
|
+
it "gives errors when the given time is after the before time" do
|
54
|
+
time = Time.now
|
55
|
+
f = Mutations::TimeFilter.new(:before => time - 1)
|
56
|
+
filtered, errors = f.filter(time)
|
57
|
+
assert_equal nil, filtered
|
58
|
+
assert_equal :before, errors
|
59
|
+
end
|
60
|
+
|
61
|
+
it "checks if the given time is in the given range" do
|
62
|
+
time = Time.now
|
63
|
+
f = Mutations::TimeFilter.new(:after => time - 1, :before => time + 1)
|
64
|
+
filtered, errors = f.filter(time)
|
65
|
+
assert_equal time, filtered
|
66
|
+
assert_equal nil, errors
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should be able to parse a D-M-Y string to a time" do
|
70
|
+
date_string = "2-1-2000"
|
71
|
+
date = Date.new(2000, 1, 2)
|
72
|
+
f = Mutations::TimeFilter.new
|
73
|
+
filtered, errors = f.filter(date_string)
|
74
|
+
assert_equal date.to_time, filtered
|
75
|
+
assert_equal nil, errors
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should be able to parse a Y-M-D string to a time" do
|
79
|
+
date_string = "2000-1-2"
|
80
|
+
date = Date.new(2000, 1, 2)
|
81
|
+
f = Mutations::TimeFilter.new
|
82
|
+
filtered, errors = f.filter(date_string)
|
83
|
+
assert_equal date.to_time, filtered
|
84
|
+
assert_equal nil, errors
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should be able to handle time formatting" do
|
88
|
+
time_string = "2000-1-2 12:13:14"
|
89
|
+
time = Time.new(2000, 1, 2, 12, 13, 14)
|
90
|
+
f = Mutations::TimeFilter.new(:format => '%Y-%m-%d %H:%M:%S')
|
91
|
+
filtered, errors = f.filter(time_string)
|
92
|
+
assert_equal time, filtered
|
93
|
+
assert_equal nil, errors
|
94
|
+
|
95
|
+
time_string = "1, 2, 2000, 121314"
|
96
|
+
f = Mutations::TimeFilter.new(:format => '%m, %d, %Y, %H%M%S')
|
97
|
+
filtered, errors = f.filter(time_string)
|
98
|
+
assert_equal time, filtered
|
99
|
+
assert_equal nil, errors
|
100
|
+
end
|
101
|
+
|
102
|
+
it "considers nil to be invalid" do
|
103
|
+
f = Mutations::TimeFilter.new
|
104
|
+
filtered, errors = f.filter(nil)
|
105
|
+
assert_equal nil, filtered
|
106
|
+
assert_equal :nils, errors
|
107
|
+
end
|
108
|
+
|
109
|
+
it "allows the use of nil when specified" do
|
110
|
+
f = Mutations::TimeFilter.new(:nils => true)
|
111
|
+
filtered, errors = f.filter(nil)
|
112
|
+
assert_equal nil, filtered
|
113
|
+
assert_equal nil, errors
|
114
|
+
end
|
115
|
+
|
116
|
+
it "considers empty strings to be empty" do
|
117
|
+
f = Mutations::TimeFilter.new
|
118
|
+
filtered, errors = f.filter('')
|
119
|
+
assert_equal '', filtered
|
120
|
+
assert_equal :empty, errors
|
121
|
+
end
|
122
|
+
|
123
|
+
it "doesn't allow non-existing times" do
|
124
|
+
invalid_time_string = "1, 20, 2013 25:13"
|
125
|
+
f = Mutations::TimeFilter.new
|
126
|
+
filtered, errors = f.filter(invalid_time_string)
|
127
|
+
assert_equal nil, filtered
|
128
|
+
assert_equal :time, errors
|
129
|
+
end
|
130
|
+
end
|
metadata
CHANGED
@@ -1,64 +1,78 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mutations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 0.7.2
|
4
|
+
version: 0.8.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Jonathan Novak
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
|
-
cert_chain:
|
12
|
-
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIDXDCCAkSgAwIBAgIBATANBgkqhkiG9w0BAQUFADA6MQowCAYDVQQDDAFwMRcw
|
14
|
+
FQYKCZImiZPyLGQBGRYHdHJpY2tvZDETMBEGCgmSJomT8ixkARkWA2NvbTAeFw0x
|
15
|
+
NjA0MjUyMTQ4NDBaFw0xNzA0MjUyMTQ4NDBaMDoxCjAIBgNVBAMMAXAxFzAVBgoJ
|
16
|
+
kiaJk/IsZAEZFgd0cmlja29kMRMwEQYKCZImiZPyLGQBGRYDY29tMIIBIjANBgkq
|
17
|
+
hkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3o2utXZQGfUe4DVqUPWirBGMOZFbmdHL
|
18
|
+
yK0/BcSaS4KT9yHZ3HmdarZth2OY9cceG1IqHBQBm4+aW5e8yT2bGAOkGbnalSAG
|
19
|
+
hgy376xolLXc2OSw9guTutZ/lO/0B9sicS+92VtwKu/+VR2wousPIJSIXQMYBbz/
|
20
|
+
I4266npP7/gHuejxxXhrDQ4cnDZY/OmcQpYxaKX2Nb8/PkoBIlIC2dbM8/f4pML0
|
21
|
+
8YEtD19QPs5AU00doh2HENo0QInKyjvWkmGxVQTaynGVMfSAhmLr0i+DSg6Rck2D
|
22
|
+
O3mi2aBWAfZS/yiGL0E6ZvAKMaiW9tZPbP+x72iT9DuH5MZiAqlbOQIDAQABo20w
|
23
|
+
azAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUONNcTs7C+A6N5EMj
|
24
|
+
HGkH+mQhqtUwGAYDVR0RBBEwD4ENcEB0cmlja29kLmNvbTAYBgNVHRIEETAPgQ1w
|
25
|
+
QHRyaWNrb2QuY29tMA0GCSqGSIb3DQEBBQUAA4IBAQCbTR4U4G1YNcU5R/6kZUIw
|
26
|
+
XaKBAu4CHUIAHj9A1m/wp8siGeoaE1PzkxfSotM7VYG/kItWxlocEFpJLe3ouiy+
|
27
|
+
ZFgUNUigTPfdzrtpWOfLThDGyBpKo8lwpndbUb9KG+IflJ7dJhpw32rXu1rZojl6
|
28
|
+
D3FU30VBrEA8nIM/flPiGgmmhL/eOE9exRTYF9ePsmV2OzsR1CxHx8856/JEzov5
|
29
|
+
Kgw8az4smHcDSM3d9ZORqx+gg1A9wQpTrrA68mWf1i0QK+r+C9cys7m+6UWkLKSa
|
30
|
+
ZVUPzKU88XkDLtlpM6AQpL+fslquuq8VF3Fp68YYg1uppU2wexcbTcjS/cgoml6b
|
31
|
+
-----END CERTIFICATE-----
|
32
|
+
date: 2016-06-05 00:00:00.000000000 Z
|
13
33
|
dependencies:
|
14
34
|
- !ruby/object:Gem::Dependency
|
15
35
|
name: activesupport
|
16
36
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
37
|
requirements:
|
19
|
-
- -
|
38
|
+
- - ">="
|
20
39
|
- !ruby/object:Gem::Version
|
21
40
|
version: '0'
|
22
41
|
type: :runtime
|
42
|
+
prerelease: false
|
23
43
|
version_requirements: !ruby/object:Gem::Requirement
|
24
|
-
none: false
|
25
44
|
requirements:
|
26
|
-
- -
|
45
|
+
- - ">="
|
27
46
|
- !ruby/object:Gem::Version
|
28
47
|
version: '0'
|
29
|
-
prerelease: false
|
30
48
|
- !ruby/object:Gem::Dependency
|
31
49
|
name: minitest
|
32
50
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
51
|
requirements:
|
35
|
-
- - ~>
|
52
|
+
- - "~>"
|
36
53
|
- !ruby/object:Gem::Version
|
37
54
|
version: '4'
|
38
55
|
type: :development
|
56
|
+
prerelease: false
|
39
57
|
version_requirements: !ruby/object:Gem::Requirement
|
40
|
-
none: false
|
41
58
|
requirements:
|
42
|
-
- - ~>
|
59
|
+
- - "~>"
|
43
60
|
- !ruby/object:Gem::Version
|
44
61
|
version: '4'
|
45
|
-
prerelease: false
|
46
62
|
- !ruby/object:Gem::Dependency
|
47
63
|
name: rake
|
48
64
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
65
|
requirements:
|
51
|
-
- -
|
66
|
+
- - ">="
|
52
67
|
- !ruby/object:Gem::Version
|
53
68
|
version: '0'
|
54
69
|
type: :development
|
70
|
+
prerelease: false
|
55
71
|
version_requirements: !ruby/object:Gem::Requirement
|
56
|
-
none: false
|
57
72
|
requirements:
|
58
|
-
- -
|
73
|
+
- - ">="
|
59
74
|
- !ruby/object:Gem::Version
|
60
75
|
version: '0'
|
61
|
-
prerelease: false
|
62
76
|
description: Compose your business logic into commands that sanitize and validate
|
63
77
|
input.
|
64
78
|
email: jnovak@gmail.com
|
@@ -66,8 +80,8 @@ executables: []
|
|
66
80
|
extensions: []
|
67
81
|
extra_rdoc_files: []
|
68
82
|
files:
|
69
|
-
- .gitignore
|
70
|
-
- .travis.yml
|
83
|
+
- ".gitignore"
|
84
|
+
- ".travis.yml"
|
71
85
|
- CHANGELOG.md
|
72
86
|
- Gemfile
|
73
87
|
- MIT-LICENSE
|
@@ -91,6 +105,7 @@ files:
|
|
91
105
|
- lib/mutations/model_filter.rb
|
92
106
|
- lib/mutations/outcome.rb
|
93
107
|
- lib/mutations/string_filter.rb
|
108
|
+
- lib/mutations/time_filter.rb
|
94
109
|
- lib/mutations/version.rb
|
95
110
|
- mutations.gemspec
|
96
111
|
- spec/additional_filter_spec.rb
|
@@ -111,28 +126,29 @@ files:
|
|
111
126
|
- spec/simple_command.rb
|
112
127
|
- spec/spec_helper.rb
|
113
128
|
- spec/string_filter_spec.rb
|
129
|
+
- spec/time_filter_spec.rb
|
114
130
|
homepage: http://github.com/cypriss/mutations
|
115
131
|
licenses: []
|
132
|
+
metadata: {}
|
116
133
|
post_install_message:
|
117
134
|
rdoc_options: []
|
118
135
|
require_paths:
|
119
136
|
- lib
|
120
137
|
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
138
|
requirements:
|
123
|
-
- -
|
139
|
+
- - ">="
|
124
140
|
- !ruby/object:Gem::Version
|
125
141
|
version: '0'
|
126
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
-
none: false
|
128
143
|
requirements:
|
129
|
-
- -
|
144
|
+
- - ">="
|
130
145
|
- !ruby/object:Gem::Version
|
131
146
|
version: '0'
|
132
147
|
requirements: []
|
133
148
|
rubyforge_project:
|
134
|
-
rubygems_version:
|
149
|
+
rubygems_version: 2.5.1
|
135
150
|
signing_key:
|
136
|
-
specification_version:
|
151
|
+
specification_version: 4
|
137
152
|
summary: Compose your business logic into commands that sanitize and validate input.
|
138
153
|
test_files: []
|
154
|
+
has_rdoc:
|
metadata.gz.sig
ADDED
Binary file
|