axiom-types 0.0.2 → 0.0.3
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.
- data/.rspec +1 -0
- data/.travis.yml +11 -16
- data/Gemfile +5 -2
- data/Gemfile.devtools +19 -24
- data/Guardfile +18 -10
- data/README.md +5 -28
- data/axiom-types.gemspec +2 -3
- data/config/flay.yml +2 -2
- data/config/flog.yml +1 -1
- data/config/reek.yml +15 -13
- data/config/rubocop.yml +62 -0
- data/lib/axiom/types.rb +5 -3
- data/lib/axiom/types/boolean.rb +4 -2
- data/lib/axiom/types/collection.rb +5 -2
- data/lib/axiom/types/encodable.rb +1 -1
- data/lib/axiom/types/float.rb +3 -0
- data/lib/axiom/types/hash.rb +8 -3
- data/lib/axiom/types/length_comparable.rb +7 -4
- data/lib/axiom/types/numeric.rb +5 -0
- data/lib/axiom/types/object.rb +2 -2
- data/lib/axiom/types/support/infinity.rb +116 -0
- data/lib/axiom/types/support/options.rb +9 -18
- data/lib/axiom/types/time.rb +2 -2
- data/lib/axiom/types/type.rb +13 -9
- data/lib/axiom/types/value_comparable.rb +5 -2
- data/lib/axiom/types/version.rb +1 -1
- data/spec/unit/axiom/types/boolean/class_methods/infer_spec.rb +6 -0
- data/spec/unit/axiom/types/collection/class_methods/finalize_spec.rb +3 -3
- data/spec/unit/axiom/types/encodable/class_methods/extended_spec.rb +8 -7
- data/spec/unit/axiom/types/encodable/finalize_spec.rb +30 -8
- data/spec/unit/axiom/types/hash/class_methods/infer_spec.rb +17 -17
- data/spec/unit/axiom/types/infinity/class_methods/coerce_spec.rb +64 -0
- data/spec/unit/axiom/types/infinity/class_methods/spaceship_operator_spec.rb +67 -0
- data/spec/unit/axiom/types/infinity/class_methods/succ_spec.rb +11 -0
- data/spec/unit/axiom/types/length_comparable/class_methods/extended_spec.rb +17 -8
- data/spec/unit/axiom/types/negative_infinity/class_methods/spaceship_operator_spec.rb +67 -0
- data/spec/unit/axiom/types/object/class_methods/coercion_method_spec.rb +2 -2
- data/spec/unit/axiom/types/object/class_methods/infer_spec.rb +13 -1
- data/spec/unit/axiom/types/object/class_methods/primitive_spec.rb +4 -4
- data/spec/unit/axiom/types/options/accept_options_spec.rb +12 -4
- data/spec/unit/axiom/types/options/inherited_spec.rb +10 -36
- data/spec/unit/axiom/types/type/class_methods/constraint_spec.rb +6 -11
- data/spec/unit/axiom/types/type/class_methods/include_predicate_spec.rb +7 -7
- data/spec/unit/axiom/types/type/class_methods/includes_spec.rb +2 -2
- data/spec/unit/axiom/types/value_comparable/class_methods/extended_spec.rb +17 -8
- metadata +29 -31
- checksums.yaml +0 -7
data/.rspec
CHANGED
data/.travis.yml
CHANGED
@@ -3,29 +3,24 @@ before_install: gem install bundler
|
|
3
3
|
bundler_args: --without yard guard benchmarks
|
4
4
|
script: "bundle exec rake ci"
|
5
5
|
rvm:
|
6
|
-
- ree
|
7
|
-
- 1.8.7
|
8
|
-
- 1.9.2
|
9
6
|
- 1.9.3
|
10
7
|
- 2.0.0
|
11
8
|
- ruby-head
|
12
|
-
- rbx-18mode
|
13
9
|
- rbx-19mode
|
14
|
-
- jruby-18mode
|
15
|
-
notifications:
|
16
|
-
irc:
|
17
|
-
channels:
|
18
|
-
- irc.freenode.org#rom-rb
|
19
|
-
on_success: never
|
20
|
-
on_failure: change
|
21
|
-
email:
|
22
|
-
recipients:
|
23
|
-
- dan.kubb@gmail.com
|
24
|
-
on_success: never
|
25
|
-
on_failure: change
|
26
10
|
matrix:
|
27
11
|
include:
|
28
12
|
- rvm: jruby-19mode
|
29
13
|
env: JRUBY_OPTS="$JRUBY_OPTS --debug"
|
30
14
|
- rvm: jruby-head
|
31
15
|
env: JRUBY_OPTS="$JRUBY_OPTS --debug"
|
16
|
+
allow_failures:
|
17
|
+
- rvm: 1.9.3 # mutant fails
|
18
|
+
- rvm: 2.0.0 # mutant fails
|
19
|
+
- rvm: ruby-head # travis broken
|
20
|
+
- rvm: rbx-19mode # mutant fails
|
21
|
+
notifications:
|
22
|
+
irc:
|
23
|
+
channels:
|
24
|
+
- irc.freenode.org#rom-rb
|
25
|
+
on_success: never
|
26
|
+
on_failure: change
|
data/Gemfile
CHANGED
@@ -4,5 +4,8 @@ source 'https://rubygems.org'
|
|
4
4
|
|
5
5
|
gemspec
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
group :development, :test do
|
8
|
+
gem 'devtools', git: 'https://github.com/rom-rb/devtools.git'
|
9
|
+
end
|
10
|
+
|
11
|
+
eval_gemfile 'Gemfile.devtools'
|
data/Gemfile.devtools
CHANGED
@@ -2,50 +2,45 @@
|
|
2
2
|
|
3
3
|
group :development do
|
4
4
|
gem 'rake', '~> 10.1.0'
|
5
|
-
gem 'rspec', '~> 2.
|
6
|
-
gem 'yard', '~> 0.8.
|
5
|
+
gem 'rspec', '~> 2.14.1'
|
6
|
+
gem 'yard', '~> 0.8.7'
|
7
7
|
end
|
8
8
|
|
9
9
|
group :yard do
|
10
|
-
gem 'kramdown', '~> 1.0
|
10
|
+
gem 'kramdown', '~> 1.1.0'
|
11
11
|
end
|
12
12
|
|
13
13
|
group :guard do
|
14
14
|
gem 'guard', '~> 1.8.1'
|
15
15
|
gem 'guard-bundler', '~> 1.0.0'
|
16
16
|
gem 'guard-rspec', '~> 3.0.2'
|
17
|
+
gem 'guard-rubocop', '~> 0.2.0'
|
18
|
+
gem 'guard-mutant', '~> 0.0.1'
|
17
19
|
|
18
20
|
# file system change event handling
|
19
|
-
gem 'listen', '~> 1.
|
20
|
-
gem 'rb-fchange', '~> 0.0.6', :
|
21
|
-
gem 'rb-fsevent', '~> 0.9.3', :
|
22
|
-
gem 'rb-inotify', '~> 0.9.0', :
|
21
|
+
gem 'listen', '~> 1.3.0'
|
22
|
+
gem 'rb-fchange', '~> 0.0.6', require: false
|
23
|
+
gem 'rb-fsevent', '~> 0.9.3', require: false
|
24
|
+
gem 'rb-inotify', '~> 0.9.0', require: false
|
23
25
|
|
24
26
|
# notification handling
|
25
|
-
gem 'libnotify', '~> 0.8.0', :
|
26
|
-
gem 'rb-notifu', '~> 0.0.4', :
|
27
|
-
gem 'terminal-notifier-guard', '~> 1.5.3', :
|
27
|
+
gem 'libnotify', '~> 0.8.0', require: false
|
28
|
+
gem 'rb-notifu', '~> 0.0.4', require: false
|
29
|
+
gem 'terminal-notifier-guard', '~> 1.5.3', require: false
|
28
30
|
end
|
29
31
|
|
30
32
|
group :metrics do
|
31
|
-
gem 'backports', '~> 3.3', '>= 3.3.2'
|
32
33
|
gem 'coveralls', '~> 0.6.7'
|
33
|
-
gem 'flay', '~> 2.
|
34
|
-
gem 'flog', '~> 4.1.
|
35
|
-
gem 'reek', '~> 1.3.
|
34
|
+
gem 'flay', '~> 2.4.0'
|
35
|
+
gem 'flog', '~> 4.1.1'
|
36
|
+
gem 'reek', '~> 1.3.2'
|
37
|
+
gem 'rubocop', '~> 0.11.0'
|
36
38
|
gem 'simplecov', '~> 0.7.1'
|
37
|
-
gem 'yardstick', '~> 0.9.
|
38
|
-
|
39
|
-
platforms :ruby_19 do
|
40
|
-
gem 'yard-spellcheck', '~> 0.1.5'
|
41
|
-
end
|
39
|
+
gem 'yardstick', '~> 0.9.7', git: 'https://github.com/dkubb/yardstick.git'
|
42
40
|
|
43
41
|
platforms :ruby_19, :ruby_20 do
|
44
|
-
gem 'mutant', '
|
45
|
-
|
46
|
-
|
47
|
-
platforms :rbx do
|
48
|
-
gem 'pelusa', '~> 0.2.2'
|
42
|
+
gem 'mutant', git: 'https://github.com/mbj/mutant.git'
|
43
|
+
gem 'yard-spellcheck', '~> 0.1.5'
|
49
44
|
end
|
50
45
|
end
|
51
46
|
|
data/Guardfile
CHANGED
@@ -2,23 +2,31 @@
|
|
2
2
|
|
3
3
|
guard :bundler do
|
4
4
|
watch('Gemfile')
|
5
|
-
watch('
|
5
|
+
watch('Gemfile.lock')
|
6
|
+
watch(%w{.+.gemspec\z})
|
6
7
|
end
|
7
8
|
|
8
|
-
guard :rspec, :keep_failed
|
9
|
-
#
|
9
|
+
guard :rspec, cli: File.read('.rspec').split.push('--fail-fast').join(' '), keep_failed: false do
|
10
|
+
# Run all specs if configuration is modified
|
11
|
+
watch('.rspec') { 'spec' }
|
10
12
|
watch('Guardfile') { 'spec' }
|
11
13
|
watch('Gemfile.lock') { 'spec' }
|
12
14
|
watch('spec/spec_helper.rb') { 'spec' }
|
13
15
|
|
14
|
-
#
|
15
|
-
watch(%r{\Aspec/(?:lib|support|shared)/.+\.rb\z}) { 'spec' }
|
16
|
+
# Run all specs if supporting files files are modified
|
17
|
+
watch(%r{\Aspec/(?:fixtures|lib|support|shared)/.+\.rb\z}) { 'spec' }
|
16
18
|
|
17
|
-
#
|
18
|
-
watch(%r{\Alib/(.+)\.rb\z}) { |m| Dir["spec/unit/#{m[1]}"] }
|
19
|
-
watch(%r{\Alib/(.+)/support/(.+)\.rb\z}) { |m| Dir["spec/unit/#{m[1]}/#{m[2]}"] }
|
20
|
-
watch("lib/#{File.basename(File.expand_path('../', __FILE__))}.rb") { 'spec'
|
19
|
+
# Run unit specs if associated lib code is modified
|
20
|
+
watch(%r{\Alib/(.+)\.rb\z}) { |m| Dir["spec/unit/#{m[1]}*"] }
|
21
|
+
watch(%r{\Alib/(.+)/support/(.+)\.rb\z}) { |m| Dir["spec/unit/#{m[1]}/#{m[2]}*"] }
|
22
|
+
watch("lib/#{File.basename(File.expand_path('../', __FILE__))}.rb") { 'spec' }
|
21
23
|
|
22
|
-
#
|
24
|
+
# Run a spec if it is modified
|
23
25
|
watch(%r{\Aspec/(?:unit|integration)/.+_spec\.rb\z})
|
24
26
|
end
|
27
|
+
|
28
|
+
guard :rubocop, cli: %w[--config config/rubocop.yml] do
|
29
|
+
watch(%r{.+\.(?:rb|rake)\z})
|
30
|
+
watch(%r{\Aconfig/rubocop\.yml\z}) { |m| File.dirname(m[0]) }
|
31
|
+
watch(%r{(?:.+/)?\.rubocop\.yml\z}) { |m| File.dirname(m[0]) }
|
32
|
+
end
|
data/README.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
axiom-types
|
2
|
+
===========
|
3
|
+
|
4
|
+
Define types with optional constraints for use within axiom and other libraries.
|
5
|
+
|
1
6
|
[][gem]
|
2
7
|
[][travis]
|
3
8
|
[][gemnasium]
|
@@ -10,11 +15,6 @@
|
|
10
15
|
[codeclimate]: https://codeclimate.com/github/dkubb/axiom-types
|
11
16
|
[coveralls]: https://coveralls.io/r/dkubb/axiom-types
|
12
17
|
|
13
|
-
axiom-types
|
14
|
-
===========
|
15
|
-
|
16
|
-
Define types with optional constraints for use within axiom and other libraries.
|
17
|
-
|
18
18
|
Examples
|
19
19
|
--------
|
20
20
|
|
@@ -35,29 +35,6 @@ Name.include?('') # => false
|
|
35
35
|
Name.include?('a' * 31) # => false
|
36
36
|
```
|
37
37
|
|
38
|
-
Installation
|
39
|
-
------------
|
40
|
-
|
41
|
-
With Rubygems:
|
42
|
-
|
43
|
-
```bash
|
44
|
-
$ gem install axiom-types
|
45
|
-
$ irb -rubygems
|
46
|
-
>> require 'axiom-types'
|
47
|
-
=> true
|
48
|
-
```
|
49
|
-
|
50
|
-
With git and local working copy:
|
51
|
-
|
52
|
-
```bash
|
53
|
-
$ git clone git://github.com/dkubb/axiom-types.git
|
54
|
-
$ cd axiom-types
|
55
|
-
$ rake install
|
56
|
-
$ irb -rubygems
|
57
|
-
>> require 'axiom-types'
|
58
|
-
=> true
|
59
|
-
```
|
60
|
-
|
61
38
|
Contributing
|
62
39
|
-------------
|
63
40
|
|
data/axiom-types.gemspec
CHANGED
@@ -17,9 +17,8 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.test_files = `git ls-files -- spec/unit`.split($/)
|
18
18
|
gem.extra_rdoc_files = %w[LICENSE README.md TODO]
|
19
19
|
|
20
|
-
gem.
|
21
|
-
gem.
|
22
|
-
gem.add_runtime_dependency('ice_nine', '~> 0.8.0')
|
20
|
+
gem.add_dependency('descendants_tracker', '~> 0.0.1')
|
21
|
+
gem.add_dependency('ice_nine', '~> 0.9')
|
23
22
|
|
24
23
|
gem.add_development_dependency('bundler', '~> 1.3', '>= 1.3.5')
|
25
24
|
end
|
data/config/flay.yml
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
---
|
2
|
-
threshold:
|
3
|
-
total_score:
|
2
|
+
threshold: 19
|
3
|
+
total_score: 142
|
data/config/flog.yml
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
---
|
2
|
-
threshold:
|
2
|
+
threshold: 10.0
|
data/config/reek.yml
CHANGED
@@ -18,7 +18,8 @@ DataClump:
|
|
18
18
|
min_clump_size: 2
|
19
19
|
DuplicateMethodCall:
|
20
20
|
enabled: true
|
21
|
-
exclude:
|
21
|
+
exclude:
|
22
|
+
- Axiom::Types::Infinity#self.coerce
|
22
23
|
max_calls: 1
|
23
24
|
allow_calls: []
|
24
25
|
FeatureEnvy:
|
@@ -52,7 +53,8 @@ NilCheck:
|
|
52
53
|
- Axiom::Types::Type#self.constraint
|
53
54
|
RepeatedConditional:
|
54
55
|
enabled: true
|
55
|
-
exclude:
|
56
|
+
exclude:
|
57
|
+
- Axiom::Types::Infinity
|
56
58
|
max_ifs: 1
|
57
59
|
TooManyInstanceVariables:
|
58
60
|
enabled: true
|
@@ -71,32 +73,32 @@ UncommunicativeMethodName:
|
|
71
73
|
enabled: true
|
72
74
|
exclude: []
|
73
75
|
reject:
|
74
|
-
|
75
|
-
|
76
|
-
|
76
|
+
- !ruby/regexp /^[a-z]$/
|
77
|
+
- !ruby/regexp /[0-9]$/
|
78
|
+
- !ruby/regexp /[A-Z]/
|
77
79
|
accept: []
|
78
80
|
UncommunicativeModuleName:
|
79
81
|
enabled: true
|
80
82
|
exclude: []
|
81
83
|
reject:
|
82
|
-
|
83
|
-
|
84
|
+
- !ruby/regexp /^.$/
|
85
|
+
- !ruby/regexp /[0-9]$/
|
84
86
|
accept: []
|
85
87
|
UncommunicativeParameterName:
|
86
88
|
enabled: true
|
87
89
|
exclude: []
|
88
90
|
reject:
|
89
|
-
|
90
|
-
|
91
|
-
|
91
|
+
- !ruby/regexp /^.$/
|
92
|
+
- !ruby/regexp /[0-9]$/
|
93
|
+
- !ruby/regexp /[A-Z]/
|
92
94
|
accept: []
|
93
95
|
UncommunicativeVariableName:
|
94
96
|
enabled: true
|
95
97
|
exclude: []
|
96
98
|
reject:
|
97
|
-
|
98
|
-
|
99
|
-
|
99
|
+
- !ruby/regexp /^.$/
|
100
|
+
- !ruby/regexp /[0-9]$/
|
101
|
+
- !ruby/regexp /[A-Z]/
|
100
102
|
accept: []
|
101
103
|
UnusedParameters:
|
102
104
|
enabled: true
|
data/config/rubocop.yml
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
AllCops:
|
2
|
+
Includes:
|
3
|
+
- '../**/*.rake'
|
4
|
+
- 'Gemfile'
|
5
|
+
- 'Gemfile.devtools'
|
6
|
+
Excludes:
|
7
|
+
- '**/vendor/**'
|
8
|
+
- '**/benchmarks/**'
|
9
|
+
|
10
|
+
# Avoid parameter lists longer than five parameters.
|
11
|
+
ParameterLists:
|
12
|
+
Max: 3
|
13
|
+
CountKeywordArgs: true
|
14
|
+
|
15
|
+
# Avoid more than `Max` levels of nesting.
|
16
|
+
BlockNesting:
|
17
|
+
Max: 3
|
18
|
+
|
19
|
+
# Align with the style guide.
|
20
|
+
CollectionMethods:
|
21
|
+
PreferredMethods:
|
22
|
+
collect: 'map'
|
23
|
+
inject: 'reduce'
|
24
|
+
find: 'detect'
|
25
|
+
find_all: 'select'
|
26
|
+
|
27
|
+
# Do not force public/protected/private keyword to be indented at the same
|
28
|
+
# level as the def keyword. My personal preference is to outdent these keywords
|
29
|
+
# because I think when scanning code it makes it easier to identify the
|
30
|
+
# sections of code and visually separate them. When the keyword is at the same
|
31
|
+
# level I think it sort of blends in with the def keywords and makes it harder
|
32
|
+
# to scan the code and see where the sections are.
|
33
|
+
AccessControl:
|
34
|
+
Enabled: false
|
35
|
+
|
36
|
+
# Limit line length
|
37
|
+
LineLength:
|
38
|
+
Max: 79
|
39
|
+
|
40
|
+
# Disable documentation checking until a class needs to be documented once
|
41
|
+
Documentation:
|
42
|
+
Enabled: false
|
43
|
+
|
44
|
+
# Do not always use &&/|| instead of and/or.
|
45
|
+
AndOr:
|
46
|
+
Enabled: false
|
47
|
+
|
48
|
+
# Do not favor modifier if/unless usage when you have a single-line body
|
49
|
+
IfUnlessModifier:
|
50
|
+
Enabled: false
|
51
|
+
|
52
|
+
# Allow case equality operator (in limited use within the specs)
|
53
|
+
CaseEquality:
|
54
|
+
Enabled: false
|
55
|
+
|
56
|
+
# Constants do not always have to use SCREAMING_SNAKE_CASE
|
57
|
+
ConstantName:
|
58
|
+
Enabled: false
|
59
|
+
|
60
|
+
# Not all trivial readers/writers can be defined with attr_* methods
|
61
|
+
TrivialAccessors:
|
62
|
+
Enabled: false
|
data/lib/axiom/types.rb
CHANGED
@@ -4,11 +4,12 @@ require 'bigdecimal'
|
|
4
4
|
require 'date'
|
5
5
|
require 'set'
|
6
6
|
|
7
|
-
require 'backports'
|
8
7
|
require 'ice_nine'
|
9
8
|
require 'descendants_tracker'
|
10
9
|
|
11
10
|
module Axiom
|
11
|
+
|
12
|
+
# Gem namespace
|
12
13
|
module Types
|
13
14
|
|
14
15
|
# Represent an undefined argument
|
@@ -23,8 +24,8 @@ module Axiom
|
|
23
24
|
# Cache the type inference lookup by object
|
24
25
|
@inference_cache = Hash.new do |cache, object|
|
25
26
|
type = nil
|
26
|
-
Type.descendants.
|
27
|
-
|
27
|
+
Type.descendants.detect do |descendant|
|
28
|
+
type = descendant.infer(object)
|
28
29
|
end
|
29
30
|
cache[object] = type
|
30
31
|
end
|
@@ -60,6 +61,7 @@ module Axiom
|
|
60
61
|
end # module Types
|
61
62
|
end # module Axiom
|
62
63
|
|
64
|
+
require 'axiom/types/support/infinity'
|
63
65
|
require 'axiom/types/support/options'
|
64
66
|
|
65
67
|
require 'axiom/types/value_comparable'
|
data/lib/axiom/types/boolean.rb
CHANGED
@@ -20,8 +20,10 @@ module Axiom
|
|
20
20
|
#
|
21
21
|
# @api private
|
22
22
|
def self.infer_from_primitive_class(object)
|
23
|
-
|
24
|
-
|
23
|
+
case object
|
24
|
+
when TrueClass.singleton_class, FalseClass.singleton_class
|
25
|
+
self
|
26
|
+
end
|
25
27
|
end
|
26
28
|
|
27
29
|
private_class_method :infer_from_primitive_class
|
@@ -76,6 +76,7 @@ module Axiom
|
|
76
76
|
member_type = Types.infer(member) || Object
|
77
77
|
infer_from(member_type) || new_from(member_type)
|
78
78
|
end
|
79
|
+
private_class_method :infer_from_primitive_instance
|
79
80
|
|
80
81
|
# Infer the type from the member_type
|
81
82
|
#
|
@@ -90,6 +91,7 @@ module Axiom
|
|
90
91
|
def self.infer_from(member_type)
|
91
92
|
self if self.member_type.equal?(member_type)
|
92
93
|
end
|
94
|
+
private_class_method :infer_from
|
93
95
|
|
94
96
|
# Instantiate a new type from a base type
|
95
97
|
#
|
@@ -104,6 +106,7 @@ module Axiom
|
|
104
106
|
def self.new_from(member_type)
|
105
107
|
new { member_type(member_type) } if base?
|
106
108
|
end
|
109
|
+
private_class_method :new_from
|
107
110
|
|
108
111
|
# Test if the type is a base type
|
109
112
|
#
|
@@ -113,6 +116,7 @@ module Axiom
|
|
113
116
|
def self.base?
|
114
117
|
# noop
|
115
118
|
end
|
119
|
+
private_class_method :base?
|
116
120
|
|
117
121
|
# Add a constraints for the member
|
118
122
|
#
|
@@ -125,8 +129,7 @@ module Axiom
|
|
125
129
|
end
|
126
130
|
end
|
127
131
|
|
128
|
-
private_class_method :
|
129
|
-
:new_from, :base?, :matches_member_type
|
132
|
+
private_class_method :matches_member_type
|
130
133
|
|
131
134
|
end # class Collection
|
132
135
|
end # module Types
|