game_validator 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b6fd7883c24e7c9a49116542af39eadf493a91c9fb3e5fb990270fc6bc7274a2
4
- data.tar.gz: 9027aa98b462ce2e7db8377f4c2962dab84c5728eddeabc0a0f6c156f63dc33a
3
+ metadata.gz: 3c542c118accd6ade4435166b23b621d9298c626b3c3101c8a6115b977cca209
4
+ data.tar.gz: bf75c56e76161880e4472e716f569345cc474013536453d6a81774508995c6d0
5
5
  SHA512:
6
- metadata.gz: b48d48ad94cda71306368f904879d8d5baba1e43059062ad34244922d9adca0e7b7c3b6418f07f133aeab7e341e09fb85d8a882927dadf4072b42821fd768bce
7
- data.tar.gz: 4e596a20f65556bc8ea328ce4cc472002862ca3a2e26963012f4abef563995ff49d5d6eb98c0252781a1539265fba08a7bbb92b2867cf328e7dd4332ef324fd8
6
+ metadata.gz: 61fd8aec87cb1d995351ba027b8b428c80ba953808f2dc2cf3be4538b8ae8af99426bbe581ec8fafde8eaf3eb57dccb60756d3881bf0e2bb26d44a2855a142fc
7
+ data.tar.gz: e9441c97742f8c52ae4cb861334312ced67d8867e765ab743d6a72bc1cde38908913ff5235770e8819506f505bdaff94b68a65d3db2d2e6dfbe05cbcb0b761b2
@@ -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.1.0' do |spec|
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']
@@ -6,6 +6,8 @@ end
6
6
 
7
7
  require 'game_validator/version'
8
8
  require 'game_validator/validator'
9
+ require 'game_validator/validator/base'
10
+ require 'game_validator/validator/result'
9
11
 
10
12
  module GameValidator
11
13
  class Error < StandardError; end
@@ -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
+
@@ -1,3 +1,3 @@
1
1
  module GameValidator
2
- VERSION = "0.1.0"
2
+ VERSION = '0.2.0'
3
3
  end
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.1.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-12 00:00:00.000000000 Z
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: