type_constraints 0.1.0 → 0.1.1
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:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: a73521ce1b69a6f75388eee3b92437c6df34dd82
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 988abcc17996f16e2d2912e2a0b729da6d472c8b
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: c1d04821360b1e2ba50d188cafe11c1d8505b079e49b78366e632d8349cf9bbb410295be508f5b7378b74350904cc8e9e5362f1e0ecf16d2fdb567b3e4293e3c
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: e88f5fa2c003baf515a4607555acdd05cc366b33116c32f0f360032c74c45cfb5bd942e53b4dc4b6ae17ffd0aebb8d0bab1b82b46914246fe899dd9c33810f8d
         
     | 
    
        data/lib/type_constraints.rb
    CHANGED
    
    | 
         @@ -1,6 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require "type_constraints/version"
         
     | 
| 
       2 
2 
     | 
    
         
             
            require "type_constraints/registry"
         
     | 
| 
       3 
3 
     | 
    
         
             
            require "type_constraints/meta"
         
     | 
| 
      
 4 
     | 
    
         
            +
            require "type_constraints/exceptions"
         
     | 
| 
       4 
5 
     | 
    
         | 
| 
       5 
6 
     | 
    
         
             
            module TypeConstraints
         
     | 
| 
       6 
7 
     | 
    
         
             
              class << self
         
     | 
| 
         @@ -15,6 +16,11 @@ module TypeConstraints 
     | 
|
| 
       15 
16 
     | 
    
         
             
                  return false if registry.metas[name].nil?
         
     | 
| 
       16 
17 
     | 
    
         
             
                  registry.metas[name].check?(val)
         
     | 
| 
       17 
18 
     | 
    
         
             
                end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                def check!(name, val)
         
     | 
| 
      
 21 
     | 
    
         
            +
                  raise Exceptions::MissingMeta if registry.metas[name].nil?
         
     | 
| 
      
 22 
     | 
    
         
            +
                  registry.metas[name].check!(val)
         
     | 
| 
      
 23 
     | 
    
         
            +
                end
         
     | 
| 
       18 
24 
     | 
    
         
             
              end
         
     | 
| 
       19 
25 
     | 
    
         
             
            end
         
     | 
| 
       20 
26 
     | 
    
         | 
| 
         @@ -35,4 +35,27 @@ describe TypeConstraints::Meta do 
     | 
|
| 
       35 
35 
     | 
    
         
             
                end
         
     | 
| 
       36 
36 
     | 
    
         
             
              end
         
     | 
| 
       37 
37 
     | 
    
         | 
| 
      
 38 
     | 
    
         
            +
              describe "#check!" do
         
     | 
| 
      
 39 
     | 
    
         
            +
                context "Without parent Object." do
         
     | 
| 
      
 40 
     | 
    
         
            +
                  meta = TypeConstraints::Meta.new(name: :AlwaysTrue, constraint: -> v { true })
         
     | 
| 
      
 41 
     | 
    
         
            +
                  it "returns TrueClass Object" do
         
     | 
| 
      
 42 
     | 
    
         
            +
                    result = meta.check!("hogehoge")
         
     | 
| 
      
 43 
     | 
    
         
            +
                    expect(result).to eq true
         
     | 
| 
      
 44 
     | 
    
         
            +
                  end
         
     | 
| 
      
 45 
     | 
    
         
            +
                end
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                context "With parent Object" do
         
     | 
| 
      
 48 
     | 
    
         
            +
                  parent = TypeConstraints::Meta.new(name: :AlwaysTrue, constraint: -> v { false })
         
     | 
| 
      
 49 
     | 
    
         
            +
                  meta   = TypeConstraints::Meta.new(
         
     | 
| 
      
 50 
     | 
    
         
            +
                    name: :AlwaysTrue,
         
     | 
| 
      
 51 
     | 
    
         
            +
                    constraint: -> v { true },
         
     | 
| 
      
 52 
     | 
    
         
            +
                    parent: parent
         
     | 
| 
      
 53 
     | 
    
         
            +
                  )
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
                  it "returns FalseClass Object" do
         
     | 
