axiom-types 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CONTRIBUTING.md +1 -2
- data/README.md +4 -8
- data/axiom-types.gemspec +2 -2
- data/config/flay.yml +1 -1
- data/lib/axiom/types/collection.rb +1 -2
- data/lib/axiom/types/object.rb +2 -2
- data/lib/axiom/types/support/infinity.rb +1 -1
- data/lib/axiom/types/version.rb +1 -1
- data/spec/unit/axiom/types/collection/class_methods/infer_spec.rb +20 -4
- data/spec/unit/axiom/types/object/class_methods/infer_spec.rb +79 -37
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OTk1ZjkwNjg3MjZkNzIwNmI5Yzc4YmNlMTQ5NjNlNDhkNWI5Y2EyZg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NTllNTE2NWUzNDUwNGJlODJmODk2NzBiZmM1YmIwYWZlNGM3YzZjNw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YjJkYjk1OWQ1MmQ5NjVkZWU4Y2FhZjVlY2VlZGFhNzMzYWE3MWZkMjc0MGY4
|
10
|
+
YmQzYjNiYmIzOGYzMzdjYzUwOTg5NmU5ZTBlN2ZjYjg3MWMxMWYzNTE4ZjA3
|
11
|
+
ZTQ0ZGI3N2YyM2ZjZGQ4MmQ2ZTA2ZTgwMTA3NmNiZjcxMTYyMTQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MGQwZmUxMDZhNjhjYWFhNTQ0NjY0ODQ2OGJmMDAwMzI0M2UwMDQ0ODg4OGRm
|
14
|
+
MzA0ZTkxYjZjNWJkYjMyNjBhZmFkMzE2Yzc4YjA4Zjk0ODI0OGQ3OTcwNjBh
|
15
|
+
OTIzZGRhODBjZjdlOWJjYTY2YTViYTVkMzY3ZmEyOThmMGU1YTE=
|
data/CONTRIBUTING.md
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
Contributing
|
2
|
-
------------
|
1
|
+
# Contributing
|
3
2
|
|
4
3
|
* If you want your code merged into the mainline, please discuss the proposed changes with me before doing any work on it. This library is still in early development, and the direction it is going may not always be clear. Some features may not be appropriate yet, may need to be deferred until later when the foundation for them is laid, or may be more applicable in a plugin.
|
5
4
|
* Fork the project.
|
data/README.md
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
axiom-types
|
2
|
-
===========
|
1
|
+
# axiom-types
|
3
2
|
|
4
3
|
Define types with optional constraints for use within axiom and other libraries.
|
5
4
|
|
@@ -15,8 +14,7 @@ Define types with optional constraints for use within axiom and other libraries.
|
|
15
14
|
[codeclimate]: https://codeclimate.com/github/dkubb/axiom-types
|
16
15
|
[coveralls]: https://coveralls.io/r/dkubb/axiom-types
|
17
16
|
|
18
|
-
Examples
|
19
|
-
--------
|
17
|
+
## Examples
|
20
18
|
|
21
19
|
```ruby
|
22
20
|
# Setup constraints for all defined types
|
@@ -35,12 +33,10 @@ Name.include?('') # => false
|
|
35
33
|
Name.include?('a' * 31) # => false
|
36
34
|
```
|
37
35
|
|
38
|
-
Contributing
|
39
|
-
-------------
|
36
|
+
## Contributing
|
40
37
|
|
41
38
|
See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
|
42
39
|
|
43
|
-
Copyright
|
44
|
-
---------
|
40
|
+
## Copyright
|
45
41
|
|
46
42
|
Copyright © 2013 Dan Kubb. See LICENSE for details.
|
data/axiom-types.gemspec
CHANGED
@@ -10,12 +10,12 @@ Gem::Specification.new do |gem|
|
|
10
10
|
gem.description = 'Abstract types for logic programming'
|
11
11
|
gem.summary = 'Define types with optional constraints for use within axiom and other libraries.'
|
12
12
|
gem.homepage = 'https://github.com/dkubb/axiom-types'
|
13
|
-
gem.
|
13
|
+
gem.license = 'MIT'
|
14
14
|
|
15
15
|
gem.require_paths = %w[lib]
|
16
16
|
gem.files = `git ls-files`.split($/)
|
17
17
|
gem.test_files = `git ls-files -- spec/unit`.split($/)
|
18
|
-
gem.extra_rdoc_files = %w[LICENSE README.md TODO]
|
18
|
+
gem.extra_rdoc_files = %w[LICENSE README.md CONTRIBUTING.md TODO]
|
19
19
|
|
20
20
|
gem.add_dependency('descendants_tracker', '~> 0.0.1')
|
21
21
|
gem.add_dependency('ice_nine', '~> 0.9')
|
data/config/flay.yml
CHANGED
@@ -84,8 +84,7 @@ module Axiom
|
|
84
84
|
#
|
85
85
|
# @api private
|
86
86
|
def self.infer_from_primitive_instance(object)
|
87
|
-
|
88
|
-
member_type = Types.infer(member) || Object
|
87
|
+
member_type = Types.infer(object.first) || Object
|
89
88
|
infer_from(member_type) || new_from(member_type)
|
90
89
|
end
|
91
90
|
private_class_method :infer_from_primitive_instance
|
data/lib/axiom/types/object.rb
CHANGED
@@ -60,8 +60,8 @@ module Axiom
|
|
60
60
|
#
|
61
61
|
# @api private
|
62
62
|
def self.match_primitive?(object)
|
63
|
-
object
|
64
|
-
object.ancestors.include?(primitive)
|
63
|
+
Module === object &&
|
64
|
+
(equal?(Object) || object.ancestors.include?(primitive))
|
65
65
|
end
|
66
66
|
private_class_method :match_primitive?
|
67
67
|
|
data/lib/axiom/types/version.rb
CHANGED
@@ -9,10 +9,20 @@ describe Axiom::Types::Collection, '.infer' do
|
|
9
9
|
object.finalize
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
context 'with the type' 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 ::Enumerable' do
|
22
|
+
let(:arg) { ::Enumerable }
|
23
|
+
|
24
|
+
it { should be(object) }
|
25
|
+
end
|
16
26
|
end
|
17
27
|
|
18
28
|
context 'with a base class' do
|
@@ -26,6 +36,12 @@ describe Axiom::Types::Collection, '.infer' do
|
|
26
36
|
end
|
27
37
|
end
|
28
38
|
|
39
|
+
before do
|
40
|
+
# Initialize a custom type that will be used if the class lookup does not
|
41
|
+
# restrict matching to only types with an Object member_type
|
42
|
+
Axiom::Types.infer(SortedSet[Float])
|
43
|
+
end
|
44
|
+
|
29
45
|
context 'when the argument is the type object' do
|
30
46
|
let(:arg) { object }
|
31
47
|
|
@@ -5,60 +5,102 @@ require 'spec_helper'
|
|
5
5
|
describe Axiom::Types::Object, '.infer' do
|
6
6
|
subject { object.infer(arg) }
|
7
7
|
|
8
|
-
|
8
|
+
context 'with the type' do
|
9
|
+
let(:object) { described_class }
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
context 'when the argument is the type object' do
|
12
|
+
let(:arg) { object }
|
12
13
|
|
13
|
-
|
14
|
-
|
14
|
+
it { should be(object) }
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
17
|
+
context 'when the argument is ::BasicObject' do
|
18
|
+
let(:arg) { ::BasicObject }
|
18
19
|
|
19
|
-
|
20
|
-
|
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
|
21
28
|
|
22
|
-
|
23
|
-
|
29
|
+
Axiom::Types::Object.descendants.each do |descendant|
|
30
|
+
primitive = descendant.primitive
|
31
|
+
|
32
|
+
context "when the argument is #{descendant}" do
|
33
|
+
let(:object) { descendant }
|
34
|
+
let(:arg) { object }
|
35
|
+
|
36
|
+
it { should be(object) }
|
37
|
+
end
|
38
|
+
|
39
|
+
context "when the argument is ::#{primitive}" do
|
40
|
+
let(:arg) { primitive }
|
41
|
+
|
42
|
+
it { should be(object) }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'when the argument is an ::Object instance' do
|
47
|
+
let(:arg) { ::Object.new }
|
48
|
+
|
49
|
+
it { should be_nil }
|
50
|
+
end
|
24
51
|
|
25
|
-
|
52
|
+
context 'when the argument is nil' do
|
53
|
+
let(:arg) { nil }
|
54
|
+
|
55
|
+
it { should be_nil }
|
56
|
+
end
|
26
57
|
end
|
27
58
|
|
28
|
-
|
29
|
-
|
59
|
+
context 'with a subclass' do
|
60
|
+
let(:object) do
|
61
|
+
described_class.new { primitive ::Struct }
|
62
|
+
end
|
30
63
|
|
31
|
-
context
|
32
|
-
let(:
|
33
|
-
let(:arg) { object }
|
64
|
+
context 'when the argument is the type object' do
|
65
|
+
let(:arg) { object }
|
34
66
|
|
35
67
|
it { should be(object) }
|
36
68
|
end
|
37
69
|
|
38
|
-
context
|
39
|
-
let(:arg) {
|
40
|
-
|
41
|
-
|
42
|
-
it 'does not match modules' do
|
43
|
-
should be_nil
|
44
|
-
end
|
45
|
-
else
|
46
|
-
it 'matches all classes' do
|
47
|
-
should be(object)
|
48
|
-
end
|
49
|
-
end
|
70
|
+
context 'when the argument is ::BasicObject' do
|
71
|
+
let(:arg) { ::BasicObject }
|
72
|
+
|
73
|
+
it { should be_nil }
|
50
74
|
end
|
51
|
-
end
|
52
75
|
|
53
|
-
|
54
|
-
|
76
|
+
context 'when the argument is ::Object' do
|
77
|
+
let(:arg) { ::Object }
|
55
78
|
|
56
|
-
|
57
|
-
|
79
|
+
it { should be_nil }
|
80
|
+
end
|
58
81
|
|
59
|
-
|
60
|
-
|
82
|
+
context 'when the argument is an ::Object instance' do
|
83
|
+
let(:arg) { ::Object.new }
|
84
|
+
|
85
|
+
it { should be_nil }
|
86
|
+
end
|
61
87
|
|
62
|
-
|
88
|
+
context 'when the argument is ::Struct' do
|
89
|
+
let(:arg) { ::Struct }
|
90
|
+
|
91
|
+
it { should be(object) }
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'when the argument is a ::Struct instance' do
|
95
|
+
let(:arg) { ::Struct.new(:a).new(1) }
|
96
|
+
|
97
|
+
it { should be_nil }
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'when the argument is nil' do
|
101
|
+
let(:arg) { nil }
|
102
|
+
|
103
|
+
it { should be_nil }
|
104
|
+
end
|
63
105
|
end
|
64
106
|
end
|
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.
|
4
|
+
version: 0.0.5
|
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-
|
11
|
+
date: 2013-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: descendants_tracker
|
@@ -65,6 +65,7 @@ extensions: []
|
|
65
65
|
extra_rdoc_files:
|
66
66
|
- LICENSE
|
67
67
|
- README.md
|
68
|
+
- CONTRIBUTING.md
|
68
69
|
- TODO
|
69
70
|
files:
|
70
71
|
- .gitignore
|