Permalink
Browse files

Refactor library

* Remove all stuff I do not need for my next project. Most likely no one
  other can use this in current state
* Introduce some basic algebra for matchers that does allow future
  serialization to javascript
* Improve yard coverage to 100%
* Enable all reek checks
* Enable all roodi checks
* Adjust flay scores down a huge step!
* Adjust flog scores down a huge step!
* Lost most unit specs. Refactoring gone to far. MUTANT MUTANT.
* Port library to rspec2, sorry minitest your where to verbose.
  • Loading branch information...
1 parent 9c61dca commit a54f8c091a8bf7a2f5f4df18d2343afb365a8440 Markus Schirp committed Nov 12, 2012
Showing with 2,389 additions and 3,019 deletions.
  1. +2 −0 .rspec
  2. +15 −14 Gemfile
  3. +1 −1 Guardfile
  4. +1 −0 TODO
  5. +2 −2 config/flay.yml
  6. +1 −1 config/flog.yml
  7. +2 −2 config/roodi.yml
  8. +16 −15 config/site.reek
  9. +1 −1 config/yardstick.yml
  10. +34 −37 lib/aequitas.rb
  11. +14 −0 lib/aequitas/builder.rb
  12. +183 −0 lib/aequitas/builder/nullary.rb
  13. +46 −6 lib/aequitas/class_methods.rb
  14. +67 −0 lib/aequitas/dsl.rb
  15. +67 −2 lib/aequitas/evaluator.rb
  16. +0 −10 lib/aequitas/exceptions.rb
  17. +0 −53 lib/aequitas/guard.rb
  18. +27 −28 lib/aequitas/instance_methods.rb
  19. +0 −362 lib/aequitas/macros.rb
  20. +19 −0 lib/aequitas/matcher.rb
  21. +59 −0 lib/aequitas/matcher/binary.rb
  22. +20 −0 lib/aequitas/matcher/binary/and.rb
  23. +20 −0 lib/aequitas/matcher/binary/or.rb
  24. +22 −0 lib/aequitas/matcher/binary/xor.rb
  25. +35 −0 lib/aequitas/matcher/nullary.rb
  26. +46 −0 lib/aequitas/matcher/nullary/equality.rb
  27. +126 −0 lib/aequitas/matcher/nullary/format.rb
  28. +45 −0 lib/aequitas/matcher/nullary/greater_than.rb
  29. +67 −0 lib/aequitas/matcher/nullary/inclusion.rb
  30. +48 −0 lib/aequitas/matcher/nullary/less_than.rb
  31. +47 −0 lib/aequitas/matcher/nullary/primitive.rb
  32. +44 −0 lib/aequitas/matcher/nullary/proc.rb
  33. +32 −0 lib/aequitas/matcher/nullary/value.rb
  34. +45 −0 lib/aequitas/matcher/unary.rb
  35. +49 −0 lib/aequitas/matcher/unary/attribute.rb
  36. +25 −0 lib/aequitas/matcher/unary/not.rb
  37. +80 −0 lib/aequitas/result.rb
  38. +19 −133 lib/aequitas/rule.rb
  39. +0 −9 lib/aequitas/rule/absence.rb
  40. +0 −16 lib/aequitas/rule/absence/blank.rb
  41. +0 −20 lib/aequitas/rule/absence/nil.rb
  42. +0 −27 lib/aequitas/rule/acceptance.rb
  43. +0 −36 lib/aequitas/rule/confirmation.rb
  44. +0 −60 lib/aequitas/rule/format.rb
  45. +0 −54 lib/aequitas/rule/format/email_address.rb
  46. +0 −15 lib/aequitas/rule/format/proc.rb
  47. +0 −34 lib/aequitas/rule/format/regexp.rb
  48. +0 −16 lib/aequitas/rule/format/url.rb
  49. +0 −29 lib/aequitas/rule/inclusion.rb
  50. +0 −74 lib/aequitas/rule/length.rb
  51. +0 −53 lib/aequitas/rule/length/equal.rb
  52. +0 −39 lib/aequitas/rule/length/maximum.rb
  53. +0 −39 lib/aequitas/rule/length/minimum.rb
  54. +0 −39 lib/aequitas/rule/length/range.rb
  55. +71 −0 lib/aequitas/rule/nullary.rb
  56. +69 −0 lib/aequitas/rule/nullary/attribute.rb
  57. +19 −0 lib/aequitas/rule/nullary/attribute/absence.rb
  58. +46 −0 lib/aequitas/rule/nullary/attribute/format.rb
  59. +62 −0 lib/aequitas/rule/nullary/attribute/inclusion.rb
  60. +171 −0 lib/aequitas/rule/nullary/attribute/length.rb
  61. +32 −0 lib/aequitas/rule/nullary/attribute/presence.rb
  62. 0 lib/aequitas/rule/nullary/attribute/presence/not_blank.rb
  63. 0 lib/aequitas/rule/nullary/attribute/presence/not_nil.rb
  64. +35 −0 lib/aequitas/rule/nullary/attribute/primitive.rb
  65. +220 −0 lib/aequitas/rule/nullary/confirmation.rb
  66. +0 −55 lib/aequitas/rule/numericalness.rb
  67. +0 −16 lib/aequitas/rule/numericalness/integer.rb
  68. +0 −44 lib/aequitas/rule/numericalness/non_integer.rb
  69. +0 −9 lib/aequitas/rule/presence.rb
  70. +0 −16 lib/aequitas/rule/presence/not_blank.rb
  71. +0 −20 lib/aequitas/rule/presence/not_nil.rb
  72. +0 −56 lib/aequitas/rule/primitive_type.rb
  73. +0 −25 lib/aequitas/rule/primitive_type/virtus.rb
  74. 0 lib/aequitas/rule/unary.rb
  75. +0 −172 lib/aequitas/rule/value.rb
  76. +0 −23 lib/aequitas/rule/value/equal.rb
  77. +0 −23 lib/aequitas/rule/value/greater_than.rb
  78. +0 −23 lib/aequitas/rule/value/greater_than_or_equal.rb
  79. +0 −23 lib/aequitas/rule/value/less_than.rb
  80. +0 −23 lib/aequitas/rule/value/less_than_or_equal.rb
  81. +0 −23 lib/aequitas/rule/value/not_equal.rb
  82. +0 −20 lib/aequitas/rule/value/range.rb
  83. +0 −137 lib/aequitas/rule_set.rb
  84. +107 −0 lib/aequitas/validator.rb
  85. +1 −1 lib/aequitas/version.rb
  86. +7 −6 lib/aequitas/violation.rb
  87. +0 −101 lib/aequitas/violation_set.rb
  88. +3 −1 spec/integration/aequitas/{macros → dsl}/validates_absence_of_spec.rb
  89. +3 −1 spec/integration/aequitas/{macros → dsl}/validates_acceptance_of_spec.rb
  90. +27 −0 spec/integration/aequitas/dsl/validates_confirmation_of_spec.rb
  91. +11 −17 spec/integration/aequitas/{macros → dsl}/validates_format_of_spec.rb
  92. +3 −1 spec/integration/aequitas/{macros → dsl}/validates_inclusion_of_spec.rb
  93. +11 −9 spec/integration/aequitas/{macros → dsl}/validates_length_of_spec.rb
  94. +3 −1 spec/integration/aequitas/{macros → dsl}/validates_presence_of_spec.rb
  95. +7 −2 spec/integration/aequitas/{macros → dsl}/validates_value_of_spec.rb
  96. +0 −23 spec/integration/aequitas/macros/validates_confirmation_of_spec.rb
  97. +0 −294 spec/integration/aequitas/macros/validates_numericalness_of_spec.rb
  98. +9 −18 spec/integration/aequitas/validator_spec.rb
  99. +75 −0 spec/shared/dsl_spec.rb
  100. +0 −93 spec/shared/integration_spec.rb
  101. +2 −5 spec/spec_helper.rb
  102. +16 −15 spec/unit/aequitas/class_methods/inherited_spec.rb
  103. +0 −119 spec/unit/aequitas/guard_spec.rb
  104. +0 −50 spec/unit/aequitas/rule/absence/blank/valid_value_spec.rb
  105. +0 −15 spec/unit/aequitas/rule/absence/blank_spec.rb
  106. +0 −24 spec/unit/aequitas/rule/acceptance/valid_value_spec.rb
  107. +0 −53 spec/unit/aequitas/rule/acceptance_spec.rb
  108. +0 −49 spec/unit/aequitas/rule/confirmation/validate_spec.rb
  109. +0 −15 spec/unit/aequitas/rule/confirmation_spec.rb
  110. +0 −22 spec/unit/aequitas/rule_spec.rb
  111. +52 −63 spec/unit/aequitas/support/blank_spec.rb
  112. +0 −86 spec/unit/aequitas/violation_set_spec.rb
