smart_core 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/CHANGELOG.md +5 -0
- data/README.md +2 -0
- data/lib/smart_core/operation.rb +4 -1
- data/lib/smart_core/validator/error_set.rb +1 -0
- data/lib/smart_core/validator/invoker.rb +27 -2
- data/lib/smart_core/version.rb +1 -1
- data/smart_core.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48849feae93285cc47dffdf7ded564e285a9294c85f33c12f46cca3f8ce2f0ac
|
4
|
+
data.tar.gz: 8c4bb987bea2d13d68bef46d9c8e571e7ab05a4ec845e1066db83e5427dfb0b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bdc6cd853dbc1feef51a6f37609c529381aa2a8a9e36484f961648fe167459397a3068a33adafc7f7f80a6c291e9ea81e91dd3580a917b810d85d45115a0534
|
7
|
+
data.tar.gz: d3938950ef78da94e8866870e7d1f08b6d122947507d7876d817a9e19788e89c98af040dfd05a3a917758e32142a3ac0af7ad902afa56fd1eb365d20bc2b4aa1
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## [0.4.0] - 2019-01-27
|
5
|
+
### Added
|
6
|
+
- **Valdiator**
|
7
|
+
- `#fatal` - an `#error`-like method that appends validation error code and stops current method execution flow;
|
8
|
+
|
4
9
|
## [0.3.0] - 2019-01-20
|
5
10
|
### Added
|
6
11
|
- **Operation**
|
data/README.md
CHANGED
@@ -34,6 +34,8 @@ require 'smart_core'
|
|
34
34
|
- [**Validation Object**](#validation-object) (`SmartCore::Validator`)
|
35
35
|
- support for nested validations;
|
36
36
|
- inheritance works as expected `:)`;
|
37
|
+
- `#error` - adds an error code;
|
38
|
+
- `#fatal` - adds an error code and stops the current method execution flow;
|
37
39
|
- command-style DSL;
|
38
40
|
- thread-safe;
|
39
41
|
- no dependencies;
|
data/lib/smart_core/operation.rb
CHANGED
@@ -21,7 +21,9 @@ class SmartCore::Operation
|
|
21
21
|
# @param arguments [Any]
|
22
22
|
# @param options [Hash<Symbol,Any>]
|
23
23
|
# @param block [Proc]
|
24
|
-
# @return [SmartCore::Operation::Success
|
24
|
+
# @return [SmartCore::Operation::Success]
|
25
|
+
# @return [SmartCore::Operation::Failure]
|
26
|
+
# @return [SmartCore::Operation::Fatal]
|
25
27
|
#
|
26
28
|
# @api public
|
27
29
|
# @since 0.2.0
|
@@ -39,6 +41,7 @@ class SmartCore::Operation
|
|
39
41
|
# @return [SmartCore::Operation::Success]
|
40
42
|
# @return [SmartCore::Operation::Failure]
|
41
43
|
# @return [SmartCore::Operation::Fatal]
|
44
|
+
# @return [Any]
|
42
45
|
#
|
43
46
|
# @api public
|
44
47
|
# @since 0.2.0
|
@@ -75,6 +75,7 @@ class SmartCore::Validator
|
|
75
75
|
# @api private
|
76
76
|
# @since 0.1.0
|
77
77
|
def store_error(error_code)
|
78
|
+
# NOTE: think about the any type of error codes
|
78
79
|
unless error_code.is_a?(Symbol) || error_code.is_a?(String)
|
79
80
|
raise IncorrectErrorCodeError, 'Error code should be a symbol or a string'
|
80
81
|
end
|
@@ -4,6 +4,18 @@ class SmartCore::Validator
|
|
4
4
|
# @api private
|
5
5
|
# @since 0.1.0
|
6
6
|
class Invoker
|
7
|
+
# @return [SmartCore::Validator::Invoker::Error]
|
8
|
+
#
|
9
|
+
# @api private
|
10
|
+
# @since 0.4.0
|
11
|
+
Error = Class.new(StandardError)
|
12
|
+
|
13
|
+
# @return [SmartCore::Validator::Invoker::StopValidationError]
|
14
|
+
#
|
15
|
+
# @api private
|
16
|
+
# @since 0.4.0
|
17
|
+
StopValidationError = Class.new(Error)
|
18
|
+
|
7
19
|
class << self
|
8
20
|
# @param validator [SmartCore::Validator]
|
9
21
|
# @param validating_method [Symbol, String]
|
@@ -35,12 +47,16 @@ class SmartCore::Validator
|
|
35
47
|
# @param validating_method [String, Symbol]
|
36
48
|
# @return [SmartCore::Validator::ErrorSet]
|
37
49
|
#
|
50
|
+
#
|
38
51
|
# @api private
|
39
52
|
# @since 0.1.0
|
40
53
|
def call(validating_method)
|
41
54
|
thread_safe do
|
42
55
|
ErrorSet.new.tap do |outer_errors|
|
43
|
-
|
56
|
+
begin
|
57
|
+
extended_validator(outer_errors).send(validating_method)
|
58
|
+
rescue StopValidationError
|
59
|
+
end
|
44
60
|
end
|
45
61
|
end
|
46
62
|
end
|
@@ -48,11 +64,15 @@ class SmartCore::Validator
|
|
48
64
|
private
|
49
65
|
|
50
66
|
# Creates new validator object cloned from the original validator object
|
51
|
-
# with the new functionality:
|
67
|
+
# with the new functionality:
|
68
|
+
# - error code interception;
|
69
|
+
# - soft quit from the original method immidietly;
|
52
70
|
#
|
53
71
|
# @param outer_errors [SmartCore::Validator::ErrorSet]
|
54
72
|
# @return [SmartCore::Validator]
|
55
73
|
#
|
74
|
+
# @raise [SmartCore::Validator::Invoker::StopValidationError]
|
75
|
+
#
|
56
76
|
# @api private
|
57
77
|
# @since 0.1.0
|
58
78
|
def extended_validator(outer_errors)
|
@@ -60,6 +80,11 @@ class SmartCore::Validator
|
|
60
80
|
validator_clone.define_singleton_method(:error) do |error_code|
|
61
81
|
outer_errors.add_error(error_code)
|
62
82
|
end
|
83
|
+
|
84
|
+
validator_clone.define_singleton_method(:fatal) do |error_code|
|
85
|
+
outer_errors.add_error(error_code)
|
86
|
+
raise StopValidationError
|
87
|
+
end
|
63
88
|
end
|
64
89
|
end
|
65
90
|
|
data/lib/smart_core/version.rb
CHANGED
data/smart_core.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
|
27
27
|
spec.add_development_dependency 'coveralls', '~> 0.8.22'
|
28
28
|
spec.add_development_dependency 'simplecov', '~> 0.16.1'
|
29
|
-
spec.add_development_dependency 'armitage-rubocop', '~> 0.
|
29
|
+
spec.add_development_dependency 'armitage-rubocop', '~> 0.18.0'
|
30
30
|
spec.add_development_dependency 'rspec', '~> 3.8.0'
|
31
31
|
|
32
32
|
spec.add_development_dependency 'bundler'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rustam Ibragimov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01-
|
11
|
+
date: 2019-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: coveralls
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.
|
47
|
+
version: 0.18.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.
|
54
|
+
version: 0.18.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|