axiom-types 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.
Files changed (41) hide show
  1. checksums.yaml +6 -14
  2. data/.gitignore +1 -1
  3. data/.ruby-gemset +1 -0
  4. data/.travis.yml +2 -6
  5. data/CONTRIBUTING.md +11 -0
  6. data/Gemfile +1 -3
  7. data/Gemfile.devtools +17 -19
  8. data/README.md +1 -8
  9. data/Rakefile +0 -1
  10. data/TODO +0 -6
  11. data/axiom-types.gemspec +12 -13
  12. data/config/devtools.yml +2 -0
  13. data/config/flay.yml +1 -1
  14. data/config/flog.yml +1 -1
  15. data/config/reek.yml +67 -60
  16. data/lib/axiom/types.rb +26 -1
  17. data/lib/axiom/types/array.rb +12 -1
  18. data/lib/axiom/types/boolean.rb +17 -0
  19. data/lib/axiom/types/collection.rb +133 -0
  20. data/lib/axiom/types/hash.rb +80 -2
  21. data/lib/axiom/types/object.rb +34 -2
  22. data/lib/axiom/types/set.rb +12 -1
  23. data/lib/axiom/types/support/options.rb +13 -1
  24. data/lib/axiom/types/type.rb +17 -2
  25. data/lib/axiom/types/version.rb +1 -1
  26. data/spec/spec_helper.rb +14 -5
  27. data/spec/unit/axiom/types/array/class_methods/infer_spec.rb +99 -0
  28. data/spec/unit/axiom/types/boolean/class_methods/infer_spec.rb +33 -0
  29. data/spec/unit/axiom/types/class_methods/finalize_spec.rb +2 -7
  30. data/spec/unit/axiom/types/class_methods/infer_spec.rb +54 -0
  31. data/spec/unit/axiom/types/collection/class_methods/finalize_spec.rb +49 -0
  32. data/spec/unit/axiom/types/collection/class_methods/infer_spec.rb +111 -0
  33. data/spec/unit/axiom/types/hash/class_methods/infer_spec.rb +175 -0
  34. data/spec/unit/axiom/types/object/class_methods/infer_spec.rb +52 -0
  35. data/spec/unit/axiom/types/options/inherited_spec.rb +36 -10
  36. data/spec/unit/axiom/types/set/class_methods/infer_spec.rb +99 -0
  37. data/spec/unit/axiom/types/type/class_methods/constraint_spec.rb +66 -4
  38. data/spec/unit/axiom/types/type/class_methods/infer_spec.rb +25 -0
  39. data/spec/unit/axiom/types/type/class_methods/new_spec.rb +4 -0
  40. metadata +44 -44
  41. data/.rvmrc +0 -1
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'backports/basic_object' unless defined?(::BasicObject)
5
+
6
+ describe Axiom::Types::Object, '.infer' do
7
+ subject { object.infer(arg) }
8
+
9
+ let(:object) { described_class }
10
+
11
+ context 'when the argument is the type object' do
12
+ let(:arg) { object }
13
+
14
+ it { should be(object) }
15
+ end
16
+
17
+ context 'when the argument is ::BasicObject' do
18
+ let(:arg) { ::BasicObject }
19
+
20
+ it { should be(object) }
21
+ end
22
+
23
+ context 'when the argument is ::Object' do
24
+ let(:arg) { ::Object }
25
+
26
+ it { should be(object) }
27
+ end
28
+
29
+ Axiom::Types::Object.descendants.each do |descendant|
30
+ primitive = descendant.primitive
31
+
32
+ context "when the argument is ::#{primitive}" do
33
+ let(:arg) { primitive }
34
+
35
+ if primitive.instance_of?(::Module)
36
+ it 'does not match modules' do
37
+ should be_nil
38
+ end
39
+ else
40
+ it 'matches all classes' do
41
+ should be(object)
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ context 'when the argument is nil' do
48
+ let(:arg) { nil }
49
+
50
+ it { should be_nil }
51
+ end
52
+ end
@@ -21,18 +21,44 @@ describe Axiom::Types::Options, '#inherited' do
21
21
  Class.new(object)
22
22
  end
23
23
 
24
- it 'delegates to the ancestor' do
25
- ancestor.should_receive(:inherited).twice
26
- subject
27
- end
24
+ context 'when the option is not set' do
25
+ it 'delegates to the ancestor' do
26
+ ancestor.should_receive(:inherited).twice
27
+ subject
28
+ end
29
+
30
+ it 'adds the accepted option to the descendant' do
31
+ subject
32
+ expect(descendant).to respond_to(:primitive, :coerce_method)
33
+ end
28
34
 
29
- it 'adds the accepted option to the descendant' do
30
- subject
31
- expect(descendant).to respond_to(:primitive, :coerce_method)
35
+ it 'sets the default value for the descendant' do
36
+ subject
37
+ expect(descendant.primitive).to be(::String)
38
+ end
32
39
  end
33
40
 
34
- it 'sets the default value for the descendant' do
35
- subject
36
- expect(descendant.primitive).to be(::String)
41
+ context 'when the option is set' do
42
+ before do
43
+ def ancestor.inherited(descendant)
44
+ # set the option explicitly
45
+ descendant.instance_variable_set(:@primitive, ::Integer)
46
+ end
47
+ end
48
+
49
+ it 'delegates to the ancestor' do
50
+ ancestor.should_receive(:inherited).twice
51
+ subject
52
+ end
53
+
54
+ it 'adds the accepted option to the descendant' do
55
+ subject
56
+ expect(descendant).to respond_to(:primitive, :coerce_method)
57
+ end
58
+
59
+ it 'does not set the value for the descendant when not set' do
60
+ subject
61
+ expect(descendant.primitive).to be(::Integer)
62
+ end
37
63
  end
38
64
  end
@@ -0,0 +1,99 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Axiom::Types::Set, '.infer' do
6
+ subject { object.infer(arg) }
7
+
8
+ before do
9
+ object.finalize
10
+ end
11
+
12
+ context 'with Axiom::Types::Set' do
13
+ let(:object) { described_class }
14
+
15
+ context 'when the argument is the type object' do
16
+ let(:arg) { object }
17
+
18
+ it { should be(object) }
19
+ end
20
+
21
+ context 'when the argument is ::Set' do
22
+ let(:arg) { ::Set }
23
+
24
+ it { should be(object) }
25
+ end
26
+
27
+ context 'when the argument is an empty Set' do
28
+ let(:arg) { ::Set[] }
29
+
30
+ it { should be(object) }
31
+ end
32
+
33
+ context 'when the argument is an Set with a type' do
34
+ let(:arg) { ::Set[object] }
35
+
36
+ its(:ancestors) { should include(object) }
37
+
38
+ its(:primitive) { should be(object.primitive) }
39
+
40
+ its(:member_type) { should be(object) }
41
+ end
42
+
43
+ context 'when the argument is an Set with a primitive' do
44
+ let(:arg) { ::Set[::Set] }
45
+
46
+ its(:ancestors) { should include(object) }
47
+
48
+ its(:primitive) { should be(object.primitive) }
49
+
50
+ its(:member_type) { should be(object) }
51
+ end
52
+
53
+ context 'when the argument is nil' do
54
+ let(:arg) { nil }
55
+
56
+ it { should be_nil }
57
+ end
58
+ end
59
+
60
+ context 'with Axiom::Types::Set subclass' do
61
+ let(:object) { Class.new(described_class) }
62
+
63
+ context 'when the argument is the type object' do
64
+ let(:arg) { object }
65
+
66
+ it { should be(object) }
67
+ end
68
+
69
+ context 'when the argument is ::Set' do
70
+ let(:arg) { ::Set }
71
+
72
+ it { should be(object) }
73
+ end
74
+
75
+ context 'when the argument is an empty Set' do
76
+ let(:arg) { ::Set[] }
77
+
78
+ it { should be(object) }
79
+ end
80
+
81
+ context 'when the argument is an Set with a type' do
82
+ let(:arg) { ::Set[object] }
83
+
84
+ it { should be_nil }
85
+ end
86
+
87
+ context 'when the argument is an Set with a primitive' do
88
+ let(:arg) { ::Set[::Set] }
89
+
90
+ it { should be_nil }
91
+ end
92
+
93
+ context 'when the argument is nil' do
94
+ let(:arg) { nil }
95
+
96
+ it { should be_nil }
97
+ end
98
+ end
99
+ end
@@ -5,6 +5,14 @@ require 'spec_helper'
5
5
  describe Axiom::Types::Type, '.constraint' do
6
6
  let(:object) { Class.new(described_class) }
7
7
 
8
+ let(:callable) do
9
+ lambda { |number| number > 1 }
10
+ end
11
+
12
+ let(:other) do
13
+ lambda { |number| number < 3 }
14
+ end
15
+
8
16
  context 'with no arguments or block' do
9
17
  subject { object.constraint }
10
18
 
@@ -13,20 +21,74 @@ describe Axiom::Types::Type, '.constraint' do
13
21
  end
14
22
 
15
23
  context 'with a callable object' do
16
- subject { object.constraint(Contradiction) }
24
+ subject { object.constraint(callable) }
17
25
 
18
26
  it_should_behave_like 'a command method'
19
27
 
20
28
  its(:constraint) { should respond_to(:call) }
21
- its(:constraint) { should_not be(Tautology) }
29
+
30
+ it 'creates a constraint that matches a number greater than 1' do
31
+ expect(object).to include(1)
32
+ expect(object).to include(2)
33
+ expect(object).to include(3)
34
+ subject
35
+ expect(object).to_not include(1)
36
+ expect(object).to include(2)
37
+ expect(object).to include(3)
38
+ end
39
+
40
+ context 'with another constraint' do
41
+ subject { super().constraint(other) }
42
+
43
+ it_should_behave_like 'a command method'
44
+
45
+ its(:constraint) { should respond_to(:call) }
46
+
47
+ it 'creates a constraint that matches a number greater than 1 and less than 3' do
48
+ expect(object).to include(1)
49
+ expect(object).to include(2)
50
+ expect(object).to include(3)
51
+ subject
52
+ expect(object).to_not include(1)
53
+ expect(object).to include(2)
54
+ expect(object).to_not include(3)
55
+ end
56
+ end
22
57
  end
23
58
 
24
59
  context 'with a block' do
25
- subject { object.constraint { false } }
60
+ subject { object.constraint(&callable) }
26
61
 
27
62
  it_should_behave_like 'a command method'
28
63
 
29
64
  its(:constraint) { should respond_to(:call) }
30
- its(:constraint) { should_not be(Tautology) }
65
+
66
+ it 'creates a constraint that matches a number greater than 1' do
67
+ expect(object).to include(1)
68
+ expect(object).to include(2)
69
+ expect(object).to include(3)
70
+ subject
71
+ expect(object).to_not include(1)
72
+ expect(object).to include(2)
73
+ expect(object).to include(3)
74
+ end
75
+
76
+ context 'with another constraint' do
77
+ subject { super().constraint(&other) }
78
+
79
+ it_should_behave_like 'a command method'
80
+
81
+ its(:constraint) { should respond_to(:call) }
82
+
83
+ it 'creates a constraint that matches a number greater than 1 and less than 3' do
84
+ expect(object).to include(1)
85
+ expect(object).to include(2)
86
+ expect(object).to include(3)
87
+ subject
88
+ expect(object).to_not include(1)
89
+ expect(object).to include(2)
90
+ expect(object).to_not include(3)
91
+ end
92
+ end
31
93
  end
32
94
  end
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Axiom::Types::Type, '.infer' do
6
+ subject { object.infer(arg) }
7
+
8
+ let(:object) { described_class }
9
+
10
+ context 'when the argument is the type object' do
11
+ let(:arg) { object }
12
+
13
+ it { should be(object) }
14
+ end
15
+
16
+ Axiom::Types::Type.descendants.each do |descendant|
17
+ context "when the argument is #{descendant}" do
18
+ let(:arg) { descendant }
19
+
20
+ it 'does not match any other type' do
21
+ should be_nil
22
+ end
23
+ end
24
+ end
25
+ end
@@ -5,6 +5,10 @@ require 'spec_helper'
5
5
  describe Axiom::Types::Type, '.new' do
6
6
  let(:undefined) { Axiom::Types::Undefined }
7
7
 
8
+ before do
9
+ object.finalize
10
+ end
11
+
8
12
  context 'with no arguments' do
9
13
  subject { object.new }
10
14
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: axiom-types
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
  - Dan Kubb
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-17 00:00:00.000000000 Z
11
+ date: 2013-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backports
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '3.1'
20
- - - ! '>='
19
+ version: '3.3'
20
+ - - '>='
21
21
  - !ruby/object:Gem::Version
22
- version: 3.1.1
22
+ version: 3.3.2
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: '3.1'
30
- - - ! '>='
29
+ version: '3.3'
30
+ - - '>='
31
31
  - !ruby/object:Gem::Version
32
- version: 3.1.1
32
+ version: 3.3.2
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: descendants_tracker
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -50,56 +50,34 @@ dependencies:
50
50
  requirements:
51
51
  - - ~>
52
52
  - !ruby/object:Gem::Version
53
- version: 0.7.0
53
+ version: 0.8.0
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - ~>
59
59
  - !ruby/object:Gem::Version
60
- version: 0.7.0
60
+ version: 0.8.0
61
61
  - !ruby/object:Gem::Dependency
62
- name: rake
62
+ name: bundler
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - ~>
66
66
  - !ruby/object:Gem::Version
67
- version: 10.0.3
68
- type: :development
69
- prerelease: false
70
- version_requirements: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - ~>
73
- - !ruby/object:Gem::Version
74
- version: 10.0.3
75
- - !ruby/object:Gem::Dependency
76
- name: rspec
77
- requirement: !ruby/object:Gem::Requirement
78
- requirements:
79
- - - ~>
67
+ version: '1.3'
68
+ - - '>='
80
69
  - !ruby/object:Gem::Version
81
- version: 2.13.0
70
+ version: 1.3.5
82
71
  type: :development
83
72
  prerelease: false
84
73
  version_requirements: !ruby/object:Gem::Requirement
85
74
  requirements:
86
75
  - - ~>
87
76
  - !ruby/object:Gem::Version
88
- version: 2.13.0
89
- - !ruby/object:Gem::Dependency
90
- name: yard
91
- requirement: !ruby/object:Gem::Requirement
92
- requirements:
93
- - - ~>
94
- - !ruby/object:Gem::Version
95
- version: 0.8.5
96
- type: :development
97
- prerelease: false
98
- version_requirements: !ruby/object:Gem::Requirement
99
- requirements:
100
- - - ~>
77
+ version: '1.3'
78
+ - - '>='
101
79
  - !ruby/object:Gem::Version
102
- version: 0.8.5
80
+ version: 1.3.5
103
81
  description: Abstract types for logic programming
104
82
  email: dan.kubb@gmail.com
105
83
  executables: []
@@ -111,9 +89,10 @@ extra_rdoc_files:
111
89
  files:
112
90
  - .gitignore
113
91
  - .rspec
114
- - .rvmrc
92
+ - .ruby-gemset
115
93
  - .travis.yml
116
94
  - .yardopts
95
+ - CONTRIBUTING.md
117
96
  - Gemfile
118
97
  - Gemfile.devtools
119
98
  - Guardfile
@@ -122,6 +101,7 @@ files:
122
101
  - Rakefile
123
102
  - TODO
124
103
  - axiom-types.gemspec
104
+ - config/devtools.yml
125
105
  - config/flay.yml
126
106
  - config/flog.yml
127
107
  - config/mutant.yml
@@ -133,6 +113,7 @@ files:
133
113
  - lib/axiom/types/array.rb
134
114
  - lib/axiom/types/boolean.rb
135
115
  - lib/axiom/types/class.rb
116
+ - lib/axiom/types/collection.rb
136
117
  - lib/axiom/types/date.rb
137
118
  - lib/axiom/types/date_time.rb
138
119
  - lib/axiom/types/decimal.rb
@@ -152,26 +133,36 @@ files:
152
133
  - lib/axiom/types/value_comparable.rb
153
134
  - lib/axiom/types/version.rb
154
135
  - spec/spec_helper.rb
136
+ - spec/unit/axiom/types/array/class_methods/infer_spec.rb
137
+ - spec/unit/axiom/types/boolean/class_methods/infer_spec.rb
155
138
  - spec/unit/axiom/types/class_methods/finalize_spec.rb
139
+ - spec/unit/axiom/types/class_methods/infer_spec.rb
140
+ - spec/unit/axiom/types/collection/class_methods/finalize_spec.rb
141
+ - spec/unit/axiom/types/collection/class_methods/infer_spec.rb
156
142
  - spec/unit/axiom/types/encodable/class_methods/extended_spec.rb
157
143
  - spec/unit/axiom/types/encodable/finalize_spec.rb
158
144
  - spec/unit/axiom/types/hash/class_methods/finalize_spec.rb
145
+ - spec/unit/axiom/types/hash/class_methods/infer_spec.rb
159
146
  - spec/unit/axiom/types/length_comparable/class_methods/extended_spec.rb
160
147
  - spec/unit/axiom/types/length_comparable/finalize_spec.rb
161
148
  - spec/unit/axiom/types/object/class_methods/coercion_method_spec.rb
162
149
  - spec/unit/axiom/types/object/class_methods/finalize_spec.rb
150
+ - spec/unit/axiom/types/object/class_methods/infer_spec.rb
163
151
  - spec/unit/axiom/types/object/class_methods/primitive_spec.rb
164
152
  - spec/unit/axiom/types/options/accept_options_spec.rb
165
153
  - spec/unit/axiom/types/options/inherited_spec.rb
154
+ - spec/unit/axiom/types/set/class_methods/infer_spec.rb
166
155
  - spec/unit/axiom/types/type/class_methods/constraint_spec.rb
167
156
  - spec/unit/axiom/types/type/class_methods/finalize_spec.rb
168
157
  - spec/unit/axiom/types/type/class_methods/include_predicate_spec.rb
169
158
  - spec/unit/axiom/types/type/class_methods/includes_spec.rb
159
+ - spec/unit/axiom/types/type/class_methods/infer_spec.rb
170
160
  - spec/unit/axiom/types/type/class_methods/new_spec.rb
171
161
  - spec/unit/axiom/types/value_comparable/class_methods/extended_spec.rb
172
162
  - spec/unit/axiom/types/value_comparable/finalize_spec.rb
173
163
  homepage: https://github.com/dkubb/axiom-types
174
- licenses: []
164
+ licenses:
165
+ - MIT
175
166
  metadata: {}
176
167
  post_install_message:
177
168
  rdoc_options: []
@@ -179,12 +170,12 @@ require_paths:
179
170
  - lib
180
171
  required_ruby_version: !ruby/object:Gem::Requirement
181
172
  requirements:
182
- - - ! '>='
173
+ - - '>='
183
174
  - !ruby/object:Gem::Version
184
175
  version: '0'
185
176
  required_rubygems_version: !ruby/object:Gem::Requirement
186
177
  requirements:
187
- - - ! '>='
178
+ - - '>='
188
179
  - !ruby/object:Gem::Version
189
180
  version: '0'
190
181
  requirements: []
@@ -192,23 +183,32 @@ rubyforge_project:
192
183
  rubygems_version: 2.0.3
193
184
  signing_key:
194
185
  specification_version: 4
195
- summary: Abstract types for logic programming
186
+ summary: Define types with optional constraints for use within axiom and other libraries.
196
187
  test_files:
188
+ - spec/unit/axiom/types/array/class_methods/infer_spec.rb
189
+ - spec/unit/axiom/types/boolean/class_methods/infer_spec.rb
197
190
  - spec/unit/axiom/types/class_methods/finalize_spec.rb
191
+ - spec/unit/axiom/types/class_methods/infer_spec.rb
192
+ - spec/unit/axiom/types/collection/class_methods/finalize_spec.rb
193
+ - spec/unit/axiom/types/collection/class_methods/infer_spec.rb
198
194
  - spec/unit/axiom/types/encodable/class_methods/extended_spec.rb
199
195
  - spec/unit/axiom/types/encodable/finalize_spec.rb
200
196
  - spec/unit/axiom/types/hash/class_methods/finalize_spec.rb
197
+ - spec/unit/axiom/types/hash/class_methods/infer_spec.rb
201
198
  - spec/unit/axiom/types/length_comparable/class_methods/extended_spec.rb
202
199
  - spec/unit/axiom/types/length_comparable/finalize_spec.rb
203
200
  - spec/unit/axiom/types/object/class_methods/coercion_method_spec.rb
204
201
  - spec/unit/axiom/types/object/class_methods/finalize_spec.rb
202
+ - spec/unit/axiom/types/object/class_methods/infer_spec.rb
205
203
  - spec/unit/axiom/types/object/class_methods/primitive_spec.rb
206
204
  - spec/unit/axiom/types/options/accept_options_spec.rb
207
205
  - spec/unit/axiom/types/options/inherited_spec.rb
206
+ - spec/unit/axiom/types/set/class_methods/infer_spec.rb
208
207
  - spec/unit/axiom/types/type/class_methods/constraint_spec.rb
209
208
  - spec/unit/axiom/types/type/class_methods/finalize_spec.rb
210
209
  - spec/unit/axiom/types/type/class_methods/include_predicate_spec.rb
211
210
  - spec/unit/axiom/types/type/class_methods/includes_spec.rb
211
+ - spec/unit/axiom/types/type/class_methods/infer_spec.rb
212
212
  - spec/unit/axiom/types/type/class_methods/new_spec.rb
213
213
  - spec/unit/axiom/types/value_comparable/class_methods/extended_spec.rb
214
214
  - spec/unit/axiom/types/value_comparable/finalize_spec.rb