duck-hunt 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e83a3b44d7c09021e9473a718dbe41a359ca2e606cb4aeed705186c67f419ed0
4
+ data.tar.gz: a6963371ad99552cecb8b7a69f5a15d8bcade5115b14924e216b9b9dae26c5b6
5
+ SHA512:
6
+ metadata.gz: 021500d3fbb1bb1d22c5ec8579ec1d556a868f394e92684f8e5d3217308abfe28270b0d4669d36f6ecdedc204fa81e0143c0af9fe78ad3bd2eac5b8539158b15
7
+ data.tar.gz: 93f9948d65a24c6a6a2c4ffed665f7325bb7c09aa50c4ac53de25cdcc5f151d05d50e5329d55153dc95042d0bb4d187b9005bcc0fe57b4d2da5da9700937adec
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Duck Hunt
1
+ # Duck Hunt [![CircleCI](https://circleci.com/gh/tcannonfodder/duck-hunt.svg?style=svg)](https://circleci.com/gh/tcannonfodder/duck-hunt)
2
2
  ## A dependency-free object validator for Ruby
3
3
 
4
4
  Duck Typing is pretty fantastic, but sometimes you need to be sure your inputs match what you expect.
@@ -4,6 +4,7 @@ module DuckHunt
4
4
  autoload :Property, File.dirname(__FILE__) + "/properties/property.rb"
5
5
  autoload :Integer, File.dirname(__FILE__) + "/properties/integer.rb"
6
6
  autoload :Float, File.dirname(__FILE__) + "/properties/float.rb"
7
+ autoload :Numeric, File.dirname(__FILE__) + "/properties/numeric.rb"
7
8
  autoload :NestedHash, File.dirname(__FILE__) + "/properties/nested_hash.rb"
8
9
  autoload :Array, File.dirname(__FILE__) + "/properties/array.rb"
9
10
  autoload :String, File.dirname(__FILE__) + "/properties/string.rb"
@@ -0,0 +1,10 @@
1
+ module DuckHunt
2
+ module Properties
3
+ class Numeric < Property
4
+ def matches_type?(value)
5
+ return true if (value.is_a?(::Float) || value.is_a?(::BigDecimal) || (value.integer? rescue return false))
6
+ return false
7
+ end
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module DuckHunt
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -0,0 +1,53 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ describe DuckHunt::Properties::Numeric, "validation" do
4
+ before do
5
+ @property = DuckHunt::Properties::Numeric.new
6
+ end
7
+
8
+ it "should be able to validate a float" do
9
+ float = 1.17
10
+ float.must_be_instance_of Float
11
+ @property.valid?(float).must_equal true
12
+ @property.errors.size.must_equal 0
13
+ end
14
+
15
+ it "should be able to validate a BigDecimal floating point" do
16
+ bigdecimal = BigDecimal.new("3.4")
17
+ bigdecimal.must_be_instance_of BigDecimal
18
+ @property.valid?(bigdecimal).must_equal true
19
+ @property.errors.size.must_equal 0
20
+ end
21
+
22
+ it "should be invalid if there's a type mismatch" do
23
+ @property.valid?([1,2,3]).must_equal false
24
+ @property.errors.size.must_equal 1
25
+ @property.errors.first.must_equal "wrong type"
26
+ end
27
+
28
+ it "should be able to parse a Fixnum" do
29
+ integer = 3
30
+ integer.must_be_instance_of Fixnum
31
+ @property.valid?(integer).must_equal true
32
+ @property.errors.size.must_equal 0
33
+ end
34
+
35
+ it "should be able to parse a Bignum" do
36
+ integer = 18446744073709551616
37
+ integer.must_be_instance_of Bignum
38
+ @property.valid?(integer).must_equal true
39
+ @property.errors.size.must_equal 0
40
+ end
41
+
42
+ it "should not be able to parse a string of an integer" do
43
+ @property.valid?("3").must_equal false
44
+ @property.errors.size.must_equal 1
45
+ @property.errors.first.must_equal "wrong type"
46
+ end
47
+
48
+ it "should not be able to validate a string of an float" do
49
+ @property.valid?("3.17").must_equal false
50
+ @property.errors.size.must_equal 1
51
+ @property.errors.first.must_equal "wrong type"
52
+ end
53
+ end
metadata CHANGED
@@ -1,92 +1,87 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: duck-hunt
3
- version: !ruby/object:Gem::Version
4
- hash: 21
5
- prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 5
10
- version: 0.0.5
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Thomas Cannon
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2014-10-12 00:00:00 -04:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
11
+ date: 2019-04-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
22
14
  name: minitest
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
27
17
  - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
