axiom-types 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +6 -14
  2. data/.gitignore +1 -1
  3. data/.ruby-gemset +1 -0
  4. data/.travis.yml +2 -6
  5. data/CONTRIBUTING.md +11 -0
  6. data/Gemfile +1 -3
  7. data/Gemfile.devtools +17 -19
  8. data/README.md +1 -8
  9. data/Rakefile +0 -1
  10. data/TODO +0 -6
  11. data/axiom-types.gemspec +12 -13
  12. data/config/devtools.yml +2 -0
  13. data/config/flay.yml +1 -1
  14. data/config/flog.yml +1 -1
  15. data/config/reek.yml +67 -60
  16. data/lib/axiom/types.rb +26 -1
  17. data/lib/axiom/types/array.rb +12 -1
  18. data/lib/axiom/types/boolean.rb +17 -0
  19. data/lib/axiom/types/collection.rb +133 -0
  20. data/lib/axiom/types/hash.rb +80 -2
  21. data/lib/axiom/types/object.rb +34 -2
  22. data/lib/axiom/types/set.rb +12 -1
  23. data/lib/axiom/types/support/options.rb +13 -1
  24. data/lib/axiom/types/type.rb +17 -2
  25. data/lib/axiom/types/version.rb +1 -1
  26. data/spec/spec_helper.rb +14 -5
  27. data/spec/unit/axiom/types/array/class_methods/infer_spec.rb +99 -0
  28. data/spec/unit/axiom/types/boolean/class_methods/infer_spec.rb +33 -0
  29. data/spec/unit/axiom/types/class_methods/finalize_spec.rb +2 -7
  30. data/spec/unit/axiom/types/class_methods/infer_spec.rb +54 -0
  31. data/spec/unit/axiom/types/collection/class_methods/finalize_spec.rb +49 -0
  32. data/spec/unit/axiom/types/collection/class_methods/infer_spec.rb +111 -0
  33. data/spec/unit/axiom/types/hash/class_methods/infer_spec.rb +175 -0
  34. data/spec/unit/axiom/types/object/class_methods/infer_spec.rb +52 -0
  35. data/spec/unit/axiom/types/options/inherited_spec.rb +36 -10
  36. data/spec/unit/axiom/types/set/class_methods/infer_spec.rb +99 -0
  37. data/spec/unit/axiom/types/type/class_methods/constraint_spec.rb +66 -4
  38. data/spec/unit/axiom/types/type/class_methods/infer_spec.rb +25 -0
  39. data/spec/unit/axiom/types/type/class_methods/new_spec.rb +4 -0
  40. metadata +44 -44
  41. data/.rvmrc +0 -1
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ODQxZTk1YzZmZDU0YjMyNTU1ZmMzNzI4ZWY2YzA5ZGZmODFmNTU4ZA==
5
- data.tar.gz: !binary |-
6
- YzU3ZjcxZjZjYzQwZGVkODY5YTgyM2YzNjI5Y2YzMmVlMjRlYTI0Yg==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- NGYzODhiZmE3NzA2ODI0MWUyZjQ5ZTBjNTBiMDljNWYxOWQ3MTZjZmI1ODVh
10
- MmYyNDcyNzcwMTNlZTgxNmE1MTc3MzFlNDRiNWI4YzhkNGZjZmJiMzUxZjcw
11
- NTFlMThkNWM5NTM3MDUyOWMxN2NmMTYxODRiNTBlNGFhYzhmOTg=
12
- data.tar.gz: !binary |-
13
- MWNkMmEwZTQ4NmMzZTc0YmRhYTI0YTE4ZjM4Yzk3YmQ4MjRhOWM4NTBhNTlk
14
- MzU2MjhhNTYxZmI4NTc4ZmZmNWNmMWUxNjBkNTU3ZjJjOGQzZjVjOWQ1MzEx
15
- MWFhZDA2N2MzMDRmNGE1YWFkZDc0MWZhYmIyOWNmZDlhOTg5ODg=
2
+ SHA1:
3
+ metadata.gz: 0654768ee346ef4d7c2ee67b09c6689a8d6511a7
4
+ data.tar.gz: edca992fe60fe03b32b5fe64e72889c228d5eaf3
5
+ SHA512:
6
+ metadata.gz: 0b028989bca769e2c8f50c8d8fd6ed2ebe3b4b11f162ee84973e91a4602c3de65a2d6f6c79ee76de021578cdc10e04f6371f8337f40bf4569aa4bfe08ace4d41
7
+ data.tar.gz: 8233f236b4b993d2774fb4cdbe00de69ae1713700c1d52433af60ce8ee735537a137d6f73e42792839d2b4efb8265f05ea64ee7f5f625fddf91ce0a1770450ba
data/.gitignore CHANGED
@@ -11,7 +11,7 @@ tmtags
11
11
  .\#*
