activevalidation 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +32 -9
  3. data/.overcommit.yml +93 -0
  4. data/.rspec +1 -1
  5. data/.rubocop.yml +80 -0
  6. data/.rubocop_todo.yml +7 -0
  7. data/.travis.yml +42 -2
  8. data/.yardops +9 -0
  9. data/Appraisals +27 -0
  10. data/Gemfile +24 -1
  11. data/MIT-LICENSE +20 -0
  12. data/README.md +142 -20
  13. data/Rakefile +21 -3
  14. data/activevalidation.gemspec +35 -25
  15. data/bin/console +4 -7
  16. data/gemfiles/am_5.0.gemfile +17 -0
  17. data/gemfiles/am_5.0.gemfile.lock +159 -0
  18. data/gemfiles/am_5.1.gemfile +17 -0
  19. data/gemfiles/am_5.1.gemfile.lock +159 -0
  20. data/gemfiles/am_5.2.gemfile +17 -0
  21. data/gemfiles/am_5.2.gemfile.lock +159 -0
  22. data/gemfiles/am_6.0.gemfile +18 -0
  23. data/gemfiles/am_6.0.gemfile.lock +158 -0
  24. data/lib/active_validation.rb +27 -0
  25. data/lib/active_validation/base_adapter.rb +103 -0
  26. data/lib/active_validation/configuration.rb +52 -0
  27. data/lib/active_validation/decorator.rb +27 -0
  28. data/lib/active_validation/decorators/consistent_registry.rb +36 -0
  29. data/lib/active_validation/decorators/disallows_duplicates_registry.rb +17 -0
  30. data/lib/active_validation/errors.rb +28 -0
  31. data/lib/active_validation/ext/add_active_validation_context_check.rb +21 -0
  32. data/lib/active_validation/formatters/manifest_name_formatter.rb +13 -0
  33. data/lib/active_validation/formatters/validation_context_formatter.rb +28 -0
  34. data/lib/active_validation/frameworks/rspec.rb +10 -0
  35. data/lib/active_validation/frameworks/rspec/helpers.rb +15 -0
  36. data/lib/active_validation/internal/models/check.rb +51 -0
  37. data/lib/active_validation/internal/models/concerns/to_internal.rb +27 -0
  38. data/lib/active_validation/internal/models/manifest.rb +122 -0
  39. data/lib/active_validation/internal/models/manifest/installer.rb +86 -0
  40. data/lib/active_validation/internal/observers/manifest.rb +114 -0
  41. data/lib/active_validation/model_extension_base.rb +33 -0
  42. data/lib/active_validation/orm_plugins/active_record_plugin/adapter.rb +59 -0
  43. data/lib/active_validation/orm_plugins/active_record_plugin/internals/active_validation/internal_model_extensions/check.rb +11 -0
  44. data/lib/active_validation/orm_plugins/active_record_plugin/model_extension/active_validation/active_record_model_extension.rb +25 -0
  45. data/lib/active_validation/orm_plugins/active_record_plugin/models/active_validation/check.rb +31 -0
  46. data/lib/active_validation/orm_plugins/active_record_plugin/models/active_validation/check/concerns/method_must_be_allowed.rb +38 -0
  47. data/lib/active_validation/orm_plugins/active_record_plugin/models/active_validation/check/validate_method.rb +9 -0
  48. data/lib/active_validation/orm_plugins/active_record_plugin/models/active_validation/check/validates_method.rb +9 -0
  49. data/lib/active_validation/orm_plugins/active_record_plugin/models/active_validation/check/validates_with_method.rb +19 -0
  50. data/lib/active_validation/orm_plugins/active_record_plugin/models/active_validation/concerns/protect_from_mutable_instance_methods.rb +31 -0
  51. data/lib/active_validation/orm_plugins/active_record_plugin/models/active_validation/manifest.rb +21 -0
  52. data/lib/active_validation/orm_plugins/active_record_plugin/types/active_validation/type/version.rb +17 -0
  53. data/lib/active_validation/registry.rb +55 -0
  54. data/lib/active_validation/values/base.rb +39 -0
  55. data/lib/active_validation/values/method_name.rb +22 -0
  56. data/lib/active_validation/values/version.rb +17 -0
  57. data/lib/active_validation/verifier.rb +150 -0
  58. data/lib/active_validation/version.rb +5 -0
  59. data/spec/active_validation/base_adapter_spec.rb +23 -0
  60. data/spec/active_validation/configuration_spec.rb +52 -0
  61. data/spec/active_validation/decorators/consistent_registry_spec.rb +117 -0
  62. data/spec/active_validation/decorators/disallows_duplicates_registry_spec.rb +21 -0
  63. data/spec/active_validation/formatters/manifest_name_formatter_spec.rb +7 -0
  64. data/spec/active_validation/formatters/validation_context_formatter_spec.rb +39 -0
  65. data/spec/active_validation/internal/models/check_spec.rb +67 -0
  66. data/spec/active_validation/internal/models/manifest/installer_spec.rb +177 -0
  67. data/spec/active_validation/internal/models/manifest_spec.rb +136 -0
  68. data/spec/active_validation/internal/observers/manifest_spec.rb +201 -0
  69. data/spec/active_validation/model_extension_base_spec.rb +71 -0
  70. data/spec/active_validation/orm_plugins/active_record_plugin/adapter_spec.rb +31 -0
  71. data/spec/active_validation/orm_plugins/active_record_plugin/adapter_spec_orm_specific_spec.rb +84 -0
  72. data/spec/active_validation/orm_plugins/active_record_plugin/models/active_validation/check/validate_method_spec.rb +26 -0
  73. data/spec/active_validation/orm_plugins/active_record_plugin/models/active_validation/check/validates_method_spec.rb +26 -0
  74. data/spec/active_validation/orm_plugins/active_record_plugin/models/active_validation/check/validates_with_method_spec.rb +34 -0
  75. data/spec/active_validation/orm_plugins/active_record_plugin/models/active_validation/check_spec.rb +48 -0
  76. data/spec/active_validation/orm_plugins/active_record_plugin/models/active_validation/manifest_spec.rb +61 -0
  77. data/spec/active_validation/orm_plugins/active_record_plugin/readme_spec.rb +89 -0
  78. data/spec/active_validation/registry_spec.rb +76 -0
  79. data/spec/active_validation/values/base_spec.rb +61 -0
  80. data/spec/active_validation/values/method_name_spec.rb +16 -0
  81. data/spec/active_validation/values/version_spec.rb +36 -0
  82. data/spec/active_validation/verifier_spec.rb +214 -0
  83. data/spec/active_validation_spec.rb +19 -0
  84. data/spec/factories/internal/internal_check.rb +43 -0
  85. data/spec/features/active_record/child_record.feature +32 -0
  86. data/spec/features/active_record/new_record.feature +22 -0
  87. data/spec/features/no_orm/install.feature +19 -0
  88. data/spec/features/no_orm/validate.feature +27 -0
  89. data/spec/features/no_orm/validate_with_multiple_manifests.feature +29 -0
  90. data/spec/features/no_orm/validate_with_multiple_versions.feature +42 -0
  91. data/spec/features/placeholders/be_matcher.rb +7 -0
  92. data/spec/features/placeholders/klass.rb +5 -0
  93. data/spec/features/placeholders/version.rb +11 -0
  94. data/spec/features/placeholders/whether_to.rb +11 -0
  95. data/spec/features/step_definitions/active_record_steps.rb +7 -0
  96. data/spec/features/step_definitions/steps.rb +85 -0
  97. data/spec/orm/active_record/db_adapters/database.mysql.yml +12 -0
  98. data/spec/orm/active_record/db_adapters/database.postgres.yml +11 -0
  99. data/spec/orm/active_record/db_adapters/database.sqlite.yml +8 -0
  100. data/spec/orm/active_record/factories/check/check_validate.rb +8 -0
  101. data/spec/orm/active_record/factories/check/check_validates.rb +8 -0
  102. data/spec/orm/active_record/factories/check/check_validates_with.rb +19 -0
  103. data/spec/orm/active_record/factories/manifest.rb +29 -0
  104. data/spec/orm/active_record/prepare_db.rb +89 -0
  105. data/spec/orm/active_record/setup.rb +11 -0
  106. data/spec/orm/mongoid/setup.rb +15 -0
  107. data/spec/spec_helper.rb +38 -0
  108. data/spec/support/database_cleaner.rb +16 -0
  109. data/spec/support/deferred_garbage_collection.rb +31 -0
  110. data/spec/support/define_constant_macros.rb +17 -0
  111. data/spec/support/factory_bot.rb +12 -0
  112. data/spec/support/helpers.rb +3 -0
  113. data/spec/support/helpers/only_with_active_record.rb +15 -0
  114. data/spec/support/matchers/delegate.rb +50 -0
  115. data/spec/support/matchers/have_attr.rb +58 -0
  116. data/spec/support/mongoid.yml +6 -0
  117. data/spec/support/shared_examples/check_attributes.rb +9 -0
  118. data/spec/support/shared_examples/verifiers_registry.rb +10 -0
  119. data/spec/support/simplecov.rb +11 -0
  120. data/spec/turnip_helper.rb +4 -0
  121. metadata +304 -20
  122. data/lib/activevalidation.rb +0 -6
  123. data/lib/activevalidation/version.rb +0 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad51852232b76c40ae0c6ecc5592471613cca20e5a50eea9315f9c16f0146faf
4
- data.tar.gz: cf6e173d154de0c0fbeb9a5f154975b663b4d2228fb505fca3215f3d6c0c9db6
3
+ metadata.gz: a5fb5e334a2e1d3f53754612dceea966b88354289f44fadcfceb9785319b63f7
4
+ data.tar.gz: 233d20c566b01decb2d01b5f61d27ef56b3529048d916c3f49d5b331bceaab53
5
5
  SHA512:
6
- metadata.gz: f1ad40509c6b81b22f975605a2d9332db591be361f7d2b208c574dcb7a9b32fd2ada624cd4e97b6b828ece3384706d597360ea5cc48daaca5b74f814eaa90154
7
- data.tar.gz: 71f0341744affa0c53c5b8855ca77665f4fb60da19ca292551499593afadd4e402b72a7ea1ff82004fdd8157f0e9acdd7a3a6af6f570c08bcdd7ff82f2c3f6d9
6
+ metadata.gz: 1c8f416c502ebf647489cdcc81dc5340c416314fe272cceaab3fd7031bfeec02446a5db865c851d159f8fc9bfd963b892f648a43ad83a34be18882d91b68317e
7
+ data.tar.gz: ccbe3be59044be2b025f7b34777248e4e0e2a99bd651003ce2a8ed12250b57d1366faa1b1f947268524cb8b51ee0ba3e85a115c67cfbc8d25c6df855aac06daa
data/.gitignore CHANGED
@@ -1,11 +1,34 @@
1
- /.bundle/
1
+ *.gem
2
+ *.sqlite3
3
+ *.sqlite3-journal
4
+ *~
5
+ .DS_Store
6
+ .bundle
7
+ .byebug_history
8
+ .env
9
+ .idea
10
+ .pry_history
11
+ .pryrc
12
+ .rake_tasks
13
+ .rbenv-gemsets
14
+ .rbenv-version
15
+ .rspec_results
16
+ .ruby-gemset
17
+ .ruby-version
18
+ .rvmrc
19
+ .secret.*
20
+ .tool-versions
21
+ .vscode/
2
22
  /.yardoc