33
20
  type: :development
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: mocha
37
21
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mocha
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
41
31
  - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 0
46
- version: "0"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
47
34
  type: :development
48
- version_requirements: *id002
49
- - !ruby/object:Gem::Dependency
50
- name: rake
51
35
  prerelease: false
52
- requirement: &id003 !ruby/object:Gem::Requirement
53
- none: false
54
- requirements:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
55
45
  - - ">="
56
- - !ruby/object:Gem::Version
57
- hash: 3
58
- segments:
59
- - 0
60
- version: "0"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
61
48
  type: :development
62
- version_requirements: *id003
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
63
55
  description: Dependency-free object validation library for Ruby 1.8.7+
64
- email:
56
+ email:
65
57
  - hello@thomascannon.me
66
58
  executables: []
67
-
68
59
  extensions: []
69
-
70
60
  extra_rdoc_files: []
71
-
72
- files:
61
+ files:
62
+ - LICENSE
63
+ - README.md
64
+ - Rakefile
65
+ - lib/duck-hunt.rb
73
66
  - lib/duck-hunt/hash_helpers.rb
67
+ - lib/duck-hunt/properties.rb
74
68
  - lib/duck-hunt/properties/array.rb
75
69
  - lib/duck-hunt/properties/boolean.rb
76
70
  - lib/duck-hunt/properties/float.rb
77
71
  - lib/duck-hunt/properties/integer.rb
78
72
  - lib/duck-hunt/properties/nested_hash.rb
79
73
  - lib/duck-hunt/properties/nil.rb
74
+ - lib/duck-hunt/properties/numeric.rb
80
75
  - lib/duck-hunt/properties/property.rb
81
76
  - lib/duck-hunt/properties/string.rb
82
77
  - lib/duck-hunt/properties/validator_lookup.rb
83
- - lib/duck-hunt/properties.rb
78
+ - lib/duck-hunt/schemas.rb
84
79
  - lib/duck-hunt/schemas/array_schema.rb
85
80
  - lib/duck-hunt/schemas/hash_schema.rb
86
81
  - lib/duck-hunt/schemas/property_lookup.rb
87
82
  - lib/duck-hunt/schemas/schema_definition.rb
88
- - lib/duck-hunt/schemas.rb
89
83
  - lib/duck-hunt/string_helpers.rb
84
+ - lib/duck-hunt/validators.rb
90
85
  - lib/duck-hunt/validators/accepted_values.rb
91
86
  - lib/duck-hunt/validators/allow_blank.rb
92
87
  - lib/duck-hunt/validators/allow_empty.rb
@@ -101,18 +96,14 @@ files:
101
96
  - lib/duck-hunt/validators/not_equal_to.rb
102
97
  - lib/duck-hunt/validators/rejected_values.rb
103
98
  - lib/duck-hunt/validators/validator.rb
104
- - lib/duck-hunt/validators.rb
105
99
  - lib/duck-hunt/version.rb
106
- - lib/duck-hunt.rb
107
- - LICENSE
108
- - Rakefile
109
- - README.md
110
100
  - test/properties/array_test.rb
111
101
  - test/properties/boolean_test.rb
112
102
  - test/properties/float_test.rb
113
103
  - test/properties/integer_test.rb
114
104
  - test/properties/nested_hash_test.rb
115
105
  - test/properties/nil_test.rb
106
+ - test/properties/numeric_test.rb
116
107
  - test/properties/property_test.rb
117
108
  - test/properties/string_test.rb
118
109
  - test/properties/validator_lookup_test.rb
@@ -120,8 +111,8 @@ files:
120
111
  - test/schemas/hash_schema_test.rb
121
112
  - test/schemas/property_lookup_test.rb
122
113
  - test/schemas/schema_definition_test.rb
123
- - test/test_helper/test_classes.rb
124
114
  - test/test_helper.rb
115
+ - test/test_helper/test_classes.rb
125
116
  - test/validators/accepted_values_test.rb
126
117
  - test/validators/allow_blank_test.rb
127
118
  - test/validators/allow_empty_test.rb
@@ -136,67 +127,56 @@ files:
136
127
  - test/validators/not_equal_to_test.rb
137
128
  - test/validators/rejected_values_test.rb
138
129
  - test/validators/validator_test.rb
139
- has_rdoc: true
140
- homepage: https://github.com/LockeCole117/duck-hunt
130
+ homepage: https://github.com/tcannonfodder/duck-hunt
141
131
  licenses: []
142
-
132
+ metadata: {}
143
133
  post_install_message:
144
134
  rdoc_options: []
145
-
146
- require_paths:
135
+ require_paths:
147
136
  - lib
148
- required_ruby_version: !ruby/object:Gem::Requirement
149
- none: false
150
- requirements:
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
151
139
  - - ">="
152
- - !ruby/object:Gem::Version
153
- hash: 3
154
- segments:
155
- - 0
156
- version: "0"
157
- required_rubygems_version: !ruby/object:Gem::Requirement
158
- none: false
159
- requirements:
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
160
144
  - - ">="
161
- - !ruby/object:Gem::Version
162
- hash: 3
163
- segments:
164
- - 0
165
- version: "0"
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
166
147
  requirements: []
167
-
168
- rubyforge_project:
169
- rubygems_version: 1.6.2
148
+ rubygems_version: 3.0.3
170
149
  signing_key:
171
- specification_version: 3
150
+ specification_version: 4
172
151
  summary: Dependency-free object validation library for Ruby 1.8.7+
173
- test_files:
152
+ test_files:
153
+ - test/schemas/hash_schema_test.rb
154
+ - test/schemas/array_schema_test.rb
155
+ - test/schemas/property_lookup_test.rb
156
+ - test/schemas/schema_definition_test.rb
157
+ - test/properties/nil_test.rb
158
+ - test/properties/nested_hash_test.rb
174
159
  - test/properties/array_test.rb
175
160
  - test/properties/boolean_test.rb
176
- - test/properties/float_test.rb
177
- - test/properties/integer_test.rb
178
- - test/properties/nested_hash_test.rb
179
- - test/properties/nil_test.rb
180
161
  - test/properties/property_test.rb
181
- - test/properties/string_test.rb
182
162
  - test/properties/validator_lookup_test.rb
183
- - test/schemas/array_schema_test.rb
184
- - test/schemas/hash_schema_test.rb
185
- - test/schemas/property_lookup_test.rb
186
- - test/schemas/schema_definition_test.rb
163
+ - test/properties/string_test.rb
164
+ - test/properties/integer_test.rb
165
+ - test/properties/numeric_test.rb
166
+ - test/properties/float_test.rb
187
167
  - test/test_helper/test_classes.rb
188
168
  - test/test_helper.rb
189
- - test/validators/accepted_values_test.rb
190
- - test/validators/allow_blank_test.rb
191
- - test/validators/allow_empty_test.rb
192
- - test/validators/divisible_by_test.rb
193
- - test/validators/equal_to_test.rb
194
- - test/validators/greater_than_or_equal_to_test.rb
195
- - test/validators/greater_than_test.rb
196
- - test/validators/less_than_or_equal_to_test.rb
197
169
  - test/validators/less_than_test.rb
198
170
  - test/validators/matches_test.rb
199
171
  - test/validators/not_divisible_by_test.rb
172
+ - test/validators/divisible_by_test.rb
200
173
  - test/validators/not_equal_to_test.rb
201
- - test/validators/rejected_values_test.rb
174
+ - test/validators/allow_blank_test.rb
202
175
  - test/validators/validator_test.rb
176
+ - test/validators/equal_to_test.rb
177
+ - test/validators/less_than_or_equal_to_test.rb
178
+ - test/validators/rejected_values_test.rb
179
+ - test/validators/greater_than_test.rb
180
+ - test/validators/accepted_values_test.rb
181
+ - test/validators/allow_empty_test.rb
182
+ - test/validators/greater_than_or_equal_to_test.rb