axiom-types 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +37 -0
  3. data/.rspec +4 -0
  4. data/.rvmrc +1 -0
  5. data/.travis.yml +35 -0
  6. data/.yardopts +4 -0
  7. data/Gemfile +10 -0
  8. data/Gemfile.devtools +62 -0
  9. data/Guardfile +24 -0
  10. data/LICENSE +20 -0
  11. data/README.md +76 -0
  12. data/Rakefile +6 -0
  13. data/TODO +25 -0
  14. data/axiom-types.gemspec +26 -0
  15. data/config/flay.yml +3 -0
  16. data/config/flog.yml +2 -0
  17. data/config/mutant.yml +3 -0
  18. data/config/reek.yml +100 -0
  19. data/config/roodi.yml +16 -0
  20. data/config/yardstick.yml +2 -0
  21. data/lib/axiom-types.rb +3 -0
  22. data/lib/axiom/types.rb +65 -0
  23. data/lib/axiom/types/array.rb +13 -0
  24. data/lib/axiom/types/boolean.rb +14 -0
  25. data/lib/axiom/types/class.rb +13 -0
  26. data/lib/axiom/types/date.rb +18 -0
  27. data/lib/axiom/types/date_time.rb +21 -0
  28. data/lib/axiom/types/decimal.rb +13 -0
  29. data/lib/axiom/types/encodable.rb +75 -0
  30. data/lib/axiom/types/float.rb +13 -0
  31. data/lib/axiom/types/hash.rb +45 -0
  32. data/lib/axiom/types/integer.rb +13 -0
  33. data/lib/axiom/types/length_comparable.rb +51 -0
  34. data/lib/axiom/types/numeric.rb +13 -0
  35. data/lib/axiom/types/object.rb +36 -0
  36. data/lib/axiom/types/set.rb +13 -0
  37. data/lib/axiom/types/string.rb +18 -0
  38. data/lib/axiom/types/support/options.rb +129 -0
  39. data/lib/axiom/types/symbol.rb +18 -0
  40. data/lib/axiom/types/time.rb +22 -0
  41. data/lib/axiom/types/type.rb +136 -0
  42. data/lib/axiom/types/value_comparable.rb +49 -0
  43. data/lib/axiom/types/version.rb +10 -0
  44. data/spec/spec_helper.rb +37 -0
  45. data/spec/unit/axiom/types/class_methods/finalize_spec.rb +22 -0
  46. data/spec/unit/axiom/types/encodable/class_methods/extended_spec.rb +31 -0
  47. data/spec/unit/axiom/types/encodable/finalize_spec.rb +55 -0
  48. data/spec/unit/axiom/types/hash/class_methods/finalize_spec.rb +55 -0
  49. data/spec/unit/axiom/types/length_comparable/class_methods/extended_spec.rb +32 -0
  50. data/spec/unit/axiom/types/length_comparable/finalize_spec.rb +32 -0
  51. data/spec/unit/axiom/types/object/class_methods/coercion_method_spec.rb +27 -0
  52. data/spec/unit/axiom/types/object/class_methods/finalize_spec.rb +29 -0
  53. data/spec/unit/axiom/types/object/class_methods/primitive_spec.rb +27 -0
  54. data/spec/unit/axiom/types/options/accept_options_spec.rb +98 -0
  55. data/spec/unit/axiom/types/options/inherited_spec.rb +38 -0
  56. data/spec/unit/axiom/types/type/class_methods/constraint_spec.rb +32 -0
  57. data/spec/unit/axiom/types/type/class_methods/finalize_spec.rb +20 -0
  58. data/spec/unit/axiom/types/type/class_methods/include_predicate_spec.rb +25 -0
  59. data/spec/unit/axiom/types/type/class_methods/includes_spec.rb +45 -0
  60. data/spec/unit/axiom/types/type/class_methods/new_spec.rb +79 -0
  61. data/spec/unit/axiom/types/value_comparable/class_methods/extended_spec.rb +32 -0
  62. data/spec/unit/axiom/types/value_comparable/finalize_spec.rb +32 -0
  63. metadata +215 -0
@@ -0,0 +1,15 @@
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=
@@ -0,0 +1,37 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## Rubinius
17
+ *.rbc
18
+ .rbx
19
+
20
+ ## PROJECT::GENERAL
21
+ *.gem
22
+ coverage
23
+ profiling
24
+ turbulence
25
+ rdoc
26
+ pkg
27
+ tmp
28
+ doc
29
+ log
30
+ .yardoc
31
+ measurements
32
+
33
+ ## BUNDLER
34
+ .bundle
35
+ Gemfile.lock
36
+
37
+ ## PROJECT::SPECIFIC
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --color
2
+ --format progress
3
+ --profile
4
+ --order random
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use @$(basename `pwd`) --create
@@ -0,0 +1,35 @@
1
+ language: ruby
2
+ before_install: gem install bundler
3
+ bundler_args: --without yard guard benchmarks
4
+ script: "bundle exec rake ci"
5
+ rvm:
6
+ - ree
7
+ - 1.8.7
8
+ - 1.9.2
9
+ - 1.9.3
10
+ - 2.0.0
11
+ - ruby-head
12
+ - rbx-18mode
13
+ - rbx-19mode
14
+ notifications:
15
+ irc:
16
+ channels:
17
+ - "irc.freenode.org#datamapper"
18
+ on_success: never
19
+ on_failure: change
20
+ email:
21
+ recipients:
22
+ - dan.kubb@gmail.com
23
+ on_success: never
24
+ on_failure: change
25
+ matrix:
26
+ include:
27
+ - rvm: jruby-18mode
28
+ - rvm: jruby-19mode
29
+ env: JRUBY_OPTS="$JRUBY_OPTS --debug"
30
+ - rvm: jruby-head
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"
@@ -0,0 +1,4 @@
1
+ --quiet
2
+ README.md
3
+ lib/**/*.rb
4
+ LICENSE
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
6
+
7
+ gem 'coveralls', '~> 0.6.2'
8
+
9
+ gem 'devtools', :git => 'https://github.com/datamapper/devtools.git'
10
+ eval File.read('Gemfile.devtools')
@@ -0,0 +1,62 @@
1
+ # encoding: utf-8
2
+
3
+ group :development do
4
+ gem 'rake', '~> 10.0.3'
5
+ gem 'rspec', '~> 2.13.0'
6
+ gem 'yard', '~> 0.8.5'
7
+ end
8
+
9
+ group :yard do
10
+ gem 'kramdown', '~> 1.0.1'
11
+ end
12
+
13
+ group :guard do
14
+ gem 'guard', '~> 1.6.2'
15
+ gem 'guard-bundler', '~> 1.0.0'
16
+ gem 'guard-rspec', '~> 2.5.1'
17
+
18
+ # file system change event handling
19
+ gem 'rb-fchange', '~> 0.0.6', :require => false
20
+ gem 'rb-fsevent', '~> 0.9.3', :require => false
21
+ gem 'rb-inotify', '~> 0.9.0', :require => false
22
+
23
+ gem 'listen', '~> 0.7.3'
24
+
25
+ # notification handling
26
+ gem 'libnotify', '~> 0.8.0', :require => false
27
+ gem 'rb-notifu', '~> 0.0.4', :require => false
28
+ gem 'terminal-notifier-guard', '~> 1.5.3', :require => false
29
+ end
30
+
31
+ 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
42
+ gem 'yard-spellcheck', '~> 0.1.5'
43
+ end
44
+
45
+ platforms :mri_19, :rbx do
46
+ gem 'mutant', '~> 0.2.20'
47
+ end
48
+
49
+ platforms :rbx do
50
+ gem 'pelusa', '~> 0.2.2'
51
+ end
52
+ end
53
+
54
+ group :benchmarks do
55
+ gem 'rbench', '~> 0.2.3'
56
+ end
57
+
58
+ platform :jruby do
59
+ group :jruby do
60
+ gem 'jruby-openssl', '~> 0.8.2'
61
+ end
62
+ end
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+
3
+ guard :bundler do
4
+ watch('Gemfile')
5
+ watch('axiom-types.gemspec')
6
+ end
7
+
8
+ guard :rspec, :keep_failed => false do
9
+ # run all specs if configuration is modified
10
+ watch('Guardfile') { 'spec' }
11
+ watch('Gemfile.lock') { 'spec' }
12
+ watch('spec/spec_helper.rb') { 'spec' }
13
+
14
+ # run all specs if supporting files files are modified
15
+ watch(%r{\Aspec/(?:lib|support|shared)/.+\.rb\z}) { 'spec' }
16
+
17
+ # run unit specs if associated lib code is modified
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' }
21
+
22
+ # run a spec if it is modified
23
+ watch(%r{\Aspec/(?:unit|integration)/.+_spec\.rb\z})
24
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Dan Kubb
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,76 @@
1
+ [![Gem Version](https://badge.fury.io/rb/axiom-types.png)][gem]
2
+ [![Build Status](https://secure.travis-ci.org/dkubb/axiom-types.png?branch=master)][travis]
3
+ [![Dependency Status](https://gemnasium.com/dkubb/axiom-types.png)][gemnasium]
4
+ [![Code Climate](https://codeclimate.com/github/dkubb/axiom-types.png)][codeclimate]
5
+ [![Coverage Status](https://coveralls.io/repos/dkubb/axiom-types/badge.png?branch=master)][coveralls]
6
+
7
+ [gem]: https://rubygems.org/gems/axiom-types
8
+ [travis]: https://travis-ci.org/dkubb/axiom-types
9
+ [gemnasium]: https://gemnasium.com/dkubb/axiom-types
10
+ [codeclimate]: https://codeclimate.com/github/dkubb/axiom-types
11
+ [coveralls]: https://coveralls.io/r/dkubb/axiom-types
12
+
13
+ axiom-types
14
+ ===========
15
+
16
+ Define types with optional constraints for use within axiom and other libraries.
17
+
18
+ Examples
19
+ --------
20
+
21
+ ```ruby
22
+ # Setup constraints for all defined types
23
+ Axiom::Types.finalize
24
+
25
+ # Create Name subtype
26
+ Name = Axiom::Types::String.new do
27
+ minimum_length 1
28
+ maximum_length 30
29
+ end
30
+
31
+ # Test if the string is a member of the type
32
+ Name.include?('a') # => true
33
+ Name.include?('a' * 30) # => true
34
+ Name.include?('') # => false
35
+ Name.include?('a' * 31) # => false
36
+ ```
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
+ Contributing
62
+ -------------
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.
72
+
73
+ Copyright
74
+ ---------
75
+
76
+ Copyright © 2013 Dan Kubb. See LICENSE for details.
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rake'
4
+ require 'devtools'
5
+
6
+ Devtools.init_rake_tasks
data/TODO ADDED
@@ -0,0 +1,25 @@
1
+ TODO
2
+ ----
3
+
4
+ * Add mechanism to find best matching type for a given primitive.
5
+
6
+ * Add finite limits to all "primitive" types.
7
+
8
+ * Add optional constraint on Date for the timezone
9
+ * Add optional constraint on DateTime for the timezone
10
+ * Add optional constraint on Time for the timezone
11
+ * Add optional regexp constraint to String
12
+ * format /\A[a-z]+\z/
13
+ * Add optional allowed characters constraint to String
14
+ * allowed_characters 'a', 'b', 'c'
15
+ * allowed_characters 'a'..'c'
16
+ * allowed_characters 'a'..'c', 'e', 'f', 'g', 'i'
17
+ * allowed_characters 'a'..'c', 'e'..'g', 'i'
18
+
19
+ * When axiom-logic is available, replace the Proc based constraints with real
20
+ predicates so that they can be serialized into SQL or optimized, etc.
21
+ * 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.
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../lib/axiom/types/version', __FILE__)
4
+
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'
13
+
14
+ gem.require_paths = %w[lib]
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.test_files = `git ls-files spec/{unit,integration}`.split($/)
17
+ gem.extra_rdoc_files = %w[LICENSE README.md TODO]
18
+
19
+ gem.add_runtime_dependency('backports', '~> 3.1', '>= 3.1.1')
20
+ gem.add_runtime_dependency('descendants_tracker', '~> 0.0.1')
21
+ gem.add_runtime_dependency('ice_nine', '~> 0.7.0')
22
+
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')
26
+ end
@@ -0,0 +1,3 @@
1
+ ---
2
+ threshold: 14
3
+ total_score: 82
@@ -0,0 +1,2 @@
1
+ ---
2
+ threshold: 11.6
@@ -0,0 +1,3 @@
1
+ ---
2
+ name: axiom-types
3
+ namespace: Axiom::Types
@@ -0,0 +1,100 @@
1
+ ---
2
+ UncommunicativeParameterName:
3
+ accept: []
4
+ exclude: []
5
+ enabled: true
6
+ reject:
7
+ - !ruby/regexp /^.$/
8
+ - !ruby/regexp /[0-9]$/
9
+ - !ruby/regexp /[A-Z]/
10
+ LargeClass:
11
+ max_methods: 0
12
+ exclude: []
13
+ enabled: true
14
+ max_instance_variables: 1
15
+ UncommunicativeMethodName:
16
+ accept: []
17
+ exclude: []
18
+ 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
+ exclude: []
26
+ enabled: true
27
+ overrides: {}
28
+ FeatureEnvy:
29
+ exclude:
30
+ - Axiom::Types::Encodable#has_encoding
31
+ enabled: true
32
+ ClassVariable:
33
+ exclude: []
34
+ enabled: true
35
+ BooleanParameter:
36
+ exclude: []
37
+ enabled: true
38
+ IrresponsibleModule:
39
+ exclude: []
40
+ enabled: true
41
+ UncommunicativeModuleName:
42
+ accept: []
43
+ exclude: []
44
+ enabled: true
45
+ reject:
46
+ - !ruby/regexp /^.$/
47
+ - !ruby/regexp /[0-9]$/
48
+ NestedIterators:
49
+ ignore_iterators: []
50
+ exclude:
51
+ - Axiom::Types::Hash#self.matches
52
+ enabled: true
53
+ max_allowed_nesting: 1
54
+ LongMethod:
55
+ max_statements: 5
56
+ exclude: []
57
+ enabled: true
58
+ Duplication:
59
+ allow_calls: []
60
+ exclude: []
61
+ enabled: true
62
+ max_calls: 1
63
+ UtilityFunction:
64
+ max_helper_calls: 0
65
+ exclude: []
66
+ enabled: true
67
+ Attribute:
68
+ exclude: []
69
+ enabled: false
70
+ UncommunicativeVariableName:
71
+ accept: []
72
+ exclude: []
73
+ enabled: true
74
+ reject:
75
+ - !ruby/regexp /^.$/
76
+ - !ruby/regexp /[0-9]$/
77
+ - !ruby/regexp /[A-Z]/
78
+ SimulatedPolymorphism:
79
+ exclude: []
80
+ enabled: true
81
+ max_ifs: 1
82
+ DataClump:
83
+ exclude: []
84
+ enabled: true
85
+ max_copies: 0
86
+ min_clump_size: 2
87
+ ControlCouple:
88
+ exclude: []
89
+ enabled: true
90
+ LongYieldList:
91
+ max_params: 0
92
+ exclude: []
93
+ enabled: true
94
+ UnusedParameters:
95
+ enabled: true
96
+ exclude: []
97
+ NilCheck:
98
+ enabled: true
99
+ exclude:
100
+ - Axiom::Types::Type#self.constraint