axiom-types 0.0.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.
Files changed (63) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +37 -0
  3. data/.rspec +4 -0
  4. data/.rvmrc +1 -0
  5. data/.travis.yml +35 -0
  6. data/.yardopts +4 -0
  7. data/Gemfile +10 -0
  8. data/Gemfile.devtools +62 -0
  9. data/Guardfile +24 -0
  10. data/LICENSE +20 -0
  11. data/README.md +76 -0
  12. data/Rakefile +6 -0
  13. data/TODO +25 -0
  14. data/axiom-types.gemspec +26 -0
  15. data/config/flay.yml +3 -0
  16. data/config/flog.yml +2 -0
  17. data/config/mutant.yml +3 -0
  18. data/config/reek.yml +100 -0
  19. data/config/roodi.yml +16 -0
  20. data/config/yardstick.yml +2 -0
  21. data/lib/axiom-types.rb +3 -0
  22. data/lib/axiom/types.rb +65 -0
  23. data/lib/axiom/types/array.rb +13 -0
  24. data/lib/axiom/types/boolean.rb +14 -0
  25. data/lib/axiom/types/class.rb +13 -0
  26. data/lib/axiom/types/date.rb +18 -0
  27. data/lib/axiom/types/date_time.rb +21 -0
  28. data/lib/axiom/types/decimal.rb +13 -0
  29. data/lib/axiom/types/encodable.rb +75 -0
  30. data/lib/axiom/types/float.rb +13 -0
  31. data/lib/axiom/types/hash.rb +45 -0
  32. data/lib/axiom/types/integer.rb +13 -0
  33. data/lib/axiom/types/length_comparable.rb +51 -0
  34. data/lib/axiom/types/numeric.rb +13 -0
  35. data/lib/axiom/types/object.rb +36 -0
  36. data/lib/axiom/types/set.rb +13 -0
  37. data/lib/axiom/types/string.rb +18 -0
  38. data/lib/axiom/types/support/options.rb +129 -0
  39. data/lib/axiom/types/symbol.rb +18 -0
  40. data/lib/axiom/types/time.rb +22 -0
  41. data/lib/axiom/types/type.rb +136 -0
  42. data/lib/axiom/types/value_comparable.rb +49 -0
  43. data/lib/axiom/types/version.rb +10 -0
  44. data/spec/spec_helper.rb +37 -0
  45. data/spec/unit/axiom/types/class_methods/finalize_spec.rb +22 -0
  46. data/spec/unit/axiom/types/encodable/class_methods/extended_spec.rb +31 -0
  47. data/spec/unit/axiom/types/encodable/finalize_spec.rb +55 -0
  48. data/spec/unit/axiom/types/hash/class_methods/finalize_spec.rb +55 -0
  49. data/spec/unit/axiom/types/length_comparable/class_methods/extended_spec.rb +32 -0
  50. data/spec/unit/axiom/types/length_comparable/finalize_spec.rb +32 -0
  51. data/spec/unit/axiom/types/object/class_methods/coercion_method_spec.rb +27 -0
  52. data/spec/unit/axiom/types/object/class_methods/finalize_spec.rb +29 -0
  53. data/spec/unit/axiom/types/object/class_methods/primitive_spec.rb +27 -0
  54. data/spec/unit/axiom/types/options/accept_options_spec.rb +98 -0
  55. data/spec/unit/axiom/types/options/inherited_spec.rb +38 -0
  56. data/spec/unit/axiom/types/type/class_methods/constraint_spec.rb +32 -0
  57. data/spec/unit/axiom/types/type/class_methods/finalize_spec.rb +20 -0
  58. data/spec/unit/axiom/types/type/class_methods/include_predicate_spec.rb +25 -0
  59. data/spec/unit/axiom/types/type/class_methods/includes_spec.rb +45 -0
  60. data/spec/unit/axiom/types/type/class_methods/new_spec.rb +79 -0
  61. data/spec/unit/axiom/types/value_comparable/class_methods/extended_spec.rb +32 -0
  62. data/spec/unit/axiom/types/value_comparable/finalize_spec.rb +32 -0
  63. metadata +215 -0
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Axiom::Types::Type, '.finalize' do
6
+ subject { object.finalize }
7
+
8
+ let(:object) do
9
+ Class.new(described_class) do
10
+ constraint Tautology
11
+ end
12
+ end
13
+
14
+ it_should_behave_like 'a command method'
15
+ it_should_behave_like 'an idempotent method'
16
+
17
+ it { should be_frozen }
18
+
19
+ its(:constraint) { should be_frozen }
20
+ end
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Axiom::Types::Type, '.include?' do
6
+ subject { object.include?(value) }
7
+
8
+ let(:value) { Object.new }
9
+
10
+ context 'when the value matches the type constraint' do
11
+ let(:object) { Class.new(described_class) }
12
+
13
+ it { should be(true) }
14
+ end
15
+
16
+ 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
22
+
23
+ it { should be(false) }
24
+ end
25
+ end
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Axiom::Types::Type, '.includes' do
6
+ subject { object.includes(*members) }
7
+
8
+ let(:object) { Class.new(described_class) }
9
+
10
+ context 'with a non-empty list' do
11
+ let(:member) { Object.new }
12
+ let(:members) { [ member, member ] }
13
+
14
+ it_should_behave_like 'a command method'
15
+
16
+ it 'adds a constraint that returns true for a valid member' do
17
+ should include(member)
18
+ end
19
+
20
+ it 'adds a constraint that returns false for an invalid member' do
21
+ should_not include(nil)
22
+ end
23
+
24
+ it 'freezes the members' do
25
+ expect { subject }.to change(member, :frozen?).from(false).to(true)
26
+ end
27
+
28
+ it 'removes duplicate members' do
29
+ member.should_receive(:frozen?).and_return(true)
30
+ member.should_receive(:hash).exactly(3).times.and_return(1)
31
+ subject
32
+ expect(object).to include(member)
33
+ end
34
+ end
35
+
36
+ context 'with an empty set' do
37
+ let(:members) { [] }
38
+
39
+ it_should_behave_like 'a command method'
40
+
41
+ it 'adds a constraint that returns false' do
42
+ should_not include(Object.new)
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,79 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Axiom::Types::Type, '.new' do
6
+ let(:undefined) { Axiom::Types::Undefined }
7
+
8
+ context 'with no arguments' do
9
+ subject { object.new }
10
+
11
+ let(:object) { described_class }
12
+
13
+ it { should be_instance_of(Class) }
14
+
15
+ it { should be_frozen }
16
+
17
+ its(:ancestors) { should include(object) }
18
+
19
+ it 'has no constraints' do
20
+ should include(undefined)
21
+ end
22
+ end
23
+
24
+ context 'with a constraint' do
25
+ subject { object.new(proc { false }) }
26
+
27
+ let(:object) { described_class }
28
+
29
+ it { should be_instance_of(Class) }
30
+
31
+ it { should be_frozen }
32
+
33
+ its(:ancestors) { should include(object) }
34
+
35
+ it 'has constraints' do
36
+ should_not include(undefined)
37
+ end
38
+ end
39
+
40
+ context 'with a block' do
41
+ subject do
42
+ object.new do
43
+ constraint { false }
44
+ end
45
+ end
46
+
47
+ let(:object) { described_class }
48
+
49
+ it { should be_instance_of(Class) }
50
+
51
+ it { should be_frozen }
52
+
53
+ its(:ancestors) { should include(object) }
54
+
55
+ it 'has constraints' do
56
+ should_not include(undefined)
57
+ end
58
+ end
59
+
60
+ context 'with a constraint and block' do
61
+ subject do
62
+ object.new(proc { false }) do
63
+ constraint { false }
64
+ end
65
+ end
66
+
67
+ let(:object) { described_class }
68
+
69
+ it { should be_instance_of(Class) }
70
+
71
+ it { should be_frozen }
72
+
73
+ its(:ancestors) { should include(object) }
74
+
75
+ it 'has constraints' do
76
+ should_not include(undefined)
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Axiom::Types::ValueComparable, '.extended' do
6
+ subject { object.extend(described_class) }
7
+
8
+ let(:object) { Class.new(Axiom::Types::Type) }
9
+
10
+ it 'delegates to the ancestor' do
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.
16
+ Module.any_instance.stub(:extended).with(object)
17
+
18
+ delegated_ancestor = false
19
+ Module.send(:define_method, :extended) { |_| delegated_ancestor = true }
20
+ expect { subject }.to change { delegated_ancestor }.from(false).to(true)
21
+ end
22
+
23
+ it 'adds minimum method' do
24
+ expect { subject }.to change { object.respond_to?(:minimum) }.
25
+ from(false).to(true)
26
+ end
27
+
28
+ it 'adds maxumum method' do
29
+ expect { subject }.to change { object.respond_to?(:maximum) }.
30
+ from(false).to(true)
31
+ end
32
+ end
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Axiom::Types::ValueComparable, '#finalize' do
6
+ subject { object.finalize }
7
+
8
+ let(:object) do
9
+ Class.new(Axiom::Types::Type) do
10
+ extend Axiom::Types::ValueComparable
11
+ minimum 1
12
+ maximum 2
13
+ end
14
+ end
15
+
16
+ it_should_behave_like 'a command method'
17
+ it_should_behave_like 'an idempotent method'
18
+
19
+ it { should be_frozen }
20
+
21
+ its(:constraint) { should be_frozen }
22
+
23
+ it 'adds a constraint that returns true for a value within range' do
24
+ should include(1)
25
+ should include(2)
26
+ end
27
+
28
+ it 'adds a constraint that returns false for a value not within range' do
29
+ should_not include(0)
30
+ should_not include(3)
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,215 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: axiom-types
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dan Kubb
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-03-17 00:00:00.000000000 Z
12
+ 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.1'
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 3.1.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.1'
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 3.1.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: descendants_tracker
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ version: 0.0.1
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 0.0.1
47
+ - !ruby/object:Gem::Dependency
48
+ name: ice_nine
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.7.0
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ version: 0.7.0
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ~>
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
+ - - ~>
80
+ - !ruby/object:Gem::Version
81
+ version: 2.13.0
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ~>
87
+ - !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
+ - - ~>
101
+ - !ruby/object:Gem::Version
102
+ version: 0.8.5
103
+ description: Abstract types for logic programming
104
+ email: dan.kubb@gmail.com
105
+ executables: []
106
+ extensions: []
107
+ extra_rdoc_files:
108
+ - LICENSE
109
+ - README.md
110
+ - TODO
111
+ files:
112
+ - .gitignore
113
+ - .rspec
114
+ - .rvmrc
115
+ - .travis.yml
116
+ - .yardopts
117
+ - Gemfile
118
+ - Gemfile.devtools
119
+ - Guardfile
120
+ - LICENSE
121
+ - README.md
122
+ - Rakefile
123
+ - TODO
124
+ - axiom-types.gemspec
125
+ - config/flay.yml
126
+ - config/flog.yml
127
+ - config/mutant.yml
128
+ - config/reek.yml
129
+ - config/roodi.yml
130
+ - config/yardstick.yml
131
+ - lib/axiom-types.rb
132
+ - lib/axiom/types.rb
133
+ - lib/axiom/types/array.rb
134
+ - lib/axiom/types/boolean.rb
135
+ - lib/axiom/types/class.rb
136
+ - lib/axiom/types/date.rb
137
+ - lib/axiom/types/date_time.rb
138
+ - lib/axiom/types/decimal.rb
139
+ - lib/axiom/types/encodable.rb
140
+ - lib/axiom/types/float.rb
141
+ - lib/axiom/types/hash.rb
142
+ - lib/axiom/types/integer.rb
143
+ - lib/axiom/types/length_comparable.rb
144
+ - lib/axiom/types/numeric.rb
145
+ - lib/axiom/types/object.rb
146
+ - lib/axiom/types/set.rb
147
+ - lib/axiom/types/string.rb
148
+ - lib/axiom/types/support/options.rb
149
+ - lib/axiom/types/symbol.rb
150
+ - lib/axiom/types/time.rb
151
+ - lib/axiom/types/type.rb
152
+ - lib/axiom/types/value_comparable.rb
153
+ - lib/axiom/types/version.rb
154
+ - spec/spec_helper.rb
155
+ - spec/unit/axiom/types/class_methods/finalize_spec.rb
156
+ - spec/unit/axiom/types/encodable/class_methods/extended_spec.rb
157
+ - spec/unit/axiom/types/encodable/finalize_spec.rb
158
+ - spec/unit/axiom/types/hash/class_methods/finalize_spec.rb
159
+ - spec/unit/axiom/types/length_comparable/class_methods/extended_spec.rb
160
+ - spec/unit/axiom/types/length_comparable/finalize_spec.rb
161
+ - spec/unit/axiom/types/object/class_methods/coercion_method_spec.rb
162
+ - spec/unit/axiom/types/object/class_methods/finalize_spec.rb
163
+ - spec/unit/axiom/types/object/class_methods/primitive_spec.rb
164
+ - spec/unit/axiom/types/options/accept_options_spec.rb
165
+ - spec/unit/axiom/types/options/inherited_spec.rb
166
+ - spec/unit/axiom/types/type/class_methods/constraint_spec.rb
167
+ - spec/unit/axiom/types/type/class_methods/finalize_spec.rb
168
+ - spec/unit/axiom/types/type/class_methods/include_predicate_spec.rb
169
+ - spec/unit/axiom/types/type/class_methods/includes_spec.rb
170
+ - spec/unit/axiom/types/type/class_methods/new_spec.rb
171
+ - spec/unit/axiom/types/value_comparable/class_methods/extended_spec.rb
172
+ - spec/unit/axiom/types/value_comparable/finalize_spec.rb
173
+ homepage: https://github.com/dkubb/axiom-types
174
+ licenses: []
175
+ metadata: {}
176
+ post_install_message:
177
+ rdoc_options: []
178
+ require_paths:
179
+ - lib
180
+ required_ruby_version: !ruby/object:Gem::Requirement
181
+ requirements:
182
+ - - ! '>='
183
+ - !ruby/object:Gem::Version
184
+ version: '0'
185
+ required_rubygems_version: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ requirements: []
191
+ rubyforge_project:
192
+ rubygems_version: 2.0.3
193
+ signing_key:
194
+ specification_version: 4
195
+ summary: Abstract types for logic programming
196
+ test_files:
197
+ - spec/unit/axiom/types/class_methods/finalize_spec.rb
198
+ - spec/unit/axiom/types/encodable/class_methods/extended_spec.rb
199
+ - spec/unit/axiom/types/encodable/finalize_spec.rb
200
+ - spec/unit/axiom/types/hash/class_methods/finalize_spec.rb
201
+ - spec/unit/axiom/types/length_comparable/class_methods/extended_spec.rb
202
+ - spec/unit/axiom/types/length_comparable/finalize_spec.rb
203
+ - spec/unit/axiom/types/object/class_methods/coercion_method_spec.rb
204
+ - spec/unit/axiom/types/object/class_methods/finalize_spec.rb
205
+ - spec/unit/axiom/types/object/class_methods/primitive_spec.rb
206
+ - spec/unit/axiom/types/options/accept_options_spec.rb
207
+ - spec/unit/axiom/types/options/inherited_spec.rb
208
+ - spec/unit/axiom/types/type/class_methods/constraint_spec.rb
209
+ - spec/unit/axiom/types/type/class_methods/finalize_spec.rb
210
+ - spec/unit/axiom/types/type/class_methods/include_predicate_spec.rb
211
+ - spec/unit/axiom/types/type/class_methods/includes_spec.rb
212
+ - spec/unit/axiom/types/type/class_methods/new_spec.rb
213
+ - spec/unit/axiom/types/value_comparable/class_methods/extended_spec.rb
214
+ - spec/unit/axiom/types/value_comparable/finalize_spec.rb
215
+ has_rdoc: