axiom-types 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ODM0YjEzMzYzZTYwY2JhYTg5ZDQwNDRiNGJjZjMzOWEzNDljMTkzYw==
5
+ data.tar.gz: !binary |-
6
+ NTQ1ZjM0ODk1NzA0OThmYzAyYWM1MmMxN2E5MGRmZjkxNWRjODA0Zg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZTlhM2FmMWM4MTY1NmI5MDc2ZDc4MjYxMGRkNzIyNDRkYzJiMGVlMDkzN2I3
10
+ Yjk0MDEwZmI2NzIzMzNhYTczYWJlYzZlZTRiNDcwYjVmYmY2ZjA0MGY1Mjg3
11
+ YmFmYjYyNTk5ODEzYmVkMjI0MDdmZDYyZDA4MWJiNjAzMjFhZjE=
12
+ data.tar.gz: !binary |-
13
+ ZGY5ZjFiYjlhN2E2ZjRkMTYxZjdjMTI1ZjA5MGE3Y2EzODIwNTlmMmNkMzE5
14
+ NjliMzg5Y2U3MDQ3MGRkNzMzNmE0YzgyMzYzM2UzMDgxYzQxNjY3MDFlNmY3
15
+ Y2FmYmEwMzZjOWM3ZWYxZTZhMmU4N2Q1YWFmMGI1OWY5NTg2ZDk=
@@ -7,7 +7,7 @@ group :development do
7
7
  end
8
8
 
9
9
  group :yard do
10
- gem 'kramdown', '~> 1.1.0'
10
+ gem 'kramdown', '~> 1.2.0'
11
11
  end
12
12
 
13
13
  group :guard do
@@ -34,7 +34,7 @@ group :metrics do
34
34
  gem 'flay', '~> 2.4.0'
35
35
  gem 'flog', '~> 4.1.1'
36
36
  gem 'reek', '~> 1.3.2'
37
- gem 'rubocop', '~> 0.11.0'
37
+ gem 'rubocop', '~> 0.13.0'
38
38
  gem 'simplecov', '~> 0.7.1'
39
39
  gem 'yardstick', '~> 0.9.7', git: 'https://github.com/dkubb/yardstick.git'
40
40
 
@@ -1,3 +1,3 @@
1
1
  ---
2
2
  threshold: 19
3
- total_score: 142
3
+ total_score: 155
@@ -16,10 +16,10 @@ module Axiom
16
16
  Undefined = Object.new.freeze
17
17
 
18
18
  # A true proposition
19
- Tautology = proc { true }.freeze
19
+ Tautology = ->(_value) { true }.freeze
20
20
 
21
21
  # A false proposition
22
- Contradiction = proc { false }.freeze
22
+ Contradiction = ->(_value) { true }.freeze
23
23
 
24
24
  # Cache the type inference lookup by object
25
25
  @inference_cache = Hash.new do |cache, object|
@@ -61,6 +61,18 @@ module Axiom
61
61
  super
62
62
  end
63
63
 
64
+ # Test if the type matches a primitive class
65
+ #
66
+ # @param [Object] object
67
+ #
68
+ # @return [Boolean]
69
+ #
70
+ # @api private
71
+ def self.match_primitive?(*)
72
+ super && member_type.equal?(Object)
73
+ end
74
+ private_class_method :match_primitive?
75
+
64
76
  # Infer the type from a primitive instance
65
77
  #
66
78
  # @param [Object] object
@@ -47,6 +47,18 @@ module Axiom
47
47
  super
48
48
  end
49
49
 
50
+ # Test if the type matches a primitive class
51
+ #
52
+ # @param [Object] object
53
+ #
54
+ # @return [Boolean]
55
+ #
56
+ # @api private
57
+ def self.match_primitive?(*)
58
+ super && key_type.equal?(Object) && value_type.equal?(Object)
59
+ end
60
+ private_class_method :match_primitive?
61
+
50
62
  # Infer the type from a primitive instance
51
63
  #
52
64
  # @param [Object] object
@@ -77,9 +89,8 @@ module Axiom
77
89
  #
78
90
  # @api private
79
91
  def self.infer_from(key_type, value_type)
80
- if self.key_type.equal?(key_type) && self.value_type.equal?(value_type)
81
- self
82
- end
92
+ self if self.key_type.equal?(key_type) &&
93
+ self.value_type.equal?(value_type)
83
94
  end
84
95
  private_class_method :infer_from
85
96
 
@@ -48,11 +48,23 @@ module Axiom
48
48
  #
49
49
  # @api private
50
50
  def self.infer_from_primitive_class(object)
51
- self if object.respond_to?(:ancestors) &&
52
- object.ancestors.include?(primitive)
51
+ self if match_primitive?(object)
53
52
  end
54
53
  private_class_method :infer_from_primitive_class
55
54
 
55
+ # Test if the type matches a primitive class
56
+ #
57
+ # @param [Object] object
58
+ #
59
+ # @return [Boolean]
60
+ #
61
+ # @api private
62
+ def self.match_primitive?(object)
63
+ object.respond_to?(:ancestors) &&
64
+ object.ancestors.include?(primitive)
65
+ end
66
+ private_class_method :match_primitive?
67
+
56
68
  # Add a constraint for the primitive
