game_validator 0.3.0 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 919eea6127e5739639bfd7034cf90ac44f4686dcc98fe8bd05d5cec91214458e
4
- data.tar.gz: 2169e75bd4797488853984472902d076da7c032eee445ba89ad02a5db98f7fac
3
+ metadata.gz: 49e3f324917b46d542868516b19cae218850e8599a4c0ae32aabc2e8534bdf76
4
+ data.tar.gz: e7b4b68f0bf8b4fe37421ed6ee3b8749bcb8f9a07f5344bf020b5632ce1b76c9
5
5
  SHA512:
6
- metadata.gz: c9002a19d864067465f51a27cf344087d75f94b22704e2b6bccb07d38d3b9c2d56470bddac6a13a90874b7f8c34feb8e88a2afdf5b318294e0b6a7e6c1ff7438
7
- data.tar.gz: 41e821d0ab7d559142a95dce2afd1032a4926a846e0be6d338f65abbc74804310668e922176940244eebbef5d096a994f5ea80e1832a7aa825fbf16b16307ab7
6
+ metadata.gz: b01fb1013aae4f2cdbded8ced72af6a5f02f06026acaba11efd7d4bb1a1e85eb9609d03dd1bf37a71e2b6fa354a00876e246fd320cc079b0f25f7e886bff9632
7
+ data.tar.gz: 1fd0f020305734494a12a61739f2acdf295755d93d65439895a94f0cf2143e148d589ca0751c2bb9253e433a3e73dfc7edb2ddff9c348eade0929c3a071ed2d2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- game_validator (0.2.0)
4
+ game_validator (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -83,6 +83,23 @@ GameValidator::Validator::new(
83
83
  full_validator_for: full_validator)
84
84
  ```
85
85
 
86
+ You can also wrap successful results from the validator, using GameValidator::Validator::ValidateToAction and GameValidator::Validator::Result
87
+ ```
88
+ class DoStuff
89
+ def call(change_orders:, **args)
90
+ # do stuff
91
+ change_orders
92
+ end
93
+ end
94
+
95
+ GameValidator::Validator::ValidateToAction::new(
96
+ validator: some_regular validator,
97
+ wrap: ->(successful_result){GameValidator::Validator::Result::new(
98
+ result: successful_result,
99
+ execute: DoStuff::new)})
100
+ ```
101
+
102
+
86
103
  ## Development
87
104
 
88
105
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -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.3.0' do |spec|
5
+ Gem::Specification.new 'game_validator', '0.4.0' do |spec|
6
6
  spec.name = 'game_validator'
7
7
  spec.version = GameValidator::VERSION
8
8
  spec.authors = ['Colin Horner']
@@ -17,7 +17,7 @@ module GameValidator
17
17
  result = validate_player_action_and_user.(a)
18
18
  return build_failure.(errors: result.errors) if result.failure?
19
19
  validate = full_validator_for[[a[:player_action], a[:user].admin?]]
20
- result = validate.(a)
20
+ result = validate.(action_hash)
21
21
  return build_failure.(errors: result.errors) if result.failure?
22
22
  result
23
23
  end
@@ -1,14 +1,12 @@
1
1
  # frozen string_literal: true
2
2
 
3
3
  require 'dry-validation'
4
- require 'dry-initializer'
5
4
 
6
5
  Dry::Validation.load_extensions(:monads)
7
6
 
8
7
  module GameValidator
9
8
  class Validator
10
9
  class Base < Dry::Validation::Contract
11
- extend Dry::Initializer
12
10
  option :legal_options, type: Types::Array.of(Types::String)
13
11
  option :next_player_id, type: Types::Coercible::Integer
14
12
 
@@ -0,0 +1,20 @@
1
+ # frozen string_literal: true
2
+
3
+ require 'dry-initializer'
4
+
5
+ module GameValidator
6
+ class Validator
7
+ class ValidateToAction
8
+ extend Dry::Initializer
9
+ option :validate, type: Types.Interface(:call)
10
+ option :wrap, type: Types.Interface(:call)
11
+
12
+ def call(action_hash)
13
+ result = validate.(action_hash)
14
+ result = wrap.(result) if result.success?
15
+ result
16
+ end
17
+ end
18
+ end
19
+ end
20
+
@@ -1,3 +1,3 @@
1
1
  module GameValidator
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.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.3.0
4
+ version: 0.4.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-22 00:00:00.000000000 Z
11
+ date: 2021-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -148,6 +148,7 @@ files:
148
148
  - lib/game_validator/validator/result/failure.rb
149
149
  - lib/game_validator/validator/result/failure/builder.rb
150
150
  - lib/game_validator/validator/result/failure/node.rb
151
+ - lib/game_validator/validator/validate_to_action.rb
151
152
  - lib/game_validator/version.rb
152
153
  homepage:
153
154
  licenses: