strong_ruby 0.0.1 → 0.0.2

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: a47fe5e22e913ae1a56c9db2deaeed13df8283b0
4
- data.tar.gz: 6b24a71bf81c91b82ded0feb16b87418a4e4e310
3
+ metadata.gz: 2842c6eb62b601a1dea1e19b2fc30a937e8b152f
4
+ data.tar.gz: 853611d184452e06cdd99b4f2c88cdd3e91b9732
5
5
  SHA512:
6
- metadata.gz: 8211e731f5f7ae80289252136a14740a6fcbd3317d28f4844435c0bb333c17399280016effd638e4085a8f739cd0bc460114dd7bd20e82b3a9ffc9e19adeb5d0
7
- data.tar.gz: b0f064acfb8c13789e6fb4b249d415001434a95ef5385bbbbf0bde710f13e7439f362505d01d7764d9dae1953695892f14657214b831bdef5415f6cbfa369cbc
6
+ metadata.gz: 7b5906762f352786b4c17746935eb02e23efc9587922763cae2a14b74effab72c323328b1d7e8a9d5298a04b3b188108fa479d1c62e3933fd1e265b44c61e5a8
7
+ data.tar.gz: 8b38b1cd46d3b8e5f178764f769fd1ed805fa2b6e7c6f15808c18b2a7cb35c96101e9abfffcc350655110200205ee267f215a859afe0b36800a9e304072294a6
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- strong_ruby (0.0.1)
4
+ strong_ruby (0.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,5 +1,6 @@
1
1
  require "strong_ruby/version"
2
2
  require "strong_ruby/dependency"
3
+ require "strong_ruby/type_classes"
3
4
 
4
5
  autoload :AbstractClass, 'strong_ruby/abstract_class'
5
6
  autoload :StrongType, 'strong_ruby/strong_type'
@@ -0,0 +1,51 @@
1
+ class Or
2
+ def initialize(classes)
3
+ @classes = classes
4
+ end
5
+
6
+ def ===(val)
7
+ @classes.map{|c| c === val}.any?
8
+ end
9
+
10
+ def self.[](*classes)
11
+ new(classes)
12
+ end
13
+ end
14
+
15
+ class And
16
+ def initialize(classes)
17
+ @classes = classes
18
+ end
19
+
20
+ def ===(val)
21
+ @classes.map{|c| c === val}.all?
22
+ end
23
+
24
+ def self.[](*classes)
25
+ new(classes)
26
+ end
27
+ end
28
+
29
+ class Pos
30
+
31
+ def self.===(val)
32
+ if val.respond_to?(:>=)
33
+ val > 0
34
+ else
35
+ false
36
+ end
37
+ end
38
+
39
+ end
40
+
41
+ class Neg
42
+
43
+ def self.===(val)
44
+ if val.respond_to?(:<)
45
+ val < 0
46
+ else
47
+ false
48
+ end
49
+ end
50
+
51
+ end
@@ -1,3 +1,3 @@
1
1
  module StrongRuby
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe Or do
4
+ it 'returns true if matched one of some class' do
5
+ expect(Or[Fixnum, Float] === 1).to eq true
6
+ end
7
+
8
+ it 'returns true if matched one of some class' do
9
+ expect(Or[Fixnum, Float] === 2.5).to eq true
10
+ end
11
+
12
+ it 'returns false if no classes matched' do
13
+ expect(Or[Fixnum, Float] === '1').to eq false
14
+ end
15
+ end
16
+
17
+
18
+ describe Pos do
19
+ it 'returns true if matched value is positive' do
20
+ expect(Pos === 1).to eq true
21
+ end
22
+
23
+ it 'returns false if matched value is negative' do
24
+ expect(Pos === -1).to eq false
25
+ end
26
+
27
+ end
28
+
29
+ describe Neg do
30
+ it 'returns true if matched value is negative' do
31
+ expect(Neg === -1).to eq true
32
+ end
33
+
34
+ it 'returns false if matched value is positive' do
35
+ expect(Neg === 1).to eq false
36
+ end
37
+ end
38
+
39
+ describe And do
40
+ it 'returns true if matched all of classes' do
41
+ expect(And[Fixnum, Pos] === 1).to eq true
42
+ end
43
+
44
+ it 'returns false if matched not all of classes' do
45
+ expect(And[Fixnum, Pos] === -1).to eq false
46
+ end
47
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strong_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Gribovski
@@ -74,6 +74,7 @@ files:
74
74
  - lib/strong_ruby/dependency/resolver_binding.rb
75
75
  - lib/strong_ruby/strong_type.rb
76
76
  - lib/strong_ruby/strong_type/method_types.rb
77
+ - lib/strong_ruby/type_classes.rb
77
78
  - lib/strong_ruby/version.rb
78
79
  - spec/lib/strong_ruby/abstract_class_spec.rb
79
80
  - spec/lib/strong_ruby/dependency/resolver_binding_spec.rb
@@ -81,6 +82,7 @@ files:
81
82
  - spec/lib/strong_ruby/dependency_spec.rb
82
83
  - spec/lib/strong_ruby/strong_type/method_types_spec.rb
83
84
  - spec/lib/strong_ruby/strong_type_spec.rb
85
+ - spec/lib/strong_ruby/type_classes_spec.rb
84
86
  - spec/spec_helper.rb
85
87
  - strong_ruby.gemspec
86
88
  homepage: ''
@@ -114,4 +116,5 @@ test_files:
114
116
  - spec/lib/strong_ruby/dependency_spec.rb
115
117
  - spec/lib/strong_ruby/strong_type/method_types_spec.rb
116
118
  - spec/lib/strong_ruby/strong_type_spec.rb
119
+ - spec/lib/strong_ruby/type_classes_spec.rb
117
120
  - spec/spec_helper.rb