View
2 .rspec
@@ -0,0 +1,2 @@
+--color
+--fail-fast
View
29 Gemfile
@@ -2,32 +2,33 @@ source 'https://rubygems.org'
gemspec
-gem 'adamantium', :git => 'https://github.com/mbj/adamantium.git', :branch => :'configurable-freezers'
+gem 'adamantium', :git => 'https://github.com/dkubb/adamantium.git'
gem 'descendants_tracker', :git => 'https://github.com/dkubb/descendants_tracker.git'
gem 'abstract_class', :git => 'https://github.com/dkubb/abstract_class.git'
gem 'equalizer', :git => 'https://github.com/dkubb/equalizer.git'
group :development do
- gem 'rake', '~> 0.9.2'
- gem 'yard', '~> 0.8.1'
- gem 'minitest'
+ gem 'rake', '~> 0.9.2'
+ gem 'yard', '~> 0.8.1'
+ gem 'rspec', '~> 2'
+ gem 'rspec-mocks', '~> 2'
end
group :guard do
- gem 'guard', '~> 1.4.0'
- gem 'guard-bundler'
- gem 'guard-minitest'
+ gem 'guard', '~> 1.5.4'
+ gem 'guard-bundler', '~> 1.0.0'
+ gem 'guard-rspec', '~> 1.2.1'
# Remove this once https://github.com/nex3/rb-inotify/pull/20 is solved.
# This patch makes rb-inotify a nice player with listen so it does not poll.
gem 'rb-inotify', :git => 'https://github.com/mbj/rb-inotify'
end
group :metrics do
- gem 'flay', '~> 1.4.2'
- gem 'flog', '~> 2.5.1'
- gem 'reek', '~> 1.2.8', :git => 'https://github.com/dkubb/reek.git'
- gem 'roodi', '~> 2.1.0'
- gem 'yardstick', '~> 0.5.0'
- gem 'yard-spellcheck', '~> 0.1.5'
- gem 'pelusa', '~> 0.2.1'
+ gem 'flay', '~> 1'
+ gem 'flog', '~> 2'
+ gem 'reek', '~> 1'
+ gem 'roodi', '~> 2'
+ gem 'yardstick', '~> 0'
+ gem 'yard-spellcheck', '~> 0'
+ gem 'pelusa', '~> 0'
end
View
@@ -4,7 +4,7 @@ guard :bundler do
watch('Gemfile')
end
-guard :minitest do
+guard :rspec do
# run all specs if the spec_helper or supporting files files are modified
watch('spec/spec_helper.rb') { 'spec' }
watch(%r{\Aspec/(?:lib|support|shared)/.+\.rb\z}) { 'spec' }
View
1 TODO
@@ -0,0 +1 @@
+* Extract boolean logic from veritas into axiom-logic and use instead of Matchers.
View
@@ -1,3 +1,3 @@
---
-threshold: 45
-total_score: 511
+threshold: 29
+total_score: 315
View
@@ -1,2 +1,2 @@
---
-threshold: 39.5
+threshold: 14.1
View
@@ -11,11 +11,11 @@ ClassVariableCheck: {}
CyclomaticComplexityBlockCheck:
complexity: 2
CyclomaticComplexityMethodCheck:
- complexity: 7 # TODO decrease to 4
+ complexity: 4
EmptyRescueBodyCheck: {}
ForLoopCheck: {}
MethodLineCountCheck:
- line_count: 15 # TODO decrease to 9
+ line_count: 8 # TODO decrease to 9
MethodNameCheck:
pattern: !ruby/regexp /\A(?:[a-z\d](?:_?[a-z\d])+[?!=]?|\[\]=?|==|<=>|<<|[+*&|-])\z/
ModuleLineCountCheck:
View
@@ -8,7 +8,7 @@ UncommunicativeParameterName:
- !ruby/regexp /[0-9]$/
- !ruby/regexp /[A-Z]/
LargeClass:
- max_methods: 12 # Todo decrease to 10
+ max_methods: 10 # Todo decrease to 10
exclude: []
enabled: true
max_instance_variables: 3
@@ -21,7 +21,7 @@ UncommunicativeMethodName:
- !ruby/regexp /[0-9]$/
- !ruby/regexp /[A-Z]/
LongParameterList:
- max_params: 3 # TODO decrease to 2
+ max_params: 2
exclude: []
enabled: true
overrides: {}
@@ -36,7 +36,7 @@ BooleanParameter:
enabled: true
IrresponsibleModule:
exclude: []
- enabled: false # Todo enable
+ enabled: false # Fix false positives and reenable
UncommunicativeModuleName:
accept: []
exclude: []
@@ -46,22 +46,24 @@ UncommunicativeModuleName:
- !ruby/regexp /[0-9]$/
NestedIterators:
ignore_iterators: []
- exclude:
- - Aequitas::ContextualRuleSet#add
+ exclude: []
enabled: true
max_allowed_nesting: 1
LongMethod:
- max_statements: 16 # Todo decrease to 6
+ max_statements: 8
exclude: []
enabled: true
Duplication:
allow_calls: []
- exclude: []
+ exclude:
+ - Aequitas#self.blank
enabled: true
- max_calls: 2 # Todo decrease to 1
+ max_calls: 1
UtilityFunction:
- max_helper_calls: 1 # Todo decrease to 0
- exclude: []
+ max_helper_calls: 0
+ exclude:
+ - Aequitas::Validator#add # TODO fix false positive
+ - Aequitas::Matcher::Nullary#matches?
enabled: true
Attribute:
exclude: []
@@ -77,15 +79,14 @@ UncommunicativeVariableName:
SimulatedPolymorphism:
exclude: []
enabled: true
- max_ifs: 2 # Todo decrease to 1
+ max_ifs: 1
DataClump:
exclude: []
enabled: true
- max_copies: 3 # Todo decrease to 2
- min_clump_size: 3 # Todo decrease to 2
+ max_copies: 2
+ min_clump_size: 2
ControlCouple:
- exclude:
- - Aequitas::Rule::Format::Regexp#expected_format? # Todo remove
+ exclude: []
enabled: true
LongYieldList:
max_params: 1
View
@@ -1,2 +1,2 @@
---
-threshold: 84.0
+threshold: 100.0
View
@@ -1,12 +1,15 @@
# -*- encoding: utf-8 -*-
+require 'date'
require 'backports'
require 'bigdecimal'
require 'bigdecimal/util'
require 'forwardable'
require 'adamantium'
require 'equalizer'
require 'abstract_class'
+require 'ice_nine'
+require 'ice_nine/core_ext/object'
# Library namespace
module Aequitas
@@ -31,45 +34,39 @@ def self.included(descendant)
end
require 'aequitas/support/blank'
-require 'aequitas/macros'
+require 'aequitas/evaluator'
+require 'aequitas/dsl'
require 'aequitas/class_methods'
require 'aequitas/instance_methods'
-require 'aequitas/rule_set'
-require 'aequitas/exceptions'
-require 'aequitas/guard'
+require 'aequitas/validator'
+require 'aequitas/builder'
+require 'aequitas/builder/nullary'
+require 'aequitas/matcher'
+require 'aequitas/matcher/unary'
+require 'aequitas/matcher/unary/not'
+require 'aequitas/matcher/binary'
+require 'aequitas/matcher/binary/and'
+require 'aequitas/matcher/binary/or'
+require 'aequitas/matcher/binary/xor'
+require 'aequitas/matcher/nullary'
+require 'aequitas/matcher/nullary/proc'
+require 'aequitas/matcher/nullary/format'
+require 'aequitas/matcher/nullary/primitive'
+require 'aequitas/matcher/nullary/inclusion'
+require 'aequitas/matcher/nullary/equality'
+require 'aequitas/matcher/nullary/greater_than'
+require 'aequitas/matcher/nullary/less_than'
+require 'aequitas/matcher/nullary/value'
require 'aequitas/rule'
-require 'aequitas/rule/absence'
-require 'aequitas/rule/absence/blank'
-require 'aequitas/rule/absence/nil'
-require 'aequitas/rule/acceptance'
-require 'aequitas/rule/confirmation'
-require 'aequitas/rule/format'
-require 'aequitas/rule/format/email_address'
-require 'aequitas/rule/format/proc'
-require 'aequitas/rule/format/regexp'
-require 'aequitas/rule/format/url'
-require 'aequitas/rule/length'
-require 'aequitas/rule/length/equal'
-require 'aequitas/rule/length/maximum'
-require 'aequitas/rule/length/minimum'
-require 'aequitas/rule/length/range'
-require 'aequitas/rule/numericalness'
-require 'aequitas/rule/numericalness/integer'
-require 'aequitas/rule/numericalness/non_integer'
-require 'aequitas/rule/presence'
-require 'aequitas/rule/presence/not_blank'
-require 'aequitas/rule/presence/not_nil'
-require 'aequitas/rule/primitive_type'
-require 'aequitas/rule/value'
-require 'aequitas/rule/value/equal'
-require 'aequitas/rule/value/greater_than'
-require 'aequitas/rule/value/greater_than_or_equal'
-require 'aequitas/rule/value/less_than'
-require 'aequitas/rule/value/less_than_or_equal'
-require 'aequitas/rule/value/not_equal'
-require 'aequitas/rule/value/range'
-require 'aequitas/rule/inclusion'
-require 'aequitas/rule_set'
+require 'aequitas/rule/nullary'
+require 'aequitas/rule/nullary/confirmation'
+require 'aequitas/rule/nullary/attribute'
+require 'aequitas/rule/nullary/attribute/format'
+require 'aequitas/rule/nullary/attribute/length'
+require 'aequitas/rule/nullary/attribute/absence'
+require 'aequitas/rule/nullary/attribute/presence'
+require 'aequitas/rule/nullary/attribute/primitive'
+require 'aequitas/rule/nullary/attribute/inclusion'
require 'aequitas/version'
require 'aequitas/violation'
-require 'aequitas/violation_set'
+require 'aequitas/result'
View
@@ -0,0 +1,14 @@
+module Aequitas
+ # Abstract base class for builders
+ class Builder
+ include Adamantium::Flat, AbstractClass
+
+ # Return rules
+ #
+ # @return [Enumerable<Rule>]
+ #
+ # @api private
+ #
+ abstract_method :rules
+ end
+end
Oops, something went wrong.

0 comments on commit a54f8c0

Please sign in to comment.