3
23
  /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
-
10
- # rspec failure tracking
11
- .rspec_status
24
+ Gemfile.lock
25
+ NOTES
26
+ coverage/*
27
+ doc/
28
+ log
29
+ node_modules/
30
+ passenger.*
31
+ pkg
32
+ rdoc/*
33
+ tmp/
34
+ yarn-error.log
@@ -0,0 +1,93 @@
1
+ verify_signatures: false
2
+ CommitMsg:
3
+ ALL:
4
+ CapitalizedSubject:
5
+ enabled: true
6
+ description: 'Checking subject capitalization'
7
+ quiet: true
8
+ on_warn: fail
9
+ EmptyMessage:
10
+ enabled: true
11
+ description: 'Checking for empty commit message'
12
+ quiet: true
13
+ HardTabs:
14
+ enabled: true
15
+ description: 'Checking for hard tabs'
16
+ RussianNovel:
17
+ enabled: true
18
+ description: 'Checking length of commit message'
19
+ quiet: true
20
+ SingleLineSubject:
21
+ enabled: true
22
+ description: 'Checking subject line'
23
+ SpellCheck:
24
+ enabled: true
25
+ description: 'Checking for misspelled words'
26
+ required_executable: 'hunspell'
27
+ flags: ['-a']
28
+ on_fail: warn
29
+ TextWidth:
30
+ enabled: true
31
+ description: 'Checking text width'
32
+ max_subject_width: 60
33
+ max_body_width: 72
34
+ on_warn: fail
35
+ TrailingPeriod:
36
+ enabled: true
37
+ description: 'Checking for trailing periods in subject'
38
+ on_warn: fail
39
+ MessageFormat:
40
+ enabled: false
41
+ description: 'Message must be ended with task number'
42
+ expected_pattern_message: '<Commit Message Description> <Issue Id>'
43
+ sample_message: 'Refactored Onboarding flow FOO-1234'
44
+ pattern: '\s([A-Z]{1,4}-\d{1,4}|\d{1,6})$'
45
+ PreCommit:
46
+ ALL:
47
+ problem_on_unmodified_line: report
48
+ requires_files: true
49
+ required: false
50
+ quiet: false
51
+ AuthorEmail:
52
+ enabled: true
53
+ description: 'Checking author email'
54
+ requires_files: false
55
+ required: true
56
+ quiet: true
57
+ pattern: '^[^@]+@.*$'
58
+ AuthorName:
59
+ enabled: false
60
+ description: 'Checking for author name'
61
+ requires_files: false
62
+ required: true
63
+ quiet: true
64
+ BrokenSymlinks:
65
+ enabled: true
66
+ description: 'Checking for broken symlinks'
67
+ quiet: true
68
+ CaseConflicts:
69
+ enabled: true
70
+ description: 'Checking for case-insensitivity conflicts'
71
+ quiet: true
72
+ MergeConflicts:
73
+ enabled: true
74
+ description: 'Checking for merge conflicts'
75
+ quiet: true
76
+ required_executable: 'grep'
77
+ flags: ['-IHn', "^<<<<<<<[ \t]"]
78
+
79
+ RuboCop:
80
+ enabled: true
81
+ required: true
82
+ quiet: false
83
+ description: 'Analyzing with RuboCop'
84
+ command: ['bundle', 'exec', 'rubocop']
85
+ flags: ['--format=emacs', '--force-exclusion', '--display-cop-names']
86
+ install_command: 'gem install rubocop'
87
+ on_warn: fail
88
+ include:
89
+ - '**/*.gemspec'
90
+ - '**/*.rake'
91
+ - '**/*.rb'
92
+ - '**/Gemfile'
93
+ - '**/Rakefile'
data/.rspec CHANGED
@@ -1,3 +1,3 @@
1
- --format documentation
2
1
  --color
