mutations-validate-outcome 0.7.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +26 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +10 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +79 -0
- data/Rakefile +26 -0
- data/lib/mutations/additional_filter.rb +15 -0
- data/lib/mutations/command_returning_hash.rb +122 -0
- data/lib/mutations/outcome_hash_filter.rb +151 -0
- data/lib/mutations/version.rb +5 -0
- data/lib/mutations_validate_outcome.rb +53 -0
- data/mutations-validate-outcome.gemspec +37 -0
- metadata +164 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2bd9b50392d4cd8659d609f182db477f237ec0b4
|
4
|
+
data.tar.gz: b83e83ea46b4128d0da1c42c541344d14cf6f64b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3645782fd77a42c27a33045570169c3101c14f4aad9d3704961eb645bc908cf9c6e4e336b08db80685a75d9845220140fdaf256bda69a1c68bebad87b2a46763
|
7
|
+
data.tar.gz: b4fc4ecc05833d28082e078fa41ba0387501b084fd712478f77600465ad315604c9f59c0a666709580fc09b34c076f9be9ec2ba68f8eb446c795abff32b691ef
|
data/.codeclimate.yml
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
---
|
2
|
+
engines:
|
3
|
+
duplication:
|
4
|
+
enabled: true
|
5
|
+
config:
|
6
|
+
languages:
|
7
|
+
- ruby
|
8
|
+
- javascript
|
9
|
+
- python
|
10
|
+
- php
|
11
|
+
fixme:
|
12
|
+
enabled: true
|
13
|
+
rubocop:
|
14
|
+
enabled: true
|
15
|
+
ratings:
|
16
|
+
paths:
|
17
|
+
- "**.inc"
|
18
|
+
- "**.js"
|
19
|
+
- "**.jsx"
|
20
|
+
- "**.module"
|
21
|
+
- "**.php"
|
22
|
+
- "**.py"
|
23
|
+
- "**.rb"
|
24
|
+
exclude_paths:
|
25
|
+
- features/
|
26
|
+
- spec/
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Aleksei Matiushkin
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# Mutations :: Mixin for validating outcome
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/am-kantox/mutations-validate-outcome.png)](https://travis-ci.org/am-kantox/mutations-validate-outcome)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/am-kantox/mutations-validate-outcome.png)](https://codeclimate.com/github/am-kantox/mutations-validate-outcome)
|
5
|
+
[![Test Coverage](https://codeclimate.com/github/am-kantox/mutations-validate-outcome/badges/coverage.svg)](https://codeclimate.com/github/am-kantox/mutations-validate-outcome/coverage)
|
6
|
+
[![Issue Count](https://codeclimate.com/github/am-kantox/mutations-validate-outcome/badges/issue_count.svg)](https://codeclimate.com/github/am-kantox/mutations-validate-outcome)
|
7
|
+
|
8
|
+
Mixin for [`cypriss/mutations`](https://github.com/cypriss/mutations) allowing validation of outcome
|
9
|
+
using the same techniques as an input validation by original gem.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
In your `Gemfile` make a following change:
|
14
|
+
|
15
|
+
```diff
|
16
|
+
- gem 'mutations'
|
17
|
+
+ gem 'mutations-validate-outcome'
|
18
|
+
```
|
19
|
+
|
20
|
+
In your code:
|
21
|
+
|
22
|
+
```diff
|
23
|
+
- require 'mutations'
|
24
|
+
+ require 'mutations-validate-outcome'
|
25
|
+
```
|
26
|
+
|
27
|
+
## Differences against [`cypriss/mutations`](https://github.com/cypriss/mutations)
|
28
|
+
|
29
|
+
* dropped a support for `1.9` and `j**`
|
30
|
+
* `CommandReturningHash` is a command, that is supposed to return… well, you guessed
|
31
|
+
* `outcome_required` and `outcome_optional` filters are introduced for the new `CommandReturningHash`
|
32
|
+
* `CommandReturningHash#validate_outcome` method is a sibling of `validate` for additional outcome validation
|
33
|
+
|
34
|
+
#### Example
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
class SimpleCommandReturningHash < Mutations::CommandReturningHash
|
38
|
+
required do
|
39
|
+
string :name, max_length: 10
|
40
|
+
string :email
|
41
|
+
end
|
42
|
+
|
43
|
+
optional do
|
44
|
+
integer :amount
|
45
|
+
end
|
46
|
+
|
47
|
+
outcome_required do
|
48
|
+
# outcome[:name] is to be shorter than 6 symbols
|
49
|
+
string :name, max_length: 5
|
50
|
+
# outcome[:email] is to be presented
|
51
|
+
string :email
|
52
|
+
end
|
53
|
+
|
54
|
+
outcome_optional do
|
55
|
+
integer :amount
|
56
|
+
end
|
57
|
+
|
58
|
+
def validate
|
59
|
+
add_error(:email, :invalid, 'Email must contain @') unless email && email.include?('@')
|
60
|
+
end
|
61
|
+
|
62
|
+
def execute
|
63
|
+
inputs
|
64
|
+
end
|
65
|
+
|
66
|
+
# outcome[:name] must include 'John' substring
|
67
|
+
def validate_outcome(outcome)
|
68
|
+
add_error(:name, :invalid, 'Name must contain john') unless outcome[:name].include?('John')
|
69
|
+
end
|
70
|
+
end
|
71
|
+
```
|
72
|
+
|
73
|
+
#### TBD:
|
74
|
+
|
75
|
+
* `CommandReturningArrayOfHashes`
|
76
|
+
|
77
|
+
## License
|
78
|
+
|
79
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rubygems'
|
3
|
+
|
4
|
+
require 'bundler'
|
5
|
+
require 'bundler/setup'
|
6
|
+
require 'bundler/gem_tasks'
|
7
|
+
|
8
|
+
require 'rake/testtask'
|
9
|
+
|
10
|
+
begin
|
11
|
+
Bundler.setup(:default, :development, :test)
|
12
|
+
rescue Bundler::BundlerError => e
|
13
|
+
$stderr.puts e.message
|
14
|
+
$stderr.puts 'Run `bundle install` to install missing gems'
|
15
|
+
exit e.status_code
|
16
|
+
end
|
17
|
+
|
18
|
+
desc 'Tests'
|
19
|
+
Rake::TestTask.new(:test) do |test|
|
20
|
+
test.libs << 'spec'
|
21
|
+
test.warning = false # Wow that outputs a lot of shit
|
22
|
+
# test.verbose = true
|
23
|
+
test.pattern = 'spec/**/*_spec.rb'
|
24
|
+
end
|
25
|
+
|
26
|
+
task default: :test
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'mutations/hash_filter'
|
2
|
+
require 'mutations/outcome_hash_filter'
|
3
|
+
require 'mutations/array_filter'
|
4
|
+
|
5
|
+
module Mutations
|
6
|
+
class AdditionalFilter < InputFilter
|
7
|
+
def self.inherited(subclass)
|
8
|
+
type_name = subclass.name[/^Mutations::([a-zA-Z]*)Filter$/, 1].underscore
|
9
|
+
|
10
|
+
Mutations::HashFilter.register_additional_filter(subclass, type_name)
|
11
|
+
Mutations::OutcomeHashFilter.register_additional_filter(subclass, type_name)
|
12
|
+
Mutations::ArrayFilter.register_additional_filter(subclass, type_name)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
module Mutations
|
2
|
+
class CommandReturningHash < Command
|
3
|
+
class << self
|
4
|
+
def create_outcome_attr_methods(meth, &block)
|
5
|
+
outcome_filters.send(meth, &block)
|
6
|
+
keys = outcome_filters.send("#{meth}_keys")
|
7
|
+
keys.each do |key|
|
8
|
+
define_method("outcome_#{key}") { @outputs[key] }
|
9
|
+
define_method("outcome_#{key}_present?") { @outputs.key?(key) }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
private :create_outcome_attr_methods
|
13
|
+
|
14
|
+
# %i(required optional).each do |m|
|
15
|
+
# meth = :"outcome_#{m}"
|
16
|
+
# define_method(meth) do |&block|
|
17
|
+
# create_outcome_attr_methods(meth, &block)
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
|
21
|
+
def outcome_required(&block)
|
22
|
+
create_outcome_attr_methods(:outcome_required, &block)
|
23
|
+
end
|
24
|
+
|
25
|
+
def outcome_optional(&block)
|
26
|
+
create_outcome_attr_methods(:outcome_optional, &block)
|
27
|
+
end
|
28
|
+
|
29
|
+
def outcome_filters
|
30
|
+
@outcome_filters ||= (CommandReturningHash == superclass) ? OutcomeHashFilter.new : superclass.outcome_filters.dup
|
31
|
+
end
|
32
|
+
|
33
|
+
def outcome_descriptions
|
34
|
+
outcome_filters.outcome_descriptions if outcome_filters.respond_to?(:outcome_descriptions)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def initialize(*args)
|
39
|
+
super(*args)
|
40
|
+
@outputs = {}
|
41
|
+
end
|
42
|
+
|
43
|
+
def outcome_filters
|
44
|
+
self.class.outcome_filters
|
45
|
+
end
|
46
|
+
|
47
|
+
def has_outcome_errors?
|
48
|
+
!@outcome_errors.nil?
|
49
|
+
end
|
50
|
+
|
51
|
+
def errors?
|
52
|
+
has_errors? || has_outcome_errors?
|
53
|
+
end
|
54
|
+
|
55
|
+
def errors
|
56
|
+
return nil unless errors?
|
57
|
+
|
58
|
+
ErrorHash.new.tap do |h|
|
59
|
+
h.merge! @errors if has_errors?
|
60
|
+
h.merge! @outcome_errors if has_outcome_errors?
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def run
|
65
|
+
return validation_outcome if has_errors?
|
66
|
+
validation_outcome(
|
67
|
+
execute.tap do |result|
|
68
|
+
if result.is_a?(Hash)
|
69
|
+
_, @outcome_errors = self.class.outcome_filters.filter(result)
|
70
|
+
validate_outcome(result) unless has_outcome_errors?
|
71
|
+
else
|
72
|
+
add_outcome_error :self, :type, "This mutation must return Hash instance (was #{result.class})"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
)
|
76
|
+
end
|
77
|
+
|
78
|
+
def run!
|
79
|
+
(outcome = run).success? ? outcome.result : (raise ValidationException.new(outcome.errors))
|
80
|
+
end
|
81
|
+
|
82
|
+
def validation_outcome(result = nil)
|
83
|
+
Outcome.new(!errors?, filtered(result), errors, @inputs)
|
84
|
+
end
|
85
|
+
|
86
|
+
protected
|
87
|
+
|
88
|
+
attr_reader :inputs, :raw_inputs, :outputs
|
89
|
+
|
90
|
+
def validate_outcome outcome
|
91
|
+
# Meant to be overridden
|
92
|
+
end
|
93
|
+
|
94
|
+
def filtered result
|
95
|
+
@outputs = result.is_a?(Hash) && has_outcome_errors? ? result.reject { |k, _| @outcome_errors[k.to_sym] } : result
|
96
|
+
end
|
97
|
+
|
98
|
+
# add_outcome_error("name", :too_short)
|
99
|
+
# add_outcome_error("colors.foreground", :not_a_color) # => to create errors = {colors: {foreground: :not_a_color}}
|
100
|
+
# or, supply a custom message:
|
101
|
+
# add_outcome_error("name", :too_short, "The name 'blahblahblah' is too short!")
|
102
|
+
def add_outcome_error(key, kind, message = nil)
|
103
|
+
raise ArgumentError.new("Invalid kind") unless kind.is_a?(Symbol)
|
104
|
+
|
105
|
+
@outcome_errors ||= ErrorHash.new
|
106
|
+
@outcome_errors.tap do |errs|
|
107
|
+
path = key.to_s.split(".")
|
108
|
+
last = path.pop
|
109
|
+
inner = path.inject(errs) do |cur_errors, part|
|
110
|
+
cur_errors[part.to_sym] ||= ErrorHash.new
|
111
|
+
end
|
112
|
+
inner[last] = ErrorAtom.new(key, kind, message: message)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def merge_outcome_errors(hash)
|
117
|
+
(@outcome_errors ||= ErrorHash.new).tap do |errs|
|
118
|
+
errs.merge!(hash) if hash.any?
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
module Mutations
|
2
|
+
class OutcomeHashFilter < InputFilter
|
3
|
+
def self.register_additional_filter(type_class, type_name)
|
4
|
+
define_method(type_name) do |*args, &block|
|
5
|
+
name = args[0]
|
6
|
+
options = args[1] || {}
|
7
|
+
|
8
|
+
@outcome_descriptions[name.to_sym] = current_outcome_description || 'N/A'
|
9
|
+
|
10
|
+
@current_outputs[name.to_sym] = type_class.new(options, &block)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
@default_options = {
|
15
|
+
nils: false
|
16
|
+
}
|
17
|
+
|
18
|
+
attr_accessor :optional_outputs, :required_outputs, :outcome_descriptions, :outcome_description
|
19
|
+
|
20
|
+
def initialize(opts = {}, &block)
|
21
|
+
super(opts)
|
22
|
+
|
23
|
+
@optional_outputs = {}
|
24
|
+
@current_outputs = @required_outputs = {}
|
25
|
+
@outcome_descriptions = {}
|
26
|
+
|
27
|
+
instance_eval(&block) if block_given?
|
28
|
+
end
|
29
|
+
|
30
|
+
def dup
|
31
|
+
dupped = OutcomeHashFilter.new
|
32
|
+
@optional_outputs.each_pair do |k, v|
|
33
|
+
dupped.optional_outputs[k] = v
|
34
|
+
end
|
35
|
+
@required_outputs.each_pair do |k, v|
|
36
|
+
dupped.required_outputs[k] = v
|
37
|
+
end
|
38
|
+
dupped
|
39
|
+
end
|
40
|
+
|
41
|
+
def desc(outcome_description)
|
42
|
+
@outcome_description = outcome_description
|
43
|
+
end
|
44
|
+
|
45
|
+
def current_outcome_description
|
46
|
+
(@outcome_description && @outcome_description.dup).tap do
|
47
|
+
@outcome_description = nil
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def outcome_required(&block)
|
52
|
+
@current_outputs = @required_outputs
|
53
|
+
instance_eval(&block)
|
54
|
+
end
|
55
|
+
|
56
|
+
def outcome_optional(&block)
|
57
|
+
@current_outputs = @optional_outputs
|
58
|
+
instance_eval(&block)
|
59
|
+
end
|
60
|
+
|
61
|
+
def outcome_required_keys
|
62
|
+
@required_outputs.keys
|
63
|
+
end
|
64
|
+
|
65
|
+
def outcome_optional_keys
|
66
|
+
@optional_outputs.keys
|
67
|
+
end
|
68
|
+
|
69
|
+
def hash(name, options = {}, &block)
|
70
|
+
@current_outputs[name.to_sym] = OutcomeHashFilter.new(options, &block)
|
71
|
+
end
|
72
|
+
|
73
|
+
def model(name, options = {})
|
74
|
+
@current_outputs[name.to_sym] = ModelFilter.new(name.to_sym, options)
|
75
|
+
end
|
76
|
+
|
77
|
+
def array(name, options = {}, &block)
|
78
|
+
name_sym = name.to_sym
|
79
|
+
@current_outputs[name.to_sym] = ArrayFilter.new(name_sym, options, &block)
|
80
|
+
end
|
81
|
+
|
82
|
+
def filter(data)
|
83
|
+
# Handle nil case
|
84
|
+
return (options[:nils] ? [nil, nil] : [nil, :nils]) if data.nil?
|
85
|
+
|
86
|
+
# Ensure it's a hash
|
87
|
+
return [data, :hash] unless data.is_a?(Hash)
|
88
|
+
|
89
|
+
# We always want a hash with indiffernet access
|
90
|
+
data = data.with_indifferent_access unless data.is_a?(HashWithIndifferentAccess)
|
91
|
+
|
92
|
+
errors = ErrorHash.new
|
93
|
+
filtered_data = HashWithIndifferentAccess.new
|
94
|
+
wildcard_filterer = nil
|
95
|
+
|
96
|
+
[[@required_outputs, true], [@optional_outputs, false]].each do |(outputs, is_required)|
|
97
|
+
outputs.each_pair do |key, filterer|
|
98
|
+
# If we are doing wildcards, then record so and move on
|
99
|
+
if key == :*
|
100
|
+
wildcard_filterer = filterer
|
101
|
+
next
|
102
|
+
end
|
103
|
+
|
104
|
+
data_element = data[key]
|
105
|
+
|
106
|
+
if data.key?(key)
|
107
|
+
sub_data, sub_error = filterer.filter(data_element)
|
108
|
+
|
109
|
+
case
|
110
|
+
when sub_error.nil? then filtered_data[key] = sub_data
|
111
|
+
when !is_required && filterer.discard_invalid? then data.delete(key)
|
112
|
+
when !is_required && sub_error == :empty && filterer.discard_empty? then data.delete(key)
|
113
|
+
when !is_required && sub_error == :nils && filterer.discard_nils? then data.delete(key)
|
114
|
+
else
|
115
|
+
sub_error = ErrorAtom.new(key, sub_error) if sub_error.is_a?(Symbol)
|
116
|
+
errors[key] = sub_error
|
117
|
+
end
|
118
|
+
next
|
119
|
+
end
|
120
|
+
|
121
|
+
if filterer.has_default?
|
122
|
+
filtered_data[key] = filterer.default
|
123
|
+
elsif is_required
|
124
|
+
errors[key] = ErrorAtom.new(key, :required)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
if wildcard_filterer
|
130
|
+
filtered_keys = data.keys - filtered_data.keys
|
131
|
+
|
132
|
+
filtered_keys.each do |key|
|
133
|
+
data_element = data[key]
|
134
|
+
|
135
|
+
sub_data, sub_error = wildcard_filterer.filter(data_element)
|
136
|
+
case
|
137
|
+
when sub_error.nil? then filtered_data[key] = sub_data
|
138
|
+
when wildcard_filterer.discard_invalid? then data.delete(key)
|
139
|
+
when sub_error == :empty && wildcard_filterer.discard_empty? then data.delete(key)
|
140
|
+
when sub_error == :nils && wildcard_filterer.discard_nils? then data.delete(key)
|
141
|
+
else
|
142
|
+
sub_error = ErrorAtom.new(key, sub_error) if sub_error.is_a?(Symbol)
|
143
|
+
errors[key] = sub_error
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
errors.any? ? [data, errors] : [filtered_data, nil]
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# require_relative 'mutations/additional_filter.rb'
|
2
|
+
# require 'mutations'
|
3
|
+
|
4
|
+
require_relative './mutations/version.rb'
|
5
|
+
|
6
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
7
|
+
require 'active_support/core_ext/string/inflections'
|
8
|
+
require 'date'
|
9
|
+
require 'time'
|
10
|
+
require 'bigdecimal'
|
11
|
+
|
12
|
+
require 'mutations/exception'
|
13
|
+
require 'mutations/errors'
|
14
|
+
require 'mutations/input_filter'
|
15
|
+
require_relative './mutations/additional_filter'
|
16
|
+
require_relative './mutations/outcome_hash_filter.rb'
|
17
|
+
require 'mutations/string_filter'
|
18
|
+
require 'mutations/integer_filter'
|
19
|
+
require 'mutations/float_filter'
|
20
|
+
require 'mutations/boolean_filter'
|
21
|
+
require 'mutations/duck_filter'
|
22
|
+
require 'mutations/date_filter'
|
23
|
+
require 'mutations/file_filter'
|
24
|
+
# require 'mutations/time_filter'
|
25
|
+
require 'mutations/model_filter'
|
26
|
+
require 'mutations/array_filter'
|
27
|
+
require 'mutations/hash_filter'
|
28
|
+
require 'mutations/outcome_hash_filter'
|
29
|
+
require 'mutations/outcome'
|
30
|
+
require 'mutations/command'
|
31
|
+
require_relative './mutations/command_returning_hash.rb'
|
32
|
+
|
33
|
+
module Mutations
|
34
|
+
class << self
|
35
|
+
def error_message_creator
|
36
|
+
@error_message_creator ||= DefaultErrorMessageCreator.new
|
37
|
+
end
|
38
|
+
|
39
|
+
def error_message_creator=(creator)
|
40
|
+
@error_message_creator = creator
|
41
|
+
end
|
42
|
+
|
43
|
+
def cache_constants=(val)
|
44
|
+
@cache_constants = val
|
45
|
+
end
|
46
|
+
|
47
|
+
def cache_constants?
|
48
|
+
@cache_constants
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
Mutations.cache_constants = true
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mutations/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'mutations-validate-outcome'
|
8
|
+
spec.version = Mutations::ValidateOutcome::VERSION
|
9
|
+
spec.authors = ['Aleksei Matiushkin']
|
10
|
+
spec.email = ['aleksei.matiushkin@kantox.com']
|
11
|
+
|
12
|
+
spec.summary = 'Mixin to add an outcome validation to mutations gem'
|
13
|
+
spec.description = 'Check mutations outcome when it’s a hash using the same techniques as the core mutations does for inputs'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
|
+
# delete this section to allow pushing this gem to any host.
|
18
|
+
|
19
|
+
raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.' unless spec.respond_to?(:metadata)
|
20
|
+
|
21
|
+
# spec.metadata['allowed_push_host'] = 'TODO: Set to \'http://mygemserver.com\''
|
22
|
+
|
23
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
spec.bindir = 'bin'
|
25
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ['lib']
|
27
|
+
|
28
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
29
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
30
|
+
|
31
|
+
spec.add_development_dependency 'minitest', '~> 5'
|
32
|
+
spec.add_development_dependency 'minitest-color', '~> 0'
|
33
|
+
spec.add_development_dependency 'minitest-documentation', '~> 0'
|
34
|
+
spec.add_development_dependency 'pry', '~> 0.10'
|
35
|
+
|
36
|
+
spec.add_dependency 'mutations', '~> 0.7', "= #{Mutations::ValidateOutcome::VERSION[0..-2]}"
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mutations-validate-outcome
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.7.22
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aleksei Matiushkin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest-color
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest-documentation
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.10'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.10'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: mutations
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.7'
|
104
|
+
- - '='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: 0.7.2
|
107
|
+
type: :runtime
|
108
|
+
prerelease: false
|
109
|
+
version_requirements: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - "~>"
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0.7'
|
114
|
+
- - '='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: 0.7.2
|
117
|
+
description: Check mutations outcome when it’s a hash using the same techniques as
|
118
|
+
the core mutations does for inputs
|
119
|
+
email:
|
120
|
+
- aleksei.matiushkin@kantox.com
|
121
|
+
executables: []
|
122
|
+
extensions: []
|
123
|
+
extra_rdoc_files: []
|
124
|
+
files:
|
125
|
+
- ".codeclimate.yml"
|
126
|
+
- ".gitignore"
|
127
|
+
- ".rspec"
|
128
|
+
- ".travis.yml"
|
129
|
+
- CODE_OF_CONDUCT.md
|
130
|
+
- Gemfile
|
131
|
+
- LICENSE.txt
|
132
|
+
- README.md
|
133
|
+
- Rakefile
|
134
|
+
- lib/mutations/additional_filter.rb
|
135
|
+
- lib/mutations/command_returning_hash.rb
|
136
|
+
- lib/mutations/outcome_hash_filter.rb
|
137
|
+
- lib/mutations/version.rb
|
138
|
+
- lib/mutations_validate_outcome.rb
|
139
|
+
- mutations-validate-outcome.gemspec
|
140
|
+
homepage:
|
141
|
+
licenses:
|
142
|
+
- MIT
|
143
|
+
metadata: {}
|
144
|
+
post_install_message:
|
145
|
+
rdoc_options: []
|
146
|
+
require_paths:
|
147
|
+
- lib
|
148
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
requirements: []
|
159
|
+
rubyforge_project:
|
160
|
+
rubygems_version: 2.4.8
|
161
|
+
signing_key:
|
162
|
+
specification_version: 4
|
163
|
+
summary: Mixin to add an outcome validation to mutations gem
|
164
|
+
test_files: []
|