12
12
 
13
13
  ## VIM
14
- *.swp
14
+ *.sw[op]
15
15
 
16
16
  ## Rubinius
17
17
  *.rbc
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ axiom-types
data/.travis.yml CHANGED
@@ -11,10 +11,11 @@ rvm:
11
11
  - ruby-head
12
12
  - rbx-18mode
13
13
  - rbx-19mode
14
+ - jruby-18mode
14
15
  notifications:
15
16
  irc:
16
17
  channels:
17
- - "irc.freenode.org#datamapper"
18
+ - irc.freenode.org#rom-rb
18
19
  on_success: never
19
20
  on_failure: change
20
21
  email:
@@ -24,12 +25,7 @@ notifications:
24
25
  on_failure: change
25
26
  matrix:
26
27
  include:
27
- - rvm: jruby-18mode
28
28
  - rvm: jruby-19mode
29
29
  env: JRUBY_OPTS="$JRUBY_OPTS --debug"
30
30
  - rvm: jruby-head
31
31
  env: JRUBY_OPTS="$JRUBY_OPTS --debug"
32
- allow_failures:
33
- # yard parser fails
34
- - rvm: jruby-head
35
- env: JRUBY_OPTS="$JRUBY_OPTS --debug"
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,11 @@
1
+ Contributing
2
+ ------------
3
+
4
+ * 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
+ * Fork the project.
6
+ * Make your feature addition or bug fix.
7
+ * Follow this [style guide](https://github.com/dkubb/styleguide).
8
+ * Add specs for it. This is important so I don't break it in a future version unintentionally. Tests must cover all branches within the code, and code must be fully covered.
9
+ * Commit, do not mess with Rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
10
+ * Run "rake ci". This must pass and not show any regressions in the metrics for the code to be merged.
11
+ * Send me a pull request. Bonus points for topic branches.
data/Gemfile CHANGED
@@ -4,7 +4,5 @@ source 'https://rubygems.org'
4
4
 
5
5
  gemspec
6
6
 
7
- gem 'coveralls', '~> 0.6.2'
8
-
9
- gem 'devtools', :git => 'https://github.com/datamapper/devtools.git'
7
+ gem 'devtools', :git => 'https://github.com/rom-rb/devtools.git'
10
8
  eval File.read('Gemfile.devtools')
data/Gemfile.devtools CHANGED
@@ -1,9 +1,9 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  group :development do
4
- gem 'rake', '~> 10.0.3'
4
+ gem 'rake', '~> 10.1.0'
5
5
  gem 'rspec', '~> 2.13.0'
6
- gem 'yard', '~> 0.8.5'
6
+ gem 'yard', '~> 0.8.6.1'
7
7
  end
8
8
 
9
9
  group :yard do
@@ -11,17 +11,16 @@ group :yard do
11
11
  end
12
12
 
13
13
  group :guard do
14
- gem 'guard', '~> 1.6.2'
14
+ gem 'guard', '~> 1.8.1'
15
15
  gem 'guard-bundler', '~> 1.0.0'
16
- gem 'guard-rspec', '~> 2.5.1'
16
+ gem 'guard-rspec', '~> 3.0.2'
17
17
 
18
18
  # file system change event handling
19
+ gem 'listen', '~> 1.2.2'
19
20
  gem 'rb-fchange', '~> 0.0.6', :require => false
20
21
  gem 'rb-fsevent', '~> 0.9.3', :require => false
21
22
  gem 'rb-inotify', '~> 0.9.0', :require => false
22
23
 
23
- gem 'listen', '~> 0.7.3'
24
-
25
24
  # notification handling
26
25
  gem 'libnotify', '~> 0.8.0', :require => false
27
26
  gem 'rb-notifu', '~> 0.0.4', :require => false
@@ -29,21 +28,20 @@ group :guard do
29
28
  end
30
29
 
31
30
  group :metrics do
32
- gem 'backports', '~> 3.1', '>= 3.1.1'
33
- gem 'flay', '~> 2.1.0'
34
- gem 'flog', '~> 3.2.2'
35
- gem 'reek', '~> 1.3.1', :git => 'https://github.com/troessner/reek.git'
36
- gem 'metric_fu-roodi', '~> 2.2.1'
37
- gem 'simplecov', '~> 0.7.1'
38
- gem 'yardstick', '~> 0.9.4'
39
-
40
- platforms :ruby_18, :ruby_19 do
41
- # this indirectly depends on ffi which does not build on ruby-head
31
+ gem 'backports', '~> 3.3', '>= 3.3.2'
32
+ gem 'coveralls', '~> 0.6.7'
33
+ gem 'flay', '~> 2.3.0'
34
+ gem 'flog', '~> 4.1.0'
35
+ gem 'reek', '~> 1.3.1', :git => 'https://github.com/troessner/reek.git'
36
+ gem 'simplecov', '~> 0.7.1'
37
+ gem 'yardstick', '~> 0.9.6'
38
+
39
+ platforms :ruby_19 do
42
40
  gem 'yard-spellcheck', '~> 0.1.5'
43
41
  end
44
42
 
45
- platforms :mri_19, :rbx do
46
- gem 'mutant', '~> 0.2.20'
43
+ platforms :ruby_19, :ruby_20 do
44
+ gem 'mutant', '~> 0.3.0.beta4'
47
45
  end
48
46
 
49
47
  platforms :rbx do
@@ -57,6 +55,6 @@ end
57
55
 
58
56
  platform :jruby do
59
57
  group :jruby do
60
- gem 'jruby-openssl', '~> 0.8.2'
58
+ gem 'jruby-openssl', '~> 0.8.5'
61
59
  end
62
60
  end
data/README.md CHANGED
@@ -61,14 +61,7 @@ $ irb -rubygems
61
61
  Contributing
62
62
  -------------
63
63
 
64
- * 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.
65
- * Fork the project.
66
- * Make your feature addition or bug fix.
67
- * Follow this [style guide](https://github.com/dkubb/styleguide).
68
- * Add specs for it. This is important so I don't break it in a future version unintentionally. Tests must cover all branches within the code, and code must be fully covered.
69
- * Commit, do not mess with Rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
70
- * Run "rake ci". This must pass and not show any regressions in the metrics for the code to be merged.
71
- * Send me a pull request. Bonus points for topic branches.
64
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
72
65
 
73
66
  Copyright
74
67
  ---------
data/Rakefile CHANGED
@@ -1,6 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'rake'
4
3
  require 'devtools'
5
4
 
6
5
  Devtools.init_rake_tasks
data/TODO CHANGED
@@ -1,8 +1,6 @@
1
1
  TODO
2
2
  ----
3
3
 
4
- * Add mechanism to find best matching type for a given primitive.
5
-
6
4
  * Add finite limits to all "primitive" types.
7
5
 
8
6
  * Add optional constraint on Date for the timezone
@@ -19,7 +17,3 @@ TODO
19
17
  * When axiom-logic is available, replace the Proc based constraints with real
20
18
  predicates so that they can be serialized into SQL or optimized, etc.
21
19
  * Can be performed as part of type finalization
22
-
23
- * Create a factory method for the Hash type
24
- * Make sure the primitive lookup system can use the key/value to find the best
25
- match for a given Hash type.
data/axiom-types.gemspec CHANGED
@@ -3,24 +3,23 @@
3
3
  require File.expand_path('../lib/axiom/types/version', __FILE__)
4
4
 
5
5
  Gem::Specification.new do |gem|
6
- gem.name = 'axiom-types'
7
- gem.version = Axiom::Types::VERSION.dup
8
- gem.authors = ['Dan Kubb']
9
- gem.email = 'dan.kubb@gmail.com'
10
- gem.description = 'Abstract types for logic programming'
11
- gem.summary = gem.description
12
- gem.homepage = 'https://github.com/dkubb/axiom-types'
6
+ gem.name = 'axiom-types'
7
+ gem.version = Axiom::Types::VERSION.dup
8
+ gem.authors = ['Dan Kubb']
9
+ gem.email = 'dan.kubb@gmail.com'
10
+ gem.description = 'Abstract types for logic programming'
11
+ gem.summary = 'Define types with optional constraints for use within axiom and other libraries.'
12
+ gem.homepage = 'https://github.com/dkubb/axiom-types'
13
+ gem.licenses = %w[MIT]
13
14
 
14
15
  gem.require_paths = %w[lib]
15
16
  gem.files = `git ls-files`.split($/)
16
- gem.test_files = `git ls-files spec/{unit,integration}`.split($/)
17
+ gem.test_files = `git ls-files -- spec/unit`.split($/)
17
18
  gem.extra_rdoc_files = %w[LICENSE README.md TODO]
18
19
 
19
- gem.add_runtime_dependency('backports', '~> 3.1', '>= 3.1.1')
20
+ gem.add_runtime_dependency('backports', '~> 3.3', '>= 3.3.2')
20
21
  gem.add_runtime_dependency('descendants_tracker', '~> 0.0.1')
21
- gem.add_runtime_dependency('ice_nine', '~> 0.7.0')
22
+ gem.add_runtime_dependency('ice_nine', '~> 0.8.0')
22
23
 
23
- gem.add_development_dependency('rake', '~> 10.0.3')
24
- gem.add_development_dependency('rspec', '~> 2.13.0')
25
- gem.add_development_dependency('yard', '~> 0.8.5')
24
+ gem.add_development_dependency('bundler', '~> 1.3', '>= 1.3.5')
26
25
  end
@@ -0,0 +1,2 @@
1
+ ---
2
+ unit_test_timeout: 0.1
data/config/flay.yml CHANGED
@@ -1,3 +1,3 @@
1
1
  ---
2
2
  threshold: 14
3
- total_score: 82
3
+ total_score: 135
data/config/flog.yml CHANGED
@@ -1,2 +1,2 @@
1
1
  ---
2
- threshold: 11.6
2
+ threshold: 9.1
data/config/reek.yml CHANGED
@@ -1,100 +1,107 @@
1
1
  ---
2
- UncommunicativeParameterName:
3
- accept: []
4
- exclude: []
2
+ Attribute:
5
3
  enabled: true
6
- reject:
7
- - !ruby/regexp /^.$/
8
- - !ruby/regexp /[0-9]$/
9
- - !ruby/regexp /[A-Z]/
10
- LargeClass:
11
- max_methods: 0
12
4
  exclude: []
5
+ BooleanParameter:
13
6
  enabled: true
14
- max_instance_variables: 1
15
- UncommunicativeMethodName:
16
- accept: []
17
7
  exclude: []
8
+ ClassVariable:
18
9
  enabled: true
19
- reject:
20
- - !ruby/regexp /^[a-z]$/
21
- - !ruby/regexp /[0-9]$/
22
- - !ruby/regexp /[A-Z]/
23
- LongParameterList:
24
- max_params: 2
25
10
  exclude: []
11
+ ControlParameter:
26
12
  enabled: true
27
- overrides: {}
28
- FeatureEnvy:
29
- exclude:
30
- - Axiom::Types::Encodable#has_encoding
13
+ exclude: []
14
+ DataClump:
31
15
  enabled: true
32
- ClassVariable:
33
16
  exclude: []
17
+ max_copies: 0
18
+ min_clump_size: 2
19
+ DuplicateMethodCall:
34
20
  enabled: true
35
- BooleanParameter:
36
21
  exclude: []
22
+ max_calls: 1
23
+ allow_calls: []
24
+ FeatureEnvy:
37
25
  enabled: true
26
+ exclude:
27
+ - Axiom::Types::Encodable#has_encoding
38
28
  IrresponsibleModule:
29
+ enabled: true
39
30
  exclude: []
31
+ LongParameterList:
40
32
  enabled: true
41
- UncommunicativeModuleName:
42
- accept: []
43
33
  exclude: []
34
+ max_params: 2
35
+ overrides:
36
+ initialize:
37
+ max_params: 3
38
+ LongYieldList:
44
39
  enabled: true
45
- reject:
46
- - !ruby/regexp /^.$/
47
- - !ruby/regexp /[0-9]$/
40
+ exclude: []
41
+ max_params: 2
48
42
  NestedIterators:
43
+ enabled: true
44
+ exclude:
45
+ - Axiom::Types::Hash#self.matches_key_and_value_types
46
+ - Axiom::Types::Collection#self.matches_member_type
47
+ max_allowed_nesting: 1
49
48
  ignore_iterators: []
49
+ NilCheck:
50
+ enabled: true
50
51
  exclude:
51
- - Axiom::Types::Hash#self.matches
52
+ - Axiom::Types::Type#self.constraint
53
+ RepeatedConditional:
52
54
  enabled: true
53
- max_allowed_nesting: 1
54
- LongMethod:
55
- max_statements: 5
56
55
  exclude: []
56
+ max_ifs: 1
57
+ TooManyInstanceVariables:
57
58
  enabled: true
58
- Duplication:
59
- allow_calls: []
60
59
  exclude: []
60
+ max_instance_variables: 1
61
+ TooManyMethods:
61
62
  enabled: true
62
- max_calls: 1
63
- UtilityFunction:
64
- max_helper_calls: 0
65
63
  exclude: []
64
+ max_methods: 0
65
+ TooManyStatements:
66
66
  enabled: true
67
- Attribute:
68
- exclude: []
69
- enabled: false
70
- UncommunicativeVariableName:
71
- accept: []
72
- exclude: []
67
+ exclude:
68
+ - each
69
+ max_statements: 5
70
+ UncommunicativeMethodName:
73
71
  enabled: true
74
- reject:
75
- - !ruby/regexp /^.$/
76
- - !ruby/regexp /[0-9]$/
77
- - !ruby/regexp /[A-Z]/
78
- SimulatedPolymorphism:
79
72
  exclude: []
73
+ reject:
74
+ - !ruby/regexp /^[a-z]$/
75
+ - !ruby/regexp /[0-9]$/
76
+ - !ruby/regexp /[A-Z]/
77
+ accept: []
78
+ UncommunicativeModuleName:
80
79
  enabled: true
81
- max_ifs: 1
82
- DataClump:
83
80
  exclude: []
81
+ reject:
82
+ - !ruby/regexp /^.$/
83
+ - !ruby/regexp /[0-9]$/
84
+ accept: []
85
+ UncommunicativeParameterName:
84
86
  enabled: true
85
- max_copies: 0
86
- min_clump_size: 2
87
- ControlCouple:
88
87
  exclude: []
88
+ reject:
89
+ - !ruby/regexp /^.$/
90
+ - !ruby/regexp /[0-9]$/
91
+ - !ruby/regexp /[A-Z]/
92
+ accept: []
93
+ UncommunicativeVariableName:
89
94
  enabled: true
90
- LongYieldList:
91
- max_params: 0
92
95
  exclude: []
93
- enabled: true
96
+ reject:
97
+ - !ruby/regexp /^.$/
98
+ - !ruby/regexp /[0-9]$/
99
+ - !ruby/regexp /[A-Z]/
100
+ accept: []
94
101
  UnusedParameters:
95
102
  enabled: true
96
103
  exclude: []
97
- NilCheck:
104
+ UtilityFunction:
98
105
  enabled: true
99
- exclude:
100
- - Axiom::Types::Type#self.constraint
106
+ exclude: []
107
+ max_helper_calls: 0
data/lib/axiom/types.rb CHANGED
@@ -20,12 +20,36 @@ module Axiom
20
20
  # A false proposition
21
21
  Contradiction = proc { false }.freeze
22
22
 
23
+ # Cache the type inference lookup by object
24
+ @inference_cache = Hash.new do |cache, object|
25
+ type = nil
26
+ Type.descendants.each do |descendant|
27
+ break if type = descendant.infer(object)
28
+ end
29
+ cache[object] = type
30
+ end
31
+
32
+ # Infer the type of an object
33
+ #
34
+ # @example
35
+ # Axiom::Types.infer(Integer) # => Axiom::Types::Integer
36
+ #
37
+ # @param [Object] object
38
+ # object to infer the type of
39
+ #
40
+ # @return [Class<Axiom::Types::Type>]
41
+ #
42
+ # @api public
43
+ def self.infer(object)
44
+ @inference_cache[object]
45
+ end
46
+
23
47
  # Finalize Axiom::Types::Type subclasses
24
48
  #
25
49
  # @example
26
50
  # Axiom::Types.finalize # => Axiom::Types
27
51
  #
28
- # @return [Axiom::Types]
52
+ # @return [Module<Axiom::Types>]
29
53
  #
30
54
  # @api public
31
55
  def self.finalize
@@ -46,6 +70,7 @@ require 'axiom/types/type'
46
70
 
47
71
  require 'axiom/types/object'
48
72
 
73
+ require 'axiom/types/collection'
49
74
  require 'axiom/types/numeric'
50
75
 
51
76
  require 'axiom/types/array'