3
2
  --require spec_helper
3
+ --require turnip/rspec
@@ -0,0 +1,80 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ Layout/AlignHash:
4
+ EnforcedHashRocketStyle: table
5
+ EnforcedColonStyle: table
6
+ AutoCorrect: true
7
+ Layout/IndentationConsistency:
8
+ EnforcedStyle: normal
9
+ Style/StringLiterals:
10
+ EnforcedStyle: double_quotes
11
+ ConsistentQuotesInMultiline: true
12
+ Style/StringLiteralsInInterpolation:
13
+ EnforcedStyle: single_quotes
14
+ Style/AndOr:
15
+ EnforcedStyle: conditionals
16
+ Metrics/ClassLength:
17
+ CountComments: false
18
+ Max: 300
19
+ Metrics/ModuleLength:
20
+ CountComments: false
21
+ Max: 300
22
+ Layout/EndAlignment:
23
+ AutoCorrect: true
24
+ Layout/DefEndAlignment:
25
+ AutoCorrect: true
26
+ Style/AutoResourceCleanup:
27
+ Description: 'Suggests the usage of an auto resource cleanup version of a method (if available).'
28
+ Enabled: true
29
+ Metrics/MethodLength:
30
+ CountComments: false # count full line comments?
31
+ Max: 25
32
+ NumericLiterals:
33
+ Enabled: false
34
+ Metrics/LineLength:
35
+ Max: 120
36
+ Documentation:
37
+ Enabled: false
38
+ Lint/Debugger:
39
+ Enabled: true
40
+ Metrics/AbcSize:
41
+ Max: 40
42
+ Metrics/CyclomaticComplexity:
43
+ Max: 10
44
+ Style/DoubleNegation:
45
+ Description: 'Checks for uses of double negation (!!).'
46
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-bang-bang'
47
+ Enabled: false
48
+ Style/AsciiComments:
49
+ Description: 'Use only ascii symbols in comments.'
50
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#english-comments'
51
+ Enabled: false
52
+ Style/ClassAndModuleChildren:
53
+ EnforcedStyle: compact
54
+ Enabled: false
55
+ Style/SingleLineMethods:
56
+ Description: 'Avoid single-line methods.'
57
+ StyleGuide: '#no-single-line-methods'
58
+ Enabled: false
59
+ Metrics/BlockLength:
60
+ ExcludedMethods: ['describe', 'context']
61
+ AllCops:
62
+ TargetRubyVersion: 2.4
63
+ Exclude:
64
+ - 'gemfiles/*'
65
+
66
+ require: rubocop-rspec
67
+ RSpec/MultipleExpectations:
68
+ Max: 7
69
+ RSpec/NestedGroups:
70
+ Max: 7
71
+ RSpec/ExampleLength:
72
+ Max: 10
73
+ RSpec/LetSetup:
74
+ Enabled: false
75
+ RSpec/ContextWording:
76
+ Enabled: false
77
+ RSpec/RepeatedDescription:
78
+ Enabled: false
79
+ RSpec/NamedSubject:
80
+ Enabled: false
@@ -0,0 +1,7 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2019-07-07 02:56:05 +0100 using RuboCop version 0.72.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
@@ -1,7 +1,47 @@
1
1
  ---
