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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODM0YjEzMzYzZTYwY2JhYTg5ZDQwNDRiNGJjZjMzOWEzNDljMTkzYw==
4
+ OTk1ZjkwNjg3MjZkNzIwNmI5Yzc4YmNlMTQ5NjNlNDhkNWI5Y2EyZg==
5
5
  data.tar.gz: !binary |-
6
- NTQ1ZjM0ODk1NzA0OThmYzAyYWM1MmMxN2E5MGRmZjkxNWRjODA0Zg==
6
+ NTllNTE2NWUzNDUwNGJlODJmODk2NzBiZmM1YmIwYWZlNGM3YzZjNw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZTlhM2FmMWM4MTY1NmI5MDc2ZDc4MjYxMGRkNzIyNDRkYzJiMGVlMDkzN2I3
10
- Yjk0MDEwZmI2NzIzMzNhYTczYWJlYzZlZTRiNDcwYjVmYmY2ZjA0MGY1Mjg3
11
- YmFmYjYyNTk5ODEzYmVkMjI0MDdmZDYyZDA4MWJiNjAzMjFhZjE=
9
+ YjJkYjk1OWQ1MmQ5NjVkZWU4Y2FhZjVlY2VlZGFhNzMzYWE3MWZkMjc0MGY4
10
+ YmQzYjNiYmIzOGYzMzdjYzUwOTg5NmU5ZTBlN2ZjYjg3MWMxMWYzNTE4ZjA3
11
+ ZTQ0ZGI3N2YyM2ZjZGQ4MmQ2ZTA2ZTgwMTA3NmNiZjcxMTYyMTQ=
12
12
  data.tar.gz: !binary |-
13
- ZGY5ZjFiYjlhN2E2ZjRkMTYxZjdjMTI1ZjA5MGE3Y2EzODIwNTlmMmNkMzE5
14
- NjliMzg5Y2U3MDQ3MGRkNzMzNmE0YzgyMzYzM2UzMDgxYzQxNjY3MDFlNmY3
15
- Y2FmYmEwMzZjOWM3ZWYxZTZhMmU4N2Q1YWFmMGI1OWY5NTg2ZDk=
13
+ MGQwZmUxMDZhNjhjYWFhNTQ0NjY0ODQ2OGJmMDAwMzI0M2UwMDQ0ODg4OGRm
14
+ MzA0ZTkxYjZjNWJkYjMyNjBhZmFkMzE2Yzc4YjA4Zjk0ODI0OGQ3OTcwNjBh
15
+ OTIzZGRhODBjZjdlOWJjYTY2YTViYTVkMzY3ZmEyOThmMGU1YTE=
@@ -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.
@@ -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.licenses = %w[MIT]
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')
@@ -1,3 +1,3 @@
1
1
  ---
2
2
  threshold: 19
3
- total_score: 155
3
+ total_score: 162
@@ -84,8 +84,7 @@ module Axiom
84
84
  #
85
85
  # @api private
86
86
  def self.infer_from_primitive_instance(object)
87
- member = object.first
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
@@ -60,8 +60,8 @@ module Axiom
60
60
  #
61
61
  # @api private
62
62
  def self.match_primitive?(object)
63
- object.respond_to?(:ancestors) &&
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
 
@@ -20,7 +20,7 @@ module Axiom
20
20
  def self.<=>(other)
21
21
  case other
22
22
  when ::BigDecimal then 1
23
- when number then 0
23
+ when ->(arg) { arg == number } then 0
24
24
  when ::Numeric, inverse.singleton_class then 1
25
25
  end
26
26
  end
@@ -4,7 +4,7 @@ module Axiom
4
4
  module Types
5
5
 
6
6
  # Gem version
7
- VERSION = '0.0.4'.freeze
7
+ VERSION = '0.0.5'.freeze
8
8
 
9
9
  end # module Types
10
10
  end # module Axiom
@@ -9,10 +9,20 @@ describe Axiom::Types::Collection, '.infer' do
9
9
  object.finalize
10
10
  end
11
11
 
12
- before do
13
- # Initialize a custom type that will be used if the class lookup does not
14
- # restrict matching to only types with an Object member_type
15
- Axiom::Types.infer(SortedSet[Float])
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
- let(:object) { described_class }
8
+ context 'with the type' do
9
+ let(:object) { described_class }
9
10
 
10
- context 'when the argument is the type object' do
11
- let(:arg) { object }
11
+ context 'when the argument is the type object' do
12
+ let(:arg) { object }
12
13
 
13
- it { should be(object) }
14
- end
14
+ it { should be(object) }
15
+ end
15
16
 
16
- context 'when the argument is ::BasicObject' do
17
- let(:arg) { ::BasicObject }
17
+ context 'when the argument is ::BasicObject' do
18
+ let(:arg) { ::BasicObject }
18
19
 
19
- it { should be(object) }
20
- end
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
- context 'when the argument is ::Object' do
23
- let(:arg) { ::Object }
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
- it { should be(object) }
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
- Axiom::Types::Object.descendants.each do |descendant|
29
- primitive = descendant.primitive
59
+ context 'with a subclass' do
60
+ let(:object) do
61
+ described_class.new { primitive ::Struct }
62
+ end
30
63
 
31
- context "when the argument is #{descendant}" do
32
- let(:object) { descendant }
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 "when the argument is ::#{primitive}" do
39
- let(:arg) { primitive }
40
-
41
- if primitive.instance_of?(::Module)
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
- context 'when the argument is an object instance' do
54
- let(:arg) { ::Object.new }
76
+ context 'when the argument is ::Object' do
77
+ let(:arg) { ::Object }
55
78
 
56
- it { should be_nil }
57
- end
79
+ it { should be_nil }
80
+ end
58
81
 
59
- context 'when the argument is nil' do
60
- let(:arg) { nil }
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
- it { should be_nil }
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
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-09-29 00:00:00.000000000 Z
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