game_validator 0.1.0 → 0.2.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/game_validator.gemspec +1 -1
- data/lib/game_validator.rb +2 -0
- data/lib/game_validator/validator.rb +6 -2
- data/lib/game_validator/validator/result.rb +21 -0
- data/lib/game_validator/validator/result/failure.rb +27 -0
- data/lib/game_validator/validator/result/failure/builder.rb +20 -0
- data/lib/game_validator/validator/result/failure/node.rb +23 -0
- data/lib/game_validator/version.rb +1 -1
- metadata +6 -3
- data/lib/game_validator/validator/.base.rb.swp +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c542c118accd6ade4435166b23b621d9298c626b3c3101c8a6115b977cca209
|
4
|
+
data.tar.gz: bf75c56e76161880e4472e716f569345cc474013536453d6a81774508995c6d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61fd8aec87cb1d995351ba027b8b428c80ba953808f2dc2cf3be4538b8ae8af99426bbe581ec8fafde8eaf3eb57dccb60756d3881bf0e2bb26d44a2855a142fc
|
7
|
+
data.tar.gz: e9441c97742f8c52ae4cb861334312ced67d8867e765ab743d6a72bc1cde38908913ff5235770e8819506f505bdaff94b68a65d3db2d2e6dfbe05cbcb0b761b2
|
data/game_validator.gemspec
CHANGED
@@ -2,7 +2,7 @@ lib = File.expand_path("lib", __dir__)
|
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
3
|
require "game_validator/version"
|
4
4
|
|
5
|
-
Gem::Specification.new 'game_validator', '0.
|
5
|
+
Gem::Specification.new 'game_validator', '0.2.0' do |spec|
|
6
6
|
spec.name = 'game_validator'
|
7
7
|
spec.version = GameValidator::VERSION
|
8
8
|
spec.authors = ['Colin Horner']
|
data/lib/game_validator.rb
CHANGED
@@ -7,14 +7,18 @@ module GameValidator
|
|
7
7
|
extend Dry::Initializer
|
8
8
|
option :validate_player_action_and_user, type: Types.Interface(:call)
|
9
9
|
option :full_validator_for, type: Types::Hash
|
10
|
+
option :build_failure, type: Types.Interface(:call),
|
11
|
+
default: ->{GameValidator::Validator::Result::Failure::Builder::new}
|
10
12
|
|
11
13
|
def call(action_hash:, user:)
|
12
14
|
a = action_hash.dup
|
13
15
|
a[:user] = user
|
14
16
|
result = validate_player_action_and_user.(a)
|
15
|
-
return result if result.failure?
|
17
|
+
return build_failure.(errors: result.errors) if result.failure?
|
16
18
|
validate = full_validator_for[[a[:player_action], a[:user].admin?]]
|
17
|
-
validate.(a)
|
19
|
+
result = validate.(a)
|
20
|
+
return build_failure.(errors: result.errors) if result.failure?
|
21
|
+
result
|
18
22
|
end
|
19
23
|
end
|
20
24
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen string_literal: true
|
2
|
+
|
3
|
+
require 'game_validator/validator/result/failure'
|
4
|
+
require 'game_validator/validator/result/failure/node'
|
5
|
+
require 'game_validator/validator/result/failure/builder'
|
6
|
+
|
7
|
+
module GameValidator
|
8
|
+
class Validator
|
9
|
+
class Result < SimpleDelegator
|
10
|
+
def initialize(result:, execute:)
|
11
|
+
super(Types.Interface(:failure?, :success?, :to_h).call(result))
|
12
|
+
@execute = Types.Interface(:call).call(execute)
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(**args)
|
16
|
+
@execute.(to_h, args)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen string_literal: true
|
2
|
+
|
3
|
+
module GameValidator
|
4
|
+
class Validator
|
5
|
+
class Result < SimpleDelegator
|
6
|
+
class Failure
|
7
|
+
extend Dry::Initializer
|
8
|
+
option :node, type: Types.Interface(:accept)
|
9
|
+
|
10
|
+
def call(**args)
|
11
|
+
change_orders = Types.Interface(:push).call(args[:change_orders])
|
12
|
+
change_orders = change_orders.push(node)
|
13
|
+
change_orders
|
14
|
+
end
|
15
|
+
|
16
|
+
def failure?
|
17
|
+
true
|
18
|
+
end
|
19
|
+
|
20
|
+
def success?
|
21
|
+
false
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen string_literal: true
|
2
|
+
|
3
|
+
require 'game_validator/validator/result/failure'
|
4
|
+
require 'game_validator/validator/result/failure/node'
|
5
|
+
|
6
|
+
module GameValidator
|
7
|
+
class Validator
|
8
|
+
class Result < SimpleDelegator
|
9
|
+
class Failure
|
10
|
+
class Builder
|
11
|
+
def call(errors:)
|
12
|
+
GameValidator::Validator::Result::Failure::new(
|
13
|
+
node: GameValidator::Validator::Result::Failure::Node::new(errors: errors))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen string_literal: true
|
2
|
+
|
3
|
+
require 'dry-initializer'
|
4
|
+
require 'dry-types'
|
5
|
+
|
6
|
+
module GameValidator
|
7
|
+
class Validator
|
8
|
+
class Result < SimpleDelegator
|
9
|
+
class Failure
|
10
|
+
class Node
|
11
|
+
extend Dry::Initializer
|
12
|
+
option :errors, type: Types.Interface(:messages)
|
13
|
+
|
14
|
+
def accept(visitor)
|
15
|
+
visitor = Types.Interface(:handle_validation_error).call(visitor)
|
16
|
+
visitor.handle_validation_error(self)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: game_validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Colin Horner
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01-
|
11
|
+
date: 2021-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -142,8 +142,11 @@ files:
|
|
142
142
|
- game_validator.gemspec
|
143
143
|
- lib/game_validator.rb
|
144
144
|
- lib/game_validator/validator.rb
|
145
|
-
- lib/game_validator/validator/.base.rb.swp
|
146
145
|
- lib/game_validator/validator/base.rb
|
146
|
+
- lib/game_validator/validator/result.rb
|
147
|
+
- lib/game_validator/validator/result/failure.rb
|
148
|
+
- lib/game_validator/validator/result/failure/builder.rb
|
149
|
+
- lib/game_validator/validator/result/failure/node.rb
|
147
150
|
- lib/game_validator/version.rb
|
148
151
|
homepage:
|
149
152
|
licenses:
|
Binary file
|