activevalidation 0.1.0 → 1.0.0
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.
- checksums.yaml +4 -4
- data/.gitignore +32 -9
- data/.overcommit.yml +93 -0
- data/.rspec +1 -1
- data/.rubocop.yml +80 -0
- data/.rubocop_todo.yml +7 -0
- data/.travis.yml +42 -2
- data/.yardops +9 -0
- data/Appraisals +27 -0
- data/Gemfile +24 -1
- data/MIT-LICENSE +20 -0
- data/README.md +142 -20
- data/Rakefile +21 -3
- data/activevalidation.gemspec +35 -25
- data/bin/console +4 -7
- data/gemfiles/am_5.0.gemfile +17 -0
- data/gemfiles/am_5.0.gemfile.lock +159 -0
- data/gemfiles/am_5.1.gemfile +17 -0
- data/gemfiles/am_5.1.gemfile.lock +159 -0
- data/gemfiles/am_5.2.gemfile +17 -0
- data/gemfiles/am_5.2.gemfile.lock +159 -0
- data/gemfiles/am_6.0.gemfile +18 -0
- data/gemfiles/am_6.0.gemfile.lock +158 -0
- data/lib/active_validation.rb +27 -0
- data/lib/active_validation/base_adapter.rb +103 -0
- data/lib/active_validation/configuration.rb +52 -0
- data/lib/active_validation/decorator.rb +27 -0
- data/lib/active_validation/decorators/consistent_registry.rb +36 -0
- data/lib/active_validation/decorators/disallows_duplicates_registry.rb +17 -0
- data/lib/active_validation/errors.rb +28 -0
- data/lib/active_validation/ext/add_active_validation_context_check.rb +21 -0
- data/lib/active_validation/formatters/manifest_name_formatter.rb +13 -0
- data/lib/active_validation/formatters/validation_context_formatter.rb +28 -0
- data/lib/active_validation/frameworks/rspec.rb +10 -0
- data/lib/active_validation/frameworks/rspec/helpers.rb +15 -0
- data/lib/active_validation/internal/models/check.rb +51 -0
- data/lib/active_validation/internal/models/concerns/to_internal.rb +27 -0
- data/lib/active_validation/internal/models/manifest.rb +122 -0
- data/lib/active_validation/internal/models/manifest/installer.rb +86 -0
- data/lib/active_validation/internal/observers/manifest.rb +114 -0
- data/lib/active_validation/model_extension_base.rb +33 -0
- data/lib/active_validation/orm_plugins/active_record_plugin/adapter.rb +59 -0
- data/lib/active_validation/orm_plugins/active_record_plugin/internals/active_validation/internal_model_extensions/check.rb +11 -0
- data/lib/active_validation/orm_plugins/active_record_plugin/model_extension/active_validation/active_record_model_extension.rb +25 -0
- data/lib/active_validation/orm_plugins/active_record_plugin/models/active_validation/check.rb +31 -0
- data/lib/active_validation/orm_plugins/active_record_plugin/models/active_validation/check/concerns/method_must_be_allowed.rb +38 -0
- data/lib/active_validation/orm_plugins/active_record_plugin/models/active_validation/check/validate_method.rb +9 -0
- data/lib/active_validation/orm_plugins/active_record_plugin/models/active_validation/check/validates_method.rb +9 -0
- data/lib/active_validation/orm_plugins/active_record_plugin/models/active_validation/check/validates_with_method.rb +19 -0
- data/lib/active_validation/orm_plugins/active_record_plugin/models/active_validation/concerns/protect_from_mutable_instance_methods.rb +31 -0
- data/lib/active_validation/orm_plugins/active_record_plugin/models/active_validation/manifest.rb +21 -0
- data/lib/active_validation/orm_plugins/active_record_plugin/types/active_validation/type/version.rb +17 -0
- data/lib/active_validation/registry.rb +55 -0
- data/lib/active_validation/values/base.rb +39 -0
- data/lib/active_validation/values/method_name.rb +22 -0
- data/lib/active_validation/values/version.rb +17 -0
- data/lib/active_validation/verifier.rb +150 -0
- data/lib/active_validation/version.rb +5 -0
- data/spec/active_validation/base_adapter_spec.rb +23 -0
- data/spec/active_validation/configuration_spec.rb +52 -0
- data/spec/active_validation/decorators/consistent_registry_spec.rb +117 -0
- data/spec/active_validation/decorators/disallows_duplicates_registry_spec.rb +21 -0
- data/spec/active_validation/formatters/manifest_name_formatter_spec.rb +7 -0
- data/spec/active_validation/formatters/validation_context_formatter_spec.rb +39 -0
- data/spec/active_validation/internal/models/check_spec.rb +67 -0
- data/spec/active_validation/internal/models/manifest/installer_spec.rb +177 -0
- data/spec/active_validation/internal/models/manifest_spec.rb +136 -0
- data/spec/active_validation/internal/observers/manifest_spec.rb +201 -0
- data/spec/active_validation/model_extension_base_spec.rb +71 -0
- data/spec/active_validation/orm_plugins/active_record_plugin/adapter_spec.rb +31 -0
- data/spec/active_validation/orm_plugins/active_record_plugin/adapter_spec_orm_specific_spec.rb +84 -0
- data/spec/active_validation/orm_plugins/active_record_plugin/models/active_validation/check/validate_method_spec.rb +26 -0
- data/spec/active_validation/orm_plugins/active_record_plugin/models/active_validation/check/validates_method_spec.rb +26 -0
- data/spec/active_validation/orm_plugins/active_record_plugin/models/active_validation/check/validates_with_method_spec.rb +34 -0
- data/spec/active_validation/orm_plugins/active_record_plugin/models/active_validation/check_spec.rb +48 -0
- data/spec/active_validation/orm_plugins/active_record_plugin/models/active_validation/manifest_spec.rb +61 -0
- data/spec/active_validation/orm_plugins/active_record_plugin/readme_spec.rb +89 -0
- data/spec/active_validation/registry_spec.rb +76 -0
- data/spec/active_validation/values/base_spec.rb +61 -0
- data/spec/active_validation/values/method_name_spec.rb +16 -0
- data/spec/active_validation/values/version_spec.rb +36 -0
- data/spec/active_validation/verifier_spec.rb +214 -0
- data/spec/active_validation_spec.rb +19 -0
- data/spec/factories/internal/internal_check.rb +43 -0
- data/spec/features/active_record/child_record.feature +32 -0
- data/spec/features/active_record/new_record.feature +22 -0
- data/spec/features/no_orm/install.feature +19 -0
- data/spec/features/no_orm/validate.feature +27 -0
- data/spec/features/no_orm/validate_with_multiple_manifests.feature +29 -0
- data/spec/features/no_orm/validate_with_multiple_versions.feature +42 -0
- data/spec/features/placeholders/be_matcher.rb +7 -0
- data/spec/features/placeholders/klass.rb +5 -0
- data/spec/features/placeholders/version.rb +11 -0
- data/spec/features/placeholders/whether_to.rb +11 -0
- data/spec/features/step_definitions/active_record_steps.rb +7 -0
- data/spec/features/step_definitions/steps.rb +85 -0
- data/spec/orm/active_record/db_adapters/database.mysql.yml +12 -0
- data/spec/orm/active_record/db_adapters/database.postgres.yml +11 -0
- data/spec/orm/active_record/db_adapters/database.sqlite.yml +8 -0
- data/spec/orm/active_record/factories/check/check_validate.rb +8 -0
- data/spec/orm/active_record/factories/check/check_validates.rb +8 -0
- data/spec/orm/active_record/factories/check/check_validates_with.rb +19 -0
- data/spec/orm/active_record/factories/manifest.rb +29 -0
- data/spec/orm/active_record/prepare_db.rb +89 -0
- data/spec/orm/active_record/setup.rb +11 -0
- data/spec/orm/mongoid/setup.rb +15 -0
- data/spec/spec_helper.rb +38 -0
- data/spec/support/database_cleaner.rb +16 -0
- data/spec/support/deferred_garbage_collection.rb +31 -0
- data/spec/support/define_constant_macros.rb +17 -0
- data/spec/support/factory_bot.rb +12 -0
- data/spec/support/helpers.rb +3 -0
- data/spec/support/helpers/only_with_active_record.rb +15 -0
- data/spec/support/matchers/delegate.rb +50 -0
- data/spec/support/matchers/have_attr.rb +58 -0
- data/spec/support/mongoid.yml +6 -0
- data/spec/support/shared_examples/check_attributes.rb +9 -0
- data/spec/support/shared_examples/verifiers_registry.rb +10 -0
- data/spec/support/simplecov.rb +11 -0
- data/spec/turnip_helper.rb +4 -0
- metadata +304 -20
- data/lib/activevalidation.rb +0 -6
- data/lib/activevalidation/version.rb +0 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a5fb5e334a2e1d3f53754612dceea966b88354289f44fadcfceb9785319b63f7
|
|
4
|
+
data.tar.gz: 233d20c566b01decb2d01b5f61d27ef56b3529048d916c3f49d5b331bceaab53
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1c8f416c502ebf647489cdcc81dc5340c416314fe272cceaab3fd7031bfeec02446a5db865c851d159f8fc9bfd963b892f648a43ad83a34be18882d91b68317e
|
|
7
|
+
data.tar.gz: ccbe3be59044be2b025f7b34777248e4e0e2a99bd651003ce2a8ed12250b57d1366faa1b1f947268524cb8b51ee0ba3e85a115c67cfbc8d25c6df855aac06daa
|
data/.gitignore
CHANGED
|
@@ -1,11 +1,34 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
data/.overcommit.yml
ADDED
|
@@ -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
data/.rubocop.yml
ADDED
|
@@ -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
|
data/.rubocop_todo.yml
ADDED
|
@@ -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.
|
data/.travis.yml
CHANGED
|
@@ -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.
|
|
7
|
-
|
|
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
|
data/.yardops
ADDED
data/Appraisals
ADDED
|
@@ -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
|
-
#
|
|
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
|
data/MIT-LICENSE
ADDED
|
@@ -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
|
-
#
|
|
1
|
+
# ActiveValidation
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
|
|
10
|
+
Extend ActiveModel validations, which introduce validations with versions and
|
|
11
|
+
allows to manage validations of the records dynamically.
|
|
6
12
|
|
|
7
|
-
|
|
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 '
|
|
71
|
+
gem 'active_validation'
|
|
13
72
|
```
|
|
14
73
|
|
|
15
|
-
|
|
74
|
+
Also will be required create dependent tables in the migration.
|
|
16
75
|
|
|
17
|
-
|
|
76
|
+
#### ActiveRecord
|
|
18
77
|
|
|
19
|
-
|
|
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
|
-
|
|
84
|
+
t.datetime :created_at
|
|
85
|
+
end
|
|
22
86
|
|
|
23
|
-
|
|
87
|
+
create_table :active_validation_checks do |t|
|
|
88
|
+
t.integer :manifest_id
|
|
89
|
+
t.string :type
|
|
90
|
+
t.string :argument
|
|
24
91
|
|
|
25
|
-
|
|
92
|
+
t.json :options
|
|
26
93
|
|
|
27
|
-
|
|
94
|
+
t.datetime :created_at
|
|
95
|
+
end
|
|
96
|
+
```
|
|
28
97
|
|
|
29
|
-
|
|
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
|
-
|
|
101
|
+
### Initial configuration
|
|
34
102
|
|
|
35
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
131
|
+
c.validation_context_formatter # You can set custom validation context generator, see lib/active_validation/formatters/validation_context_formatter.rb
|
|
42
132
|
|
|
43
|
-
|
|
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&utm_medium=referral&utm_content=kvokka/activevalidation&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
|