type 0.1.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.
@@ -0,0 +1,84 @@
1
+ # encoding: utf-8
2
+ require 'type'
3
+
4
+ Proc.const_set(:IDENTITY, ->(x) { x }) unless defined?(Proc::IDENTITY)
5
+
6
+ describe Type::Definition do
7
+ it { should be_an_instance_of Module }
8
+ context 'implementation' do
9
+ let(:implementation) do
10
+ Class.new { include Type::Definition }
11
+ end
12
+ subject { implementation }
13
+ it { should be <= Type::Definition }
14
+ context 'bare instance' do
15
+ let(:instance) { implementation.new }
16
+ subject { instance }
17
+ it { should be_a_kind_of Type::Definition }
18
+ it { should validate :anything }
19
+ it { should cast('a string').unchanged }
20
+ it { should respond_to :to_proc }
21
+ end
22
+ context 'liberal instance (validates anything)' do
23
+ let(:instance) do
24
+ implementation.new do
25
+ validate { true }
26
+ cast(&Proc::IDENTITY)
27
+ end
28
+ end
29
+ subject { instance }
30
+ it { should validate :anything }
31
+ it { should cast('a string').unchanged }
32
+ end
33
+ context 'conservative instance (validates :exact_match)' do
34
+ let(:instance) do
35
+ implementation.new do
36
+ validate { |x| x == :exact_match }
37
+ cast(&Proc::IDENTITY)
38
+ end
39
+ end
40
+ subject { instance }
41
+ it { should_not validate :random_input }
42
+ it { should validate :exact_match }
43
+ it { should_not cast('a string') }
44
+ it { should cast(:exact_match).unchanged }
45
+ end
46
+ context 'with inheritance (divisible by 5 inherits divisible by 3)' do
47
+ let(:parent_instance) do
48
+ implementation.new do
49
+ validate { |x| (x % 3).zero? }
50
+ end
51
+ end
52
+ let(:instance) do
53
+ implementation.new(nil, parent_instance) do
54
+ validate { |x| (x % 5).zero? }
55
+ end
56
+ end
57
+ subject { instance }
58
+ it { should_not validate 3 }
59
+ it { should_not validate 5 }
60
+ it { should validate 15 }
61
+ it { should validate 90 }
62
+ it { should cast(15).unchanged }
63
+ it { should cast(90).unchanged }
64
+ it { should_not cast(3) }
65
+ it { should_not cast(5) }
66
+ end
67
+ context '#to_proc' do
68
+ let(:instance) do
69
+ implementation.new do
70
+ cast { |x| String(x) }
71
+ validate { |x| x.kind_of?(String) }
72
+ end
73
+ end
74
+ subject { instance.to_proc }
75
+ it { should be_a_kind_of Proc }
76
+ context 'when called' do
77
+ it 'should cast the input' do
78
+ expect(instance.to_proc.call(:asdf)).to eq 'asdf'
79
+ expect([:foo, 3].map(&instance)).to eq ['foo', '3']
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'type/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'type'
9
+ spec.version = Type::VERSION
10
+ spec.authors = ['Ryan Biesemeyer']
11
+ spec.email = ['ryan@simplymeasured.com']
12
+ spec.summary = 'Type validation and Type casting'
13
+ spec.description = 'The `Type` gem provides tools for type-validation ' +
14
+ 'and type-casting, and is useful for ensuring ' +
15
+ 'well-formed messages are passed to external APIs/'
16
+ spec.homepage = 'https://github.com/simplymeasured/type-gem'
17
+ spec.license = 'Apache 2'
18
+
19
+ spec.files = `git ls-files`.split($/)
20
+ spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
21
+ spec.test_files = spec.files.grep(/^(test|spec|features)\//)
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.3'
25
+ spec.add_development_dependency 'rake'
26
+ spec.add_development_dependency 'rspec', '~> 2.14'
27
+ spec.add_development_dependency 'ruby-appraiser-rubocop'
28
+ spec.add_development_dependency 'ruby-appraiser-reek'
29
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: type
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ryan Biesemeyer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-01-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '2.14'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.14'
62
+ - !ruby/object:Gem::Dependency
63
+ name: ruby-appraiser-rubocop
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: ruby-appraiser-reek
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: The `Type` gem provides tools for type-validation and type-casting, and
95
+ is useful for ensuring well-formed messages are passed to external APIs/
96
+ email:
97
+ - ryan@simplymeasured.com
98
+ executables: []
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - .githooks/pre-commit/ruby-appraiser
103
+ - .gitignore
104
+ - CHANGELOG.md
105
+ - CONTRIBUTING.md
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - lib/type.rb
111
+ - lib/type/builtin.rb
112
+ - lib/type/definition.rb
113
+ - lib/type/definition/collection.rb
114
+ - lib/type/definition/collection/constrained.rb
115
+ - lib/type/definition/nilable.rb
116
+ - lib/type/definition/proxy.rb
117
+ - lib/type/definition/scalar.rb
118
+ - lib/type/error.rb
119
+ - lib/type/version.rb
120
+ - spec/type/builtin_spec.rb
121
+ - spec/type/definition_spec.rb
122
+ - type.gemspec
123
+ homepage: https://github.com/simplymeasured/type-gem
124
+ licenses:
125
+ - Apache 2
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ! '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 1.8.24
145
+ signing_key:
146
+ specification_version: 3
147
+ summary: Type validation and Type casting
148
+ test_files:
149
+ - spec/type/builtin_spec.rb
150
+ - spec/type/definition_spec.rb
151
+ has_rdoc: