axiom-types 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/.rspec +1 -0
  2. data/.travis.yml +11 -16
  3. data/Gemfile +5 -2
  4. data/Gemfile.devtools +19 -24
  5. data/Guardfile +18 -10
  6. data/README.md +5 -28
  7. data/axiom-types.gemspec +2 -3
  8. data/config/flay.yml +2 -2
  9. data/config/flog.yml +1 -1
  10. data/config/reek.yml +15 -13
  11. data/config/rubocop.yml +62 -0
  12. data/lib/axiom/types.rb +5 -3
  13. data/lib/axiom/types/boolean.rb +4 -2
  14. data/lib/axiom/types/collection.rb +5 -2
  15. data/lib/axiom/types/encodable.rb +1 -1
  16. data/lib/axiom/types/float.rb +3 -0
  17. data/lib/axiom/types/hash.rb +8 -3
  18. data/lib/axiom/types/length_comparable.rb +7 -4
  19. data/lib/axiom/types/numeric.rb +5 -0
  20. data/lib/axiom/types/object.rb +2 -2
  21. data/lib/axiom/types/support/infinity.rb +116 -0
  22. data/lib/axiom/types/support/options.rb +9 -18
  23. data/lib/axiom/types/time.rb +2 -2
  24. data/lib/axiom/types/type.rb +13 -9
  25. data/lib/axiom/types/value_comparable.rb +5 -2
  26. data/lib/axiom/types/version.rb +1 -1
  27. data/spec/unit/axiom/types/boolean/class_methods/infer_spec.rb +6 -0
  28. data/spec/unit/axiom/types/collection/class_methods/finalize_spec.rb +3 -3
  29. data/spec/unit/axiom/types/encodable/class_methods/extended_spec.rb +8 -7
  30. data/spec/unit/axiom/types/encodable/finalize_spec.rb +30 -8
  31. data/spec/unit/axiom/types/hash/class_methods/infer_spec.rb +17 -17
  32. data/spec/unit/axiom/types/infinity/class_methods/coerce_spec.rb +64 -0
  33. data/spec/unit/axiom/types/infinity/class_methods/spaceship_operator_spec.rb +67 -0
  34. data/spec/unit/axiom/types/infinity/class_methods/succ_spec.rb +11 -0
  35. data/spec/unit/axiom/types/length_comparable/class_methods/extended_spec.rb +17 -8
  36. data/spec/unit/axiom/types/negative_infinity/class_methods/spaceship_operator_spec.rb +67 -0
  37. data/spec/unit/axiom/types/object/class_methods/coercion_method_spec.rb +2 -2
  38. data/spec/unit/axiom/types/object/class_methods/infer_spec.rb +13 -1
  39. data/spec/unit/axiom/types/object/class_methods/primitive_spec.rb +4 -4
  40. data/spec/unit/axiom/types/options/accept_options_spec.rb +12 -4
  41. data/spec/unit/axiom/types/options/inherited_spec.rb +10 -36
  42. data/spec/unit/axiom/types/type/class_methods/constraint_spec.rb +6 -11
  43. data/spec/unit/axiom/types/type/class_methods/include_predicate_spec.rb +7 -7
  44. data/spec/unit/axiom/types/type/class_methods/includes_spec.rb +2 -2
  45. data/spec/unit/axiom/types/value_comparable/class_methods/extended_spec.rb +17 -8
  46. metadata +29 -31
  47. checksums.yaml +0 -7
@@ -20,8 +20,8 @@ describe Axiom::Types::Object, '.coercion_method' do
20
20
  it_should_behave_like 'a command method'
21
21
 
22
22
  it 'sets the coercion_method' do
23
- expect { subject }.to change { object.coercion_method }.
24
- from(coercion_method).to(symbol)
23
+ expect { subject }.to change { object.coercion_method }
24
+ .from(coercion_method).to(symbol)
25
25
  end
26
26
  end
27
27
  end
@@ -1,7 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require 'spec_helper'
4
- require 'backports/basic_object' unless defined?(::BasicObject)
5
4
 
6
5
  describe Axiom::Types::Object, '.infer' do
7
6
  subject { object.infer(arg) }
@@ -29,6 +28,13 @@ describe Axiom::Types::Object, '.infer' do
29
28
  Axiom::Types::Object.descendants.each do |descendant|
30
29
  primitive = descendant.primitive
31
30
 
31
+ context "when the argument is #{descendant}" do
32
+ let(:object) { descendant }
33
+ let(:arg) { object }
34
+
35
+ it { should be(object) }
36
+ end
37
+
32
38
  context "when the argument is ::#{primitive}" do
33
39
  let(:arg) { primitive }
34
40
 
@@ -44,6 +50,12 @@ describe Axiom::Types::Object, '.infer' do
44
50
  end
45
51
  end
46
52
 
53
+ context 'when the argument is an object instance' do
54
+ let(:arg) { ::Object.new }
55
+
56
+ it { should be_nil }
57
+ end
58
+
47
59
  context 'when the argument is nil' do
48
60
  let(:arg) { nil }
49
61
 
@@ -3,8 +3,8 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe Axiom::Types::Object, '.primitive' do
6
- let(:object) { Class.new(described_class) }
7
- let(:primitive) { RUBY_VERSION < '1.9' ? ::Object : ::BasicObject }
6
+ let(:object) { Class.new(described_class) }
7
+ let(:primitive) { ::BasicObject }
8
8
 
9
9
  context 'with no arguments' do
10
10
  subject { object.primitive }
@@ -20,8 +20,8 @@ describe Axiom::Types::Object, '.primitive' do
20
20
  it_should_behave_like 'a command method'
21
21
 
22
22
  it 'sets the primitive' do
23
- expect { subject }.to change { object.primitive.object_id }.
24
- from(primitive.object_id).to(klass.object_id)
23
+ expect { subject }.to change { object.primitive.object_id }
24
+ .from(primitive.object_id).to(klass.object_id)
25
25
  end
26
26
  end
27
27
  end
@@ -9,7 +9,7 @@ describe Axiom::Types::Options, '#accept_options' do
9
9
  let(:descendant) { Class.new(object) }
10
10
 
11
11
  context 'with valid options' do
12
- let(:new_options) { [ :primitive, :coerce_method ] }
12
+ let(:new_options) { [:primitive, :coerce_method] }
13
13
 
14
14
  it_should_behave_like 'a command method'
15
15
  it_should_behave_like 'an idempotent method'
@@ -20,10 +20,18 @@ describe Axiom::Types::Options, '#accept_options' do
20
20
  expect(object).to respond_to(*new_options)
21
21
  end
22
22
 
23
+ it 'defines the instance variables for the options' do
24
+ subject
25
+ expect(object.instance_variable_defined?(:@primitive)).to be(true)
26
+ expect(object.instance_variable_defined?(:@coerce_method)).to be(true)
27
+ end
28
+
23
29
  it 'adds methods to the object that can set a value' do
24
30
  subject
25
- object.primitive(::Symbol)
26
- expect(object.primitive).to be(::Symbol)
31
+ expect { object.primitive(Class) }
32
+ .to change(object, :primitive).from(nil).to(Class)
33
+ expect { object.coerce_method(:to_class) }
34
+ .to change(object, :coerce_method).from(nil).to(:to_class)
27
35
  end
28
36
 
29
37
  context 'with the descendant class' do
@@ -86,7 +94,7 @@ describe Axiom::Types::Options, '#accept_options' do
86
94
  end
87
95
 
88
96
  context 'with an option that conflicts with an existing method' do
89
- let(:new_options) { [ :name ] }
97
+ let(:new_options) { [:name] }
90
98
 
91
99
  specify do
