json_structure 0.0.2 → 0.0.3

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: 7743f55d019b53d39543aede96c77ab327a2fe4a
4
- data.tar.gz: 91f6d05f464028a7f8b3183db2b236b15033968b
3
+ metadata.gz: ddd50a60ceb48fde2376452cd100867cfc839f40
4
+ data.tar.gz: 12aedfb98c64758d0b69905111fd730b0811649a
5
5
  SHA512:
6
- metadata.gz: 622248b21a9759681fae67b8d6000bd28c77140e93a0ac2d83a1c9b717dc8b1fd2c93b465d74bb51fbd138002b8a1c5ebaae6c037185430b70966695db6aa515
7
- data.tar.gz: 570fbf46a0c804daf3603ad4b322b231764020157e86a8d12fadeecd9e4ad758e63015966d87fd6ae0456bbfe27f77ababafe160d17a170afeab734aa5bc15eb
6
+ metadata.gz: ee77013efd9d01e9bf5e42c9a10ee78ba79ae2b3678872cc7ea3d3e26f6c2e71ad9e6d49a977150e56e796165c72e2b4a8898ba8495ea9441a7c2c412cedc9f6
7
+ data.tar.gz: 1694e8b09ce760d8625315ed96526491ca3c6ba779e11311ef4c70cf19a5565fc7b7db16c5848eee97c987fcc86b9734b8c5fb2e83dc7d0900a8a6287de46daf
data/Rakefile CHANGED
@@ -1,2 +1,8 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
2
3
 
4
+ Rake::TestTask.new('test') do |test|
5
+ test.libs << 'test'
6
+ test.pattern = 'test/**/test_*.rb'
7
+ test.verbose = true
8
+ end
@@ -6,6 +6,10 @@ require 'json_structure/string'
6
6
  require 'json_structure/null'
7
7
  require 'json_structure/any_of'
8
8
  require 'json_structure/value'
9
+ require 'json_structure/any'
10
+ require 'json_structure/boolean'
11
+
12
+ require 'json_structure/version'
9
13
 
10
14
  module JsonStructure
11
15
  def self.build(&block)
@@ -13,18 +17,22 @@ module JsonStructure
13
17
  end
14
18
 
15
19
  class Builder
16
- [
17
- Type,
18
- Object_,
19
- Array,
20
- Number,
21
- Integer,
22
- Float,
23
- String,
24
- Null,
25
- AnyOf,
26
- ].each do |klass|
27
- method = klass.name
20
+ %w[
21
+ Type
22
+ Object_
23
+ Array
24
+ Number
25
+ Integer
26
+ String
27
+ Null
28
+ AnyOf
29
+ Value
30
+ Any
31
+ Boolean
32
+ ].each do |name|
33
+ klass = JsonStructure.const_get(name)
34
+
35
+ method = name
28
36
  .gsub(/([a-z])([A-Z])/, '\1_\2')
29
37
  .gsub(/_+$/, '')
30
38
  .downcase
@@ -0,0 +1,7 @@
1
+ module JsonStructure
2
+ class Any < Type
3
+ def ===(_value)
4
+ true
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module JsonStructure
2
+ class Boolean
3
+ def ===(value)
4
+ value == true || value == false
5
+ end
6
+ end
7
+ end
@@ -20,11 +20,4 @@ module JsonStructure
20
20
  super
21
21
  end
22
22
  end
23
-
24
- class Float < Number
25
- def ===(value)
26
- return false unless value.is_a?(::Float)
27
- super
28
- end
29
- end
30
23
  end
@@ -1,7 +1,7 @@
1
1
  module JsonStructure
2
2
  class Object_ < Type
3
3
  def initialize(hash = nil)
4
- @hash = hash.each_with_object({}) do |(key, value), new_hash|
4
+ @hash = hash && hash.each_with_object({}) do |(key, value), new_hash|
5
5
  new_hash[key.to_s] = value
6
6
  end
7
7
  end
@@ -9,9 +9,9 @@ module JsonStructure
9
9
  def ===(value)
10
10
  return false unless value.is_a?(::String)
11
11
 
12
- return false unless @min_length && value.size < @min_length
13
- return false unless @max_length && value.size > @max_length
14
- return false unless @pattern && pattern =~ value
12
+ return false if @min_length && value.size < @min_length
13
+ return false if @max_length && value.size > @max_length
14
+ return false if @pattern && @pattern !~ value
15
15
  true
16
16
  end
17
17
  end
@@ -1,11 +1,7 @@
1
1
  module JsonStructure
2
2
  class Type
3
- def initialize(cond)
4
- @cond = cond
5
- end
6
-
7
- def ===(value)
8
- !!(@cond && @cond.call(value))
3
+ def ===(*)
4
+ false
9
5
  end
10
6
 
11
7
  def |(type)
@@ -1,3 +1,3 @@
1
1
  module JsonStructure
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_structure
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kaido Iwamoto
@@ -55,8 +55,10 @@ files:
55
55
  - bin/setup
56
56
  - json_structure.gemspec
57
57
  - lib/json_structure.rb
58
+ - lib/json_structure/any.rb
58
59
  - lib/json_structure/any_of.rb
59
60
  - lib/json_structure/array.rb
61
+ - lib/json_structure/boolean.rb
60
62
  - lib/json_structure/null.rb
61
63
  - lib/json_structure/number.rb
62
64
  - lib/json_structure/object.rb