2
2
  sudo: false
3
3
  language: ruby
4
+ install: bundle --without local_development --jobs=3 --retry=3
4
5
  cache: bundler
5
6
  rvm:
6
- - 2.6.3
7
- before_install: gem install bundler -v 2.0.2
7
+ - 2.4
8
+ - 2.5
9
+ - 2.6
10
+
11
+ services:
12
+ - mysql
13
+ - postgresql
14
+
15
+ gemfile:
16
+ - gemfiles/am_5.0.gemfile
17
+ - gemfiles/am_5.1.gemfile
18
+ - gemfiles/am_5.2.gemfile
19
+ - gemfiles/am_6.0.gemfile
20
+
21
+ env:
22
+ global:
23
+ - CC_TEST_REPORTER_ID=73c88f60a4ed839ffb0da252514d11374fff29c811beebd0796311faffa7b6b5
24
+ - COVERAGE=1
25
+ - TRAVIS_TEST_RESULT=simplecov
26
+ matrix:
27
+ - DB=mysql
28
+ - DB=sqlite
29
+ - DB=postgres
30
+
31
+ matrix:
32
+ exclude:
33
+ - rvm: 2.4
34
+ gemfile: gemfiles/am_6.0.gemfile
35
+
36
+ before_script:
37
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
38
+ - chmod +x ./cc-test-reporter
39
+ - ./cc-test-reporter before-build
40
+ - psql -c 'create database test;' -U postgres
41
+ - mysql -e 'CREATE DATABASE IF NOT EXISTS test;'
42
+
43
+ before_install: gem install bundler -v 2.0.1
44
+ script:
45
+ - bundle exec rspec
46
+ after_script:
47
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
@@ -0,0 +1,9 @@
1
+ --protected
2
+ --no-private
3
+ --embed-mixin ClassMethods
4
+ -
5
+ README.md
6
+ CHANGELOG.rdoc
7
+ CONTRIBUTING.md
8
+ MIT-LICENSE
9
+ CODE_OF_CONDUCT.md
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Specify here only version constraints that differ from
4
+ # `active_validation.gemspec`.
5
+ #
6
+ # > The dependencies in your Appraisals file are combined with dependencies in
7
+ # > your Gemfile, so you don't need to repeat anything that's the same for each
8
+ # > appraisal. If something is specified in both the Gemfile and an appraisal,
9
+ # > the version from the appraisal takes precedence.
10
+ # > https://github.com/thoughtbot/appraisal
11
+
12
+ appraise "am-5.0" do
13
+ gem "activerecord", "~> 5.0.0"
14
+ end
15
+
16
+ appraise "am-5.1" do
17
+ gem "activerecord", "~> 5.1.0"
18
+ end
19
+
20
+ appraise "am-5.2" do
21
+ gem "activerecord", "~> 5.2.0"
22
+ end
23
+
24
+ appraise "am-6.0" do
25
+ gem "activerecord", "~> 6.0.0"
26
+ gem "sqlite3", "~> 1.4.0"
27
+ end
data/Gemfile CHANGED
@@ -1,4 +1,27 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
4
+ # git_source(:github) { |repo| "https://github.com/#{repo}.git" }
2
5
 
3
- # Specify your gem's dependencies in activevalidation.gemspec
6
+ # Declare your gem's dependencies in active_validation.gemspec.
7
+ # Bundler will treat runtime dependencies like base dependencies, and
8
+ # development dependencies will be added by default to the :development group.
4
9
  gemspec
10
+
11
+ # Declare any dependencies that are still in development here instead of in
12
+ # your gemspec. These might include edge Rails or gems from your path or
13
+ # Git. Remember to move these dependencies to your gemspec before releasing
14
+ # your gem to rubygems.org.
15
+
16
+ # To use a debugger
17
+ # gem 'byebug', group: [:development, :test]
18
+
19
+ group :local_development do
20
+ gem "appraisal", "~> 2.2.0"
21
+ gem "overcommit", "~> 0.48.0"
22
+ gem "pry", "~> 0.12.0"
23
+ gem "pry-byebug", "~> 3.7.0"
24
+ gem "reek", "~> 5.4.0"
25
+ gem "rubocop", "~> 0.72.0"
26
+ gem "rubocop-rspec", "~> 1.32"
27
+ end
@@ -0,0 +1,20 @@
1
+ Copyright 2019 kvokka
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.
data/README.md CHANGED
@@ -1,43 +1,165 @@
1
- # Activevalidation
1
+ # ActiveValidation
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/activevalidation`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ [![Version ][rubygems_badge]][rubygems]
4
+ [![Build Status ][travisci_badge]][travisci]
5
+ [![Codacy Badge ][codacy_badge]][codacy]
6
+ [![Reviewed by Hound ][hound_badge]][hound]
7
+ [![Maintainability ][codeclimate_badge]][codeclimate]
8
+ [![Test Coverage ][codeclimate_coverage_badge]][codeclimate_coveradge]
4
9
 
5
- TODO: Delete this and the text above, and describe your gem
10
+ Extend ActiveModel validations, which introduce validations with versions and
11
+ allows to manage validations of the records dynamically.
6
12
 
7
- ## Installation
13
+ With `ActiveValidation` instead of storing all validations hardcoded
14
+ in the Model, you can also store them in the database. Validation Manifests
15
+ are lazy loaded once, and only when they required so it does not
16
+ affect the performance.
17
+
18
+ ## Require
19
+
20
+ Ruby 2.4+
21
+ ActiveModel ~> 5.0
22
+
23
+ Supported ORM:
24
+
25
+ * ActiveRecord ~> 5.0
26
+
27
+ ## Overview
28
+
29
+ This is the add-on for ActiveModel validations. The gem allows to store
30
+ `ActiveModel` validations in some backend, like DB.
31
+ Each record with `ActiveValidation` belongs to
32
+ `ActiveValidation::Manifest` which holds general information about
33
+ the validation, including `name`, `version` and `id`. Assumed, that
34
+ `ActiveValidation::Manifest`'s with the same version are compatible and share
35
+ the same validation methods. Folder structure example for model `MyModelName`:
36
+
37
+ ```
38
+ .
39
+ └── app
40
+ └── models
41
+ ├── my_model_name
42
+ │   └── validations
43
+ │   └── v1.rb
44
+ └── my_model_name.rb
45
+ ```
46
+
47
+ for different versions of the records.
48
+ Validation versions are stored in the selected backend.
49
+ Validations themselves are stored in `ActiveValidation::Check`, 1 validation
50
+ per one record. `ActiveValidation::Manifest` has many `ActiveValidation::Check`'s.
51
+
52
+ `Manifest`'s and `Check`'s are immutable by design. Instead of updating or
53
+ patching the existed objects the developer should clone and create the new
54
+ record.
8
55
 
56
+ It is assumed that inside one version manifests are compatible. Verifier version
57
+ is a border between new version and the existed one, which allows co-existing of
58
+ both versions at the same time.
59
+
60
+ To control `ActiveValidation::Manifest`'s there is `ActiveValidation::Verifier`
61
+ class. Each model with activated `ActiveValidation` has one corresponding
62
+ `ActiveValidation::Verifier` instance (which can easily taken with
63
+ `MyModelName.active_validation` method). Through this instance user can add or find
64
+ `Minifest`(s).
65
+
66
+
67
+ ## Installation
9
68
  Add this line to your application's Gemfile:
10
69
 
11
70
  ```ruby
12
- gem 'activevalidation'
71
+ gem 'active_validation'
13
72
  ```
14
73
 
15
- And then execute:
74
+ Also will be required create dependent tables in the migration.
16
75
 
17
- $ bundle
76
+ #### ActiveRecord
18
77
 
19
- Or install it yourself as:
78
+ ```bash
79
+ create_table :active_validation_manifests do |t|
80
+ t.string :name
81
+ t.string :version
82
+ t.string :base_klass
20
83
 
21
- $ gem install activevalidation
84
+ t.datetime :created_at
85
+ end
22
86
 
23
- ## Usage
87
+ create_table :active_validation_checks do |t|
88
+ t.integer :manifest_id
89
+ t.string :type
90
+ t.string :argument
24
91
 
25
- TODO: Write usage instructions here
92
+ t.json :options
26
93
 
27
- ## Development
94
+ t.datetime :created_at
95
+ end
96
+ ```
28
97
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
98
+ ## Quick start
30
99
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
100
 
33
- ## Contributing
101
+ ### Initial configuration
34
102
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/activevalidation. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
103
+ ```ruby
104
+ ActiveValidation.configuration do |c|
105
+ c.orm_adapter = :active_record
106
+ end
107
+
108
+ # app/models/foo
109
+ class Foo < ActiveRecord::Base
110
+ active_validation
111
+
112
+ # active_validation do |verifier| # this is a form with optional block
113
+ # verifier.manifest = some_manifest # lock manifest to some particular existed manifest
114
+ # verifier.version = 42 # lock version
115
+ # verifier.orm_adapter = :active_record # ORM adapter name
116
+ # end
117
+ end
118
+ ```
36
119
 
37
- ## License
120
+ The usage described [in special spec][readme-spec]. Only this way allows to keep it always up-to-date.
121
+
122
+ ## Configuration
123
+
124
+ You can manage default values with the configuration:
125
+
126
+ ```ruby
38
127
 
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
128
+ ActiveValidation.configuration do |c|
129
+ c.manifest_name_formatter # You can set custom manifest name generator, see lib/active_validation/formatters/manifest_name_formatter.rb
40
130
 
41
- ## Code of Conduct
131
+ c.validation_context_formatter # You can set custom validation context generator, see lib/active_validation/formatters/validation_context_formatter.rb
42
132
 
43
- Everyone interacting in the Activevalidation project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/activevalidation/blob/master/CODE_OF_CONDUCT.md).
133
+ c.orm_adapter # currently supported `active_record`
134
+
135
+ c.verifier_defaults do |v|
136
+ v.validations_module_name # folder with validations versions, default: "Validations"
137
+
138
+ v.failed_attempt_retry_time # Rate limiter for check of missing Manifest, default: `1 day`
139
+ end
140
+ end
141
+ ```
142
+
143
+ ## FAQ
144
+
145
+
146
+ ## License
147
+ The gem is available as open source under the terms of the
148
+ [MIT License][mit-licence-link].
149
+
150
+ [rubygems_badge]: http://img.shields.io/gem/v/activevalidation.svg
151
+ [rubygems]: https://rubygems.org/gems/activevalidation
152
+ [travisci_badge]: https://travis-ci.org/kvokka/activevalidation.svg?branch=master
153
+ [travisci]: https://travis-ci.org/kvokka/activevalidation
154
+ [codacy_badge]: https://api.codacy.com/project/badge/Grade/687bcb63afb74686b3acdd0b8cbaf2cf
155
+ [codacy]: https://www.codacy.com/manual/kvokka/activevalidation?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=kvokka/activevalidation&amp;utm_campaign=Badge_Grade
156
+ [hound_badge]: https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg
157
+ [hound]: https://houndci.com
158
+ [codeclimate_badge]: https://api.codeclimate.com/v1/badges/53dc9ce7ec0b94570044/maintainability
159
+ [codeclimate]: https://codeclimate.com/github/kvokka/activevalidation/maintainability
160
+ [codeclimate_coverage_badge]: https://api.codeclimate.com/v1/badges/a99a88d28ad37a79dbf6/test_coverage
161
+ [codeclimate_coveradge]: https://codeclimate.com/github/codeclimate/codeclimate/test_coverage
162
+
163
+ [readme-spec]: https://github.com/kvokka/activevalidation/blob/master/spec/active_validation/orm_plugins/active_record_plugin/readme_spec.rb
164
+
165
+ [mit-licence-link]: http://opensource.org/licenses/MIT