92
100
  expect { subject }.to raise_error(
@@ -21,44 +21,18 @@ describe Axiom::Types::Options, '#inherited' do
21
21
  Class.new(object)
22
22
  end
23
23
 
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
34
-
35
- it 'sets the default value for the descendant' do
36
- subject
37
- expect(descendant.primitive).to be(::String)
38
- end
24
+ it 'delegates to the ancestor' do
25
+ ancestor.should_receive(:inherited).twice
26
+ subject
39
27
  end
40
28
 
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
29
+ it 'adds the accepted option to the descendant' do
30
+ subject
31
+ expect(descendant).to respond_to(:primitive, :coerce_method)
32
+ end
58
33
 
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
34
+ it 'sets the default value for the descendant' do
35
+ subject
36
+ expect(descendant.primitive).to be(::String)
63
37
  end
64
38
  end
@@ -5,13 +5,8 @@ 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
8
+ let(:callable) { ->(number) { number > 1 } }
9
+ let(:other) { ->(number) { number < 3 } }
15
10
 
16
11
  context 'with no arguments or block' do
17
12
  subject { object.constraint }
@@ -27,7 +22,7 @@ describe Axiom::Types::Type, '.constraint' do
27
22
 
28
23
  its(:constraint) { should respond_to(:call) }
29
24
 
30
- it 'creates a constraint that matches a number greater than 1' do
25
+ it 'creates a constraint that matches a number > 1' do
31
26
  expect(object).to include(1)
32
27
  expect(object).to include(2)
33
28
  expect(object).to include(3)
@@ -44,7 +39,7 @@ describe Axiom::Types::Type, '.constraint' do
44
39
 
45
40
  its(:constraint) { should respond_to(:call) }
46
41
 
47
- it 'creates a constraint that matches a number greater than 1 and less than 3' do
42
+ it 'creates a constraint that matches a number > 1 and < 3' do
48
43
  expect(object).to include(1)
49
44
  expect(object).to include(2)
50
45
  expect(object).to include(3)
@@ -63,7 +58,7 @@ describe Axiom::Types::Type, '.constraint' do
63
58
 
64
59
  its(:constraint) { should respond_to(:call) }
65
60
 
66
- it 'creates a constraint that matches a number greater than 1' do
61
+ it 'creates a constraint that matches a number > 1' do
67
62
  expect(object).to include(1)
68
63
  expect(object).to include(2)
69
64
  expect(object).to include(3)
@@ -80,7 +75,7 @@ describe Axiom::Types::Type, '.constraint' do
80
75
 
81
76
  its(:constraint) { should respond_to(:call) }
82
77
 
83
- it 'creates a constraint that matches a number greater than 1 and less than 3' do
78
+ it 'creates a constraint that matches a number > 1 and < 3' do
84
79
  expect(object).to include(1)
85
80
  expect(object).to include(2)
86
81
  expect(object).to include(3)
@@ -5,20 +5,20 @@ require 'spec_helper'
5
5
  describe Axiom::Types::Type, '.include?' do
6
6
  subject { object.include?(value) }
7
7
 
8
- let(:value) { Object.new }
8
+ let(:object) do
9
+ Class.new(described_class) do
10
+ constraint(->(object) { !object.nil? })
11
+ end
12
+ end
9
13
 
10
14
  context 'when the value matches the type constraint' do
11
- let(:object) { Class.new(described_class) }
15
+ let(:value) { Object.new }
12
16
 
13
17
  it { should be(true) }
14
18
  end
15
19
 
16
20
  context 'when the value does not match the type constraint' do
17
- let(:object) do
18
- Class.new(described_class) do
19
- constraint(proc { false })
20
- end
21
- end
21
+ let(:value) { nil }
22
22
 
23
23
  it { should be(false) }
24
24
  end
@@ -8,8 +8,8 @@ describe Axiom::Types::Type, '.includes' do
8
8
  let(:object) { Class.new(described_class) }
9
9
 
10
10
  context 'with a non-empty list' do
11
- let(:member) { Object.new }
12
- let(:members) { [ member, member ] }
11
+ let(:member) { Object.new }
12
+ let(:members) { [member, member] }
13
13
 
14
14
  it_should_behave_like 'a command method'
15
15
 
@@ -9,24 +9,33 @@ describe Axiom::Types::ValueComparable, '.extended' do
9
9
 
10
10
  it 'delegates to the ancestor' do
11
11
  # RSpec will reset stubbed methods after the example. A normal expectation
12
- # causes a SystemStackError to be thrown, so we stub it first so that RSpec
13
- # tracks the original method (if any), then we add our own stub that
14
- # actually works, and finally when the example finishes RSpec will reset the
15
- # Module#extended method back to it's original state.
12
+ # causes a SystemStackError to be thrown, so we stub it first so that
13
+ # RSpec tracks the original method (if any), then we add our own stub that
14
+ # actually works, and finally when the example finishes RSpec will reset
15
+ # the Module#extended method back to it's original state.
16
16
  Module.any_instance.stub(:extended).with(object)
17
17
 
18
18
  delegated_ancestor = false
19
+ Module.send(:undef_method, :extended)
19
20
  Module.send(:define_method, :extended) { |_| delegated_ancestor = true }
20
21
  expect { subject }.to change { delegated_ancestor }.from(false).to(true)
21
22
  end
22
23
 
23
24
  it 'adds minimum method' do
24
- expect { subject }.to change { object.respond_to?(:minimum) }.
25
- from(false).to(true)
25
+ expect { subject }.to change { object.respond_to?(:minimum) }
26
+ .from(false).to(true)
26
27
  end
27
28
 
28
29
  it 'adds maxumum method' do
29
- expect { subject }.to change { object.respond_to?(:maximum) }.
30
- from(false).to(true)
30
+ expect { subject }.to change { object.respond_to?(:maximum) }
31
+ .from(false).to(true)
32
+ end
33
+
34
+ it 'does not set the default minimum' do
35
+ expect(subject.minimum).to be_nil
36
+ end
37
+
38
+ it 'does not set the default maximum' do
39
+ expect(subject.maximum).to be_nil
31
40
  end
32
41
  end
metadata CHANGED
@@ -1,38 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: axiom-types
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Dan Kubb
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-06-27 00:00:00.000000000 Z
12
+ date: 2013-08-22 00:00:00.000000000 Z
12
13
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: backports
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ~>
18
- - !ruby/object:Gem::Version
19
- version: '3.3'
20
- - - '>='
21
- - !ruby/object:Gem::Version
22
- version: 3.3.2
23
- type: :runtime
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- version: '3.3'
30
- - - '>='
31
- - !ruby/object:Gem::Version
32
- version: 3.3.2
33
14
  - !ruby/object:Gem::Dependency
34
15
  name: descendants_tracker
35
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
36
18
  requirements:
37
19
  - - ~>
38
20
  - !ruby/object:Gem::Version
@@ -40,6 +22,7 @@ dependencies:
40
22
  type: :runtime
41
23
  prerelease: false
42
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
43
26
  requirements:
44
27
  - - ~>
45
28
  - !ruby/object:Gem::Version
@@ -47,35 +30,39 @@ dependencies:
47
30
  - !ruby/object:Gem::Dependency
48
31
  name: ice_nine
49
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
50
34
  requirements:
51
35
  - - ~>
52
36
  - !ruby/object:Gem::Version
53
- version: 0.8.0
37
+ version: '0.9'
54
38
  type: :runtime
55
39
  prerelease: false
56
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
57
42
  requirements:
58
43
  - - ~>
59
44
  - !ruby/object:Gem::Version
60
- version: 0.8.0
45
+ version: '0.9'
61
46
  - !ruby/object:Gem::Dependency
62
47
  name: bundler
63
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
64
50
  requirements:
65
51
  - - ~>
66
52
  - !ruby/object:Gem::Version
67
53
  version: '1.3'
68
- - - '>='
54
+ - - ! '>='
69
55
  - !ruby/object:Gem::Version
70
56
  version: 1.3.5
71
57
  type: :development
72
58
  prerelease: false
73
59
  version_requirements: !ruby/object:Gem::Requirement
60
+ none: false
74
61
  requirements:
75
62
  - - ~>
76
63
  - !ruby/object:Gem::Version
77
64
  version: '1.3'
78
- - - '>='
65
+ - - ! '>='
79
66
  - !ruby/object:Gem::Version
80
67
  version: 1.3.5
81
68
  description: Abstract types for logic programming
@@ -107,6 +94,7 @@ files:
107
94
  - config/mutant.yml
108
95
  - config/reek.yml
109
96
  - config/roodi.yml
97
+ - config/rubocop.yml
110
98
  - config/yardstick.yml
111
99
  - lib/axiom-types.rb
112
100
  - lib/axiom/types.rb
@@ -126,6 +114,7 @@ files:
126
114
  - lib/axiom/types/object.rb
127
115
  - lib/axiom/types/set.rb
128
116
  - lib/axiom/types/string.rb
117
+ - lib/axiom/types/support/infinity.rb
129
118
  - lib/axiom/types/support/options.rb
130
119
  - lib/axiom/types/symbol.rb
131
120
  - lib/axiom/types/time.rb
@@ -143,8 +132,12 @@ files:
143
132
  - spec/unit/axiom/types/encodable/finalize_spec.rb
144
133
  - spec/unit/axiom/types/hash/class_methods/finalize_spec.rb
145
134
  - spec/unit/axiom/types/hash/class_methods/infer_spec.rb
135
+ - spec/unit/axiom/types/infinity/class_methods/coerce_spec.rb
136
+ - spec/unit/axiom/types/infinity/class_methods/spaceship_operator_spec.rb
137
+ - spec/unit/axiom/types/infinity/class_methods/succ_spec.rb
146
138
  - spec/unit/axiom/types/length_comparable/class_methods/extended_spec.rb
147
139
  - spec/unit/axiom/types/length_comparable/finalize_spec.rb
140
+ - spec/unit/axiom/types/negative_infinity/class_methods/spaceship_operator_spec.rb
148
141
  - spec/unit/axiom/types/object/class_methods/coercion_method_spec.rb
149
142
  - spec/unit/axiom/types/object/class_methods/finalize_spec.rb
150
143
  - spec/unit/axiom/types/object/class_methods/infer_spec.rb
@@ -163,26 +156,27 @@ files:
163
156
  homepage: https://github.com/dkubb/axiom-types
164
157
  licenses:
165
158
  - MIT
166
- metadata: {}
167
159
  post_install_message:
168
160
  rdoc_options: []
169
161
  require_paths:
170
162
  - lib
171
163
  required_ruby_version: !ruby/object:Gem::Requirement
164
+ none: false
172
165
  requirements:
173
- - - '>='
166
+ - - ! '>='
174
167
  - !ruby/object:Gem::Version
175
168
  version: '0'
176
169
  required_rubygems_version: !ruby/object:Gem::Requirement
170
+ none: false
177
171
  requirements:
178
- - - '>='
172
+ - - ! '>='
179
173
  - !ruby/object:Gem::Version
180
174
  version: '0'
181
175
  requirements: []
182
176
  rubyforge_project:
183
- rubygems_version: 2.0.3
177
+ rubygems_version: 1.8.23
184
178
  signing_key:
185
- specification_version: 4
179
+ specification_version: 3
186
180
  summary: Define types with optional constraints for use within axiom and other libraries.
187
181
  test_files:
188
182
  - spec/unit/axiom/types/array/class_methods/infer_spec.rb
@@ -195,8 +189,12 @@ test_files:
195
189
  - spec/unit/axiom/types/encodable/finalize_spec.rb
196
190
  - spec/unit/axiom/types/hash/class_methods/finalize_spec.rb
197
191
  - spec/unit/axiom/types/hash/class_methods/infer_spec.rb
192
+ - spec/unit/axiom/types/infinity/class_methods/coerce_spec.rb
193
+ - spec/unit/axiom/types/infinity/class_methods/spaceship_operator_spec.rb
194
+ - spec/unit/axiom/types/infinity/class_methods/succ_spec.rb
198
195
  - spec/unit/axiom/types/length_comparable/class_methods/extended_spec.rb
199
196
  - spec/unit/axiom/types/length_comparable/finalize_spec.rb
197
+ - spec/unit/axiom/types/negative_infinity/class_methods/spaceship_operator_spec.rb
200
198
  - spec/unit/axiom/types/object/class_methods/coercion_method_spec.rb
201
199
  - spec/unit/axiom/types/object/class_methods/finalize_spec.rb
202
200
  - spec/unit/axiom/types/object/class_methods/infer_spec.rb