game_validator 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b6fd7883c24e7c9a49116542af39eadf493a91c9fb3e5fb990270fc6bc7274a2
4
+ data.tar.gz: 9027aa98b462ce2e7db8377f4c2962dab84c5728eddeabc0a0f6c156f63dc33a
5
+ SHA512:
6
+ metadata.gz: b48d48ad94cda71306368f904879d8d5baba1e43059062ad34244922d9adca0e7b7c3b6418f07f133aeab7e341e09fb85d8a882927dadf4072b42821fd768bce
7
+ data.tar.gz: 4e596a20f65556bc8ea328ce4cc472002862ca3a2e26963012f4abef563995ff49d5d6eb98c0252781a1539265fba08a7bbb92b2867cf328e7dd4332ef324fd8
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 2.0.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in game_validator.gemspec
4
+ gemspec
@@ -0,0 +1,82 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ game_validator (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ concurrent-ruby (1.1.7)
10
+ diff-lcs (1.4.4)
11
+ dry-configurable (0.12.0)
12
+ concurrent-ruby (~> 1.0)
13
+ dry-core (~> 0.5, >= 0.5.0)
14
+ dry-container (0.7.2)
15
+ concurrent-ruby (~> 1.0)
16
+ dry-configurable (~> 0.1, >= 0.1.3)
17
+ dry-core (0.5.0)
18
+ concurrent-ruby (~> 1.0)
19
+ dry-equalizer (0.3.0)
20
+ dry-inflector (0.2.0)
21
+ dry-initializer (3.0.4)
22
+ dry-logic (1.1.0)
23
+ concurrent-ruby (~> 1.0)
24
+ dry-core (~> 0.5, >= 0.5)
25
+ dry-monads (1.3.5)
26
+ concurrent-ruby (~> 1.0)
27
+ dry-core (~> 0.4, >= 0.4.4)
28
+ dry-equalizer
29
+ dry-schema (1.5.6)
30
+ concurrent-ruby (~> 1.0)
31
+ dry-configurable (~> 0.8, >= 0.8.3)
32
+ dry-core (~> 0.4)
33
+ dry-equalizer (~> 0.2)
34
+ dry-initializer (~> 3.0)
35
+ dry-logic (~> 1.0)
36
+ dry-types (~> 1.4)
37
+ dry-types (1.4.0)
38
+ concurrent-ruby (~> 1.0)
39
+ dry-container (~> 0.3)
40
+ dry-core (~> 0.4, >= 0.4.4)
41
+ dry-equalizer (~> 0.3)
42
+ dry-inflector (~> 0.1, >= 0.1.2)
43
+ dry-logic (~> 1.0, >= 1.0.2)
44
+ dry-validation (1.6.0)
45
+ concurrent-ruby (~> 1.0)
46
+ dry-container (~> 0.7, >= 0.7.1)
47
+ dry-core (~> 0.4)
48
+ dry-equalizer (~> 0.2)
49
+ dry-initializer (~> 3.0)
50
+ dry-schema (~> 1.5, >= 1.5.2)
51
+ method_call_count (0.1.1)
52
+ rake (10.5.0)
53
+ rspec (3.10.0)
54
+ rspec-core (~> 3.10.0)
55
+ rspec-expectations (~> 3.10.0)
56
+ rspec-mocks (~> 3.10.0)
57
+ rspec-core (3.10.1)
58
+ rspec-support (~> 3.10.0)
59
+ rspec-expectations (3.10.1)
60
+ diff-lcs (>= 1.2.0, < 2.0)
61
+ rspec-support (~> 3.10.0)
62
+ rspec-mocks (3.10.1)
63
+ diff-lcs (>= 1.2.0, < 2.0)
64
+ rspec-support (~> 3.10.0)
65
+ rspec-support (3.10.1)
66
+
67
+ PLATFORMS
68
+ ruby
69
+
70
+ DEPENDENCIES
71
+ bundler (~> 2.0)
72
+ dry-initializer
73
+ dry-monads
74
+ dry-types
75
+ dry-validation
76
+ game_validator!
77
+ method_call_count
78
+ rake (~> 10.0)
79
+ rspec (~> 3.0)
80
+
81
+ BUNDLED WITH
82
+ 2.0.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Colin Horner
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.
@@ -0,0 +1,39 @@
1
+ # GameValidator
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/game_validator`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'game_validator'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install game_validator
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/game_validator.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "game_validator"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,39 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "game_validator/version"
4
+
5
+ Gem::Specification.new 'game_validator', '0.1.0' do |spec|
6
+ spec.name = 'game_validator'
7
+ spec.version = GameValidator::VERSION
8
+ spec.authors = ['Colin Horner']
9
+ spec.email = ['25807014+cmcolinh@users.noreply.github.com']
10
+
11
+ spec.summary = 'Game validator'
12
+ spec.description = 'Validator for turn based games'
13
+ #spec.homepage = 'TODO: Put your gem's website or public repo URL here.'
14
+ spec.license = 'MIT'
15
+
16
+ spec.metadata['allowed_push_host'] = 'https://www.rubygems.org'
17
+
18
+ #spec.metadata["homepage_uri"] = spec.homepage
19
+ #spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
20
+ #spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ end
27
+ spec.bindir = 'exe'
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ['lib']
30
+
31
+ spec.add_development_dependency 'bundler', '~> 2.0'
32
+ spec.add_development_dependency 'dry-initializer'
33
+ spec.add_development_dependency 'dry-monads'
34
+ spec.add_development_dependency 'dry-types'
35
+ spec.add_development_dependency 'dry-validation'
36
+ spec.add_development_dependency 'method_call_count'
37
+ spec.add_development_dependency 'rake', '~> 10.0'
38
+ spec.add_development_dependency 'rspec', '~> 3.0'
39
+ end
@@ -0,0 +1,13 @@
1
+ require 'dry-types'
2
+
3
+ module Types
4
+ include Dry.Types()
5
+ end
6
+
7
+ require 'game_validator/version'
8
+ require 'game_validator/validator'
9
+
10
+ module GameValidator
11
+ class Error < StandardError; end
12
+ # Your code goes here...
13
+ end
@@ -0,0 +1,21 @@
1
+ # frozen string_literal: true
2
+
3
+ require 'game_validator/validator/base'
4
+
5
+ module GameValidator
6
+ class Validator
7
+ extend Dry::Initializer
8
+ option :validate_player_action_and_user, type: Types.Interface(:call)
9
+ option :full_validator_for, type: Types::Hash
10
+
11
+ def call(action_hash:, user:)
12
+ a = action_hash.dup
13
+ a[:user] = user
14
+ result = validate_player_action_and_user.(a)
15
+ return result if result.failure?
16
+ validate = full_validator_for[[a[:player_action], a[:user].admin?]]
17
+ validate.(a)
18
+ end
19
+ end
20
+ end
21
+
@@ -0,0 +1,34 @@
1
+ # frozen string_literal: true
2
+
3
+ require 'dry-validation'
4
+ require 'dry-initializer'
5
+
6
+ Dry::Validation.load_extensions(:monads)
7
+
8
+ module GameValidator
9
+ class Validator
10
+ class Base < Dry::Validation::Contract
11
+ extend Dry::Initializer
12
+ option :legal_options, type: Types::Array.of(Types::String)
13
+ option :next_player_id, type: Types::Coercible::Integer
14
+
15
+ params do
16
+ required(:player_action).filled(:string)
17
+ required(:user).filled(Types.Interface(:id, :admin?))
18
+ end
19
+
20
+ rule(:player_action) do
21
+ if !legal_options.include?(values[:player_action])
22
+ key.failure({text: "player_action '#{values[:player_action]}' is not permitted", status: 400})
23
+ end
24
+ end
25
+
26
+ rule(:user) do
27
+ if !values[:user].id.eql?(next_player_id) && !values[:user].admin?
28
+ key.failure({text: 'Not logged in', status: 401})
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+
@@ -0,0 +1,3 @@
1
+ module GameValidator
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,172 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: game_validator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Colin Horner
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-01-12 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: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dry-initializer
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: dry-monads
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: dry-types
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: dry-validation
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: method_call_count
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.0'
125
+ description: Validator for turn based games
126
+ email:
127
+ - 25807014+cmcolinh@users.noreply.github.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - ".travis.yml"
135
+ - Gemfile
136
+ - Gemfile.lock
137
+ - LICENSE.txt
138
+ - README.md
139
+ - Rakefile
140
+ - bin/console
141
+ - bin/setup
142
+ - game_validator.gemspec
143
+ - lib/game_validator.rb
144
+ - lib/game_validator/validator.rb
145
+ - lib/game_validator/validator/.base.rb.swp
146
+ - lib/game_validator/validator/base.rb
147
+ - lib/game_validator/version.rb
148
+ homepage:
149
+ licenses:
150
+ - MIT
151
+ metadata:
152
+ allowed_push_host: https://www.rubygems.org
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubygems_version: 3.0.3
169
+ signing_key:
170
+ specification_version: 4
171
+ summary: Game validator
172
+ test_files: []