mutations-validate-outcome 0.7.22 → 0.7.29
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/.rubocop.yml +31 -0
- data/.rubocop_todo.yml +96 -0
- data/README.md +1 -1
- data/lib/mutations/command_returning_array.rb +73 -0
- data/lib/mutations/version.rb +1 -1
- data/lib/mutations_validate_outcome.rb +42 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b6b4cbb1076d7ff847aacb574feadb923f3f3fe
|
4
|
+
data.tar.gz: 1aa782c70b954269660512a7ba700f5fba1ffe4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60b055c38e0ce56785c79eae7b37845a136056e9969ea9535168b009ccc4717b47e45d07b65defa5c653a0b14a0831a6e98fc1245d105bbc03b1ae1499adf2a7
|
7
|
+
data.tar.gz: df70e4f27652fb56e3c8dc7320183b7dee45a9f25d90c71e76101551188ff85ca2df1084c4df1bba69bc672dda1653401b3c4c9d0a4f0b5eb2b9dda3307f07ab
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
Style/AsciiComments:
|
4
|
+
Enabled: false
|
5
|
+
|
6
|
+
Style/MethodDefParentheses:
|
7
|
+
Enabled: false
|
8
|
+
|
9
|
+
Style/MultilineBlockChain:
|
10
|
+
Enabled: false
|
11
|
+
|
12
|
+
Style/ParallelAssignment:
|
13
|
+
Enabled: false
|
14
|
+
|
15
|
+
Metrics/AbcSize:
|
16
|
+
Max: 100
|
17
|
+
|
18
|
+
Metrics/ClassLength:
|
19
|
+
Max: 200
|
20
|
+
|
21
|
+
Metrics/CyclomaticComplexity:
|
22
|
+
Max: 42
|
23
|
+
|
24
|
+
Metrics/LineLength:
|
25
|
+
Max: 180
|
26
|
+
|
27
|
+
Metrics/MethodLength:
|
28
|
+
Max: 64
|
29
|
+
|
30
|
+
Metrics/PerceivedComplexity:
|
31
|
+
Max: 42
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2016-05-26 14:17:34 +0200 using RuboCop version 0.40.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.
|
8
|
+
|
9
|
+
# Offense count: 2
|
10
|
+
# Cop supports --auto-correct.
|
11
|
+
# Configuration parameters: SupportedStyles, IndentationWidth.
|
12
|
+
# SupportedStyles: outdent, indent
|
13
|
+
Style/AccessModifierIndentation:
|
14
|
+
EnforcedStyle: outdent
|
15
|
+
|
16
|
+
# Offense count: 5
|
17
|
+
Style/Documentation:
|
18
|
+
Exclude:
|
19
|
+
- 'spec/**/*'
|
20
|
+
- 'test/**/*'
|
21
|
+
- 'lib/mutations/additional_filter.rb'
|
22
|
+
- 'lib/mutations/command_returning_array.rb'
|
23
|
+
- 'lib/mutations/command_returning_hash.rb'
|
24
|
+
- 'lib/mutations/outcome_hash_filter.rb'
|
25
|
+
- 'lib/mutations_validate_outcome.rb'
|
26
|
+
|
27
|
+
# Offense count: 2
|
28
|
+
# Cop supports --auto-correct.
|
29
|
+
Style/EmptyCaseCondition:
|
30
|
+
Exclude:
|
31
|
+
- 'lib/mutations/outcome_hash_filter.rb'
|
32
|
+
|
33
|
+
# Offense count: 2
|
34
|
+
# Cop supports --auto-correct.
|
35
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
36
|
+
# SupportedStyles: empty_lines, no_empty_lines
|
37
|
+
Style/EmptyLinesAroundBlockBody:
|
38
|
+
Exclude:
|
39
|
+
- 'spec/command_returning_array_spec.rb'
|
40
|
+
- 'spec/command_returning_hash_spec.rb'
|
41
|
+
|
42
|
+
# Offense count: 4
|
43
|
+
# Cop supports --auto-correct.
|
44
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
45
|
+
# SupportedStyles: empty_lines, no_empty_lines
|
46
|
+
Style/EmptyLinesAroundClassBody:
|
47
|
+
Exclude:
|
48
|
+
- 'spec/command_returning_array_spec.rb'
|
49
|
+
- 'spec/command_returning_hash_spec.rb'
|
50
|
+
|
51
|
+
# Offense count: 2
|
52
|
+
# Cop supports --auto-correct.
|
53
|
+
# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment.
|
54
|
+
Style/ExtraSpacing:
|
55
|
+
Exclude:
|
56
|
+
- 'spec/command_returning_array_spec.rb'
|
57
|
+
- 'spec/command_returning_hash_spec.rb'
|
58
|
+
|
59
|
+
# Offense count: 1
|
60
|
+
# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist.
|
61
|
+
# NamePrefix: is_, has_, have_
|
62
|
+
# NamePrefixBlacklist: is_, has_, have_
|
63
|
+
# NameWhitelist: is_a?
|
64
|
+
Style/PredicateName:
|
65
|
+
Exclude:
|
66
|
+
- 'spec/**/*'
|
67
|
+
- 'lib/mutations/command_returning_hash.rb'
|
68
|
+
|
69
|
+
# Offense count: 1
|
70
|
+
# Cop supports --auto-correct.
|
71
|
+
# Configuration parameters: SupportedStyles.
|
72
|
+
# SupportedStyles: compact, exploded
|
73
|
+
Style/RaiseArgs:
|
74
|
+
EnforcedStyle: compact
|
75
|
+
|
76
|
+
# Offense count: 2
|
77
|
+
# Cop supports --auto-correct.
|
78
|
+
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles.
|
79
|
+
# SupportedStyles: space, no_space
|
80
|
+
Style/SpaceInsideHashLiteralBraces:
|
81
|
+
Enabled: false
|
82
|
+
|
83
|
+
# Offense count: 60
|
84
|
+
# Cop supports --auto-correct.
|
85
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
|
86
|
+
# SupportedStyles: single_quotes, double_quotes
|
87
|
+
Style/StringLiterals:
|
88
|
+
Enabled: false
|
89
|
+
|
90
|
+
# Offense count: 2
|
91
|
+
# Cop supports --auto-correct.
|
92
|
+
# Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, IgnoreClassMethods, Whitelist.
|
93
|
+
# Whitelist: to_ary, to_a, to_c, to_enum, to_h, to_hash, to_i, to_int, to_io, to_open, to_path, to_proc, to_r, to_regexp, to_str, to_s, to_sym
|
94
|
+
Style/TrivialAccessors:
|
95
|
+
Exclude:
|
96
|
+
- 'lib/mutations_validate_outcome.rb'
|
data/README.md
CHANGED
@@ -0,0 +1,73 @@
|
|
1
|
+
require_relative 'command_returning_hash'
|
2
|
+
|
3
|
+
module Mutations
|
4
|
+
class CommandReturningArray < CommandReturningHash
|
5
|
+
class << self
|
6
|
+
def create_outcome_attr_methods(meth, &block)
|
7
|
+
outcome_filters.send(meth, &block)
|
8
|
+
keys = outcome_filters.send("#{meth}_keys")
|
9
|
+
keys.each do |key|
|
10
|
+
define_method("outcome_#{key}") { @outputs.map { |o| o[key] } }
|
11
|
+
define_method("outcome_#{key}_present?") { @outputs.map { |o| o.key?(key) } }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
private :create_outcome_attr_methods
|
15
|
+
|
16
|
+
# %i(required optional).each do |m|
|
17
|
+
# meth = :"outcome_#{m}"
|
18
|
+
# define_method(meth) do |&block|
|
19
|
+
# create_outcome_attr_methods(meth, &block)
|
20
|
+
# end
|
21
|
+
# end
|
22
|
+
|
23
|
+
def outcome_required(&block)
|
24
|
+
create_outcome_attr_methods(:outcome_required, &block)
|
25
|
+
end
|
26
|
+
|
27
|
+
def outcome_optional(&block)
|
28
|
+
create_outcome_attr_methods(:outcome_optional, &block)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def errors
|
33
|
+
return nil unless errors?
|
34
|
+
|
35
|
+
ErrorHash.new.tap do |h|
|
36
|
+
h.merge! @errors if has_errors?
|
37
|
+
|
38
|
+
case @outcome_errors
|
39
|
+
when ErrorHash then h.merge! @outcome_errors
|
40
|
+
when Hash
|
41
|
+
h.merge!(@outcome_errors.each_with_object({}) do |(idx, err), memo|
|
42
|
+
memo.merge! err[:errors].map { |k, v| [:"#{k}_#{idx}", v] }.to_h
|
43
|
+
end)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def run
|
49
|
+
return validation_outcome if has_errors?
|
50
|
+
validation_outcome(
|
51
|
+
execute.tap do |result|
|
52
|
+
if result.is_a?(Array)
|
53
|
+
result.each_with_index.with_object({}) do |(e, i), memo|
|
54
|
+
_, outcome_error = self.class.outcome_filters.filter(e)
|
55
|
+
outcome_error = validate_outcome(e) if outcome_error.nil?
|
56
|
+
memo[i] = { outcome: e, errors: outcome_error } unless outcome_error.nil?
|
57
|
+
end.tap do |errs|
|
58
|
+
@outcome_errors = errs unless errs.empty?
|
59
|
+
end
|
60
|
+
else
|
61
|
+
add_outcome_error :self, :type, "This mutation must return Array instance (was #{result.class})"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
protected
|
68
|
+
|
69
|
+
def filtered result
|
70
|
+
@outputs = result.is_a?(Array) && has_outcome_errors? ? result.reject.with_index { |_, i| @outcome_errors[i] } : result
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/lib/mutations/version.rb
CHANGED
@@ -29,6 +29,7 @@ require 'mutations/outcome_hash_filter'
|
|
29
29
|
require 'mutations/outcome'
|
30
30
|
require 'mutations/command'
|
31
31
|
require_relative './mutations/command_returning_hash.rb'
|
32
|
+
require_relative './mutations/command_returning_array.rb'
|
32
33
|
|
33
34
|
module Mutations
|
34
35
|
class << self
|
@@ -48,6 +49,47 @@ module Mutations
|
|
48
49
|
@cache_constants
|
49
50
|
end
|
50
51
|
end
|
52
|
+
|
53
|
+
class ValidationException
|
54
|
+
def inspect
|
55
|
+
# rubocop:disable Style/FormatString
|
56
|
+
oid = '%x' % (object_id << 1)
|
57
|
+
"#<Mutations::ValidationException:0x#{oid.rjust(14, '0')} @errors=<#{errors}>>"
|
58
|
+
# rubocop:enable Style/FormatString
|
59
|
+
end
|
60
|
+
|
61
|
+
def message
|
62
|
+
errors.map do |k, v|
|
63
|
+
"#{k}: “#{v.message || v.symbol}”"
|
64
|
+
end.join(', ')
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
class YoValidationException < ValidationException
|
69
|
+
attr_reader :cause, :owner
|
70
|
+
def initialize(e, owner = nil)
|
71
|
+
super(e.is_a?(ValidationException) ? e.errors : Mutations::ErrorHash[error: Mutations::ErrorAtom.new(e.message.to_sym, e.class.name.to_sym, message: e.message)])
|
72
|
+
@cause, @owner = e, owner || caller
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
class Command
|
77
|
+
class << self
|
78
|
+
def yo! *args
|
79
|
+
result = run!(*args)
|
80
|
+
case name # name of the class
|
81
|
+
when ->(_) { !const_defined?('Hashie::Mash') } then result
|
82
|
+
when /Hash\z/ then ::Hashie::Mash.new(result)
|
83
|
+
when /Array\z/ then result.map { |h| ::Hashie::Mash.new(h) }
|
84
|
+
else result
|
85
|
+
end
|
86
|
+
rescue => e
|
87
|
+
yve = YoValidationException.new(e, self)
|
88
|
+
# we’ll re-raise either if no block was given, or if the block returned truthy
|
89
|
+
raise yve if !block_given? || (yield yve)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
51
93
|
end
|
52
94
|
|
53
95
|
Mutations.cache_constants = true
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mutations-validate-outcome
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.29
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aleksei Matiushkin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -125,6 +125,8 @@ files:
|
|
125
125
|
- ".codeclimate.yml"
|
126
126
|
- ".gitignore"
|
127
127
|
- ".rspec"
|
128
|
+
- ".rubocop.yml"
|
129
|
+
- ".rubocop_todo.yml"
|
128
130
|
- ".travis.yml"
|
129
131
|
- CODE_OF_CONDUCT.md
|
130
132
|
- Gemfile
|
@@ -132,6 +134,7 @@ files:
|
|
132
134
|
- README.md
|
133
135
|
- Rakefile
|
134
136
|
- lib/mutations/additional_filter.rb
|
137
|
+
- lib/mutations/command_returning_array.rb
|
135
138
|
- lib/mutations/command_returning_hash.rb
|
136
139
|
- lib/mutations/outcome_hash_filter.rb
|
137
140
|
- lib/mutations/version.rb
|