| 
      
 56 
     | 
    
         
            +
                    expect { meta.check!("hogehoge") }.to raise_error(TypeConstraints::Exceptions::Invalid)
         
     | 
| 
      
 57 
     | 
    
         
            +
                  end
         
     | 
| 
      
 58 
     | 
    
         
            +
                end
         
     | 
| 
      
 59 
     | 
    
         
            +
              end
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
       38 
61 
     | 
    
         
             
            end
         
     | 
| 
         @@ -45,4 +45,24 @@ describe TypeConstraints do 
     | 
|
| 
       45 
45 
     | 
    
         
             
                  expect(TypeConstraints.check?(:Hoge, [100, 200])).to eq false
         
     | 
| 
       46 
46 
     | 
    
         
             
                end
         
     | 
| 
       47 
47 
     | 
    
         
             
              end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
              describe "#check!" do
         
     | 
| 
      
 50 
     | 
    
         
            +
                it "return true if passed :TypeName and array" do
         
     | 
| 
      
 51 
     | 
    
         
            +
                  expect(TypeConstraints.check!(:TypeName, [100,101,102])).to eq true
         
     | 
| 
      
 52 
     | 
    
         
            +
                end
         
     | 
| 
      
 53 
     | 
    
         
            +
                it "returns exception if passed :TypeName and integer" do
         
     | 
| 
      
 54 
     | 
    
         
            +
                  expect { TypeConstraints.check!(:TypeName, 10000000000000) }.to raise_error(TypeConstraints::Exceptions::Invalid)
         
     | 
| 
      
 55 
     | 
    
         
            +
                end
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
                it "returns true if passed :TypeName2 and Array[string]" do
         
     | 
| 
      
 58 
     | 
    
         
            +
                  expect(TypeConstraints.check!(:TypeName2, ["100", "200"])).to eq true
         
     | 
| 
      
 59 
     | 
    
         
            +
                end
         
     | 
| 
      
 60 
     | 
    
         
            +
                it "returns exception if passed :TypeName2 and Array[integer]" do
         
     | 
| 
      
 61 
     | 
    
         
            +
                  expect { TypeConstraints.check!(:TypeName, 10000000000000) }.to raise_error(TypeConstraints::Exceptions::Invalid)
         
     | 
| 
      
 62 
     | 
    
         
            +
                end
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
                it "returns exception if not exists meta" do
         
     | 
| 
      
 65 
     | 
    
         
            +
                  expect { TypeConstraints.check!(:Hoge, [100, 200]) }.to raise_error(TypeConstraints::Exceptions::MissingMeta)
         
     | 
| 
      
 66 
     | 
    
         
            +
                end
         
     | 
| 
      
 67 
     | 
    
         
            +
              end
         
     | 
| 
       48 
68 
     | 
    
         
             
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: type_constraints
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.1
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - hisaichi5518
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date:  
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2015-01-09 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     | 
| 
         @@ -67,6 +67,7 @@ files: 
     | 
|
| 
       67 
67 
     | 
    
         
             
            - README.md
         
     | 
| 
       68 
68 
     | 
    
         
             
            - Rakefile
         
     | 
| 
       69 
69 
     | 
    
         
             
            - lib/type_constraints.rb
         
     | 
| 
      
 70 
     | 
    
         
            +
            - lib/type_constraints/exceptions.rb
         
     | 
| 
       70 
71 
     | 
    
         
             
            - lib/type_constraints/meta.rb
         
     | 
| 
       71 
72 
     | 
    
         
             
            - lib/type_constraints/registry.rb
         
     | 
| 
       72 
73 
     | 
    
         
             
            - lib/type_constraints/type/default.rb
         
     |