57
69
  #
58
70
  # @return [undefined]
@@ -88,7 +88,7 @@ module Axiom
88
88
  # Add a constraint to the type
89
89
  #
90
90
  # @example with an argument
91
- # type.constraint(lambda { |object| object == 42 }
91
+ # type.constraint(->(object) { object == 42 }
92
92
  #
93
93
  # @example with a block
94
94
  # type.constraint { |object| object == 42 }
@@ -4,7 +4,7 @@ module Axiom
4
4
  module Types
5
5
 
6
6
  # Gem version
7
- VERSION = '0.0.3'.freeze
7
+ VERSION = '0.0.4'.freeze
8
8
 
9
9
  end # module Types
10
10
  end # module Axiom
@@ -1,7 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'devtools/spec_helper'
4
-
5
3
  if ENV['COVERAGE'] == 'true'
6
4
  require 'simplecov'
7
5
  require 'coveralls'
@@ -12,22 +10,21 @@ if ENV['COVERAGE'] == 'true'
12
10
  ]
13
11
 
14
12
  SimpleCov.start do
15
- command_name 'spec:unit'
16
- add_filter 'config'
17
- add_filter 'spec'
13
+ command_name 'spec:unit'
14
+
15
+ add_filter 'config'
16
+ add_filter 'spec'
17
+ add_filter 'vendor'
18
+
18
19
  minimum_coverage 100
19
20
  end
20
21
  end
21
22
 
23
+ require 'devtools/spec_helper'
22
24
  require 'axiom-types'
23
25
 
24
26
  include Axiom::Types
25
27
 
26
- # Require spec support files and shared behavior
27
- Dir[File.expand_path('../{support,shared}/**/*.rb', __FILE__)].each do |file|
28
- require file.chomp('.rb')
29
- end
30
-
31
28
  RSpec.configure do |config|
32
29
  config.expect_with :rspec do |expect_with|
33
30
  expect_with.syntax = :expect
@@ -9,6 +9,12 @@ describe Axiom::Types::Array, '.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(Array[Float])
16
+ end
17
+
12
18
  context 'with Axiom::Types::Array' do
13
19
  let(:object) { described_class }
14
20
 
@@ -9,6 +9,12 @@ 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])
16
+ end
17
+
12
18
  context 'with a base class' do
13
19
  let(:object) do
14
20
  Class.new(described_class) do
@@ -9,6 +9,13 @@ describe Axiom::Types::Hash, '.infer' do
9
9
  object.finalize
10
10
  end
11
11
 
12
+ before do
13
+ # Initialize custom types that will be used if the class lookup does not
14
+ # restrict matching to only types with an Object key and value types
15
+ Axiom::Types.infer(Hash[Object => Float])
16
+ Axiom::Types.infer(Hash[Float => Object])
17
+ end
18
+
12
19
  context 'with Axiom::Types::Hash' do
13
20
  let(:object) { described_class }
14
21
 
@@ -9,6 +9,12 @@ describe Axiom::Types::Set, '.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(Set[Float])
16
+ end
17
+
12
18
  context 'with Axiom::Types::Set' do
13
19
  let(:object) { described_class }
14
20
 
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: axiom-types
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
5
- prerelease:
4
+ version: 0.0.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Dan Kubb
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-08-22 00:00:00.000000000 Z
11
+ date: 2013-09-29 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: descendants_tracker
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: ice_nine
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: bundler
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -57,7 +51,6 @@ dependencies:
57
51
  type: :development
58
52
  prerelease: false
59
53
  version_requirements: !ruby/object:Gem::Requirement
60
- none: false
61
54
  requirements:
62
55
  - - ~>
63
56
  - !ruby/object:Gem::Version
@@ -156,27 +149,26 @@ files:
156
149
  homepage: https://github.com/dkubb/axiom-types
157
150
  licenses:
158
151
  - MIT
152
+ metadata: {}
159
153
  post_install_message:
160
154
  rdoc_options: []
161
155
  require_paths:
162
156
  - lib
163
157
  required_ruby_version: !ruby/object:Gem::Requirement
164
- none: false
165
158
  requirements:
166
159
  - - ! '>='
167
160
  - !ruby/object:Gem::Version
168
161
  version: '0'
169
162
  required_rubygems_version: !ruby/object:Gem::Requirement
170
- none: false
171
163
  requirements:
172
164
  - - ! '>='
173
165
  - !ruby/object:Gem::Version
174
166
  version: '0'
175
167
  requirements: []
176
168
  rubyforge_project:
177
- rubygems_version: 1.8.23
169
+ rubygems_version: 2.1.1
178
170
  signing_key:
179
- specification_version: 3
171
+ specification_version: 4
180
172
  summary: Define types with optional constraints for use within axiom and other libraries.
181
173
  test_files:
182
174
  - spec/unit/axiom/types/array/class_methods/infer_spec.rb