arkaan 0.9.6 → 0.9.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/arkaan/campaign.rb +3 -0
- data/lib/arkaan/concerns/enumerable.rb +1 -1
- data/lib/arkaan/utils/controller.rb +2 -0
- data/lib/arkaan/utils/errors.rb +3 -0
- data/lib/arkaan/utils/errors/bad_request.rb +4 -13
- data/lib/arkaan/utils/errors/forbidden.rb +5 -14
- data/lib/arkaan/utils/errors/http_error.rb +30 -0
- data/lib/arkaan/utils/errors/not_found.rb +5 -14
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82b48398f8819576417eade7cf5eba42d356d5ce
|
4
|
+
data.tar.gz: b2cfd36e16de4b6b4fa50d85e5a17bdc41b3b8aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f4dcd6b8d2c101495e0fa339deab9c1c063604f9c7e10865084b59506d3b6daa1fbe2735a69e2284e2e52cad63337dce697ae8b8bf8a5017f5565717a68afc6
|
7
|
+
data.tar.gz: 2dd59574e0346ab75935889a48d2b56133671b56eaa3c98a900267bb86be60517b42b2e64baf30507e2bab556b1c59c01d6bc11b97917bf50ed67ba919452a09
|
data/lib/arkaan/campaign.rb
CHANGED
@@ -17,6 +17,9 @@ module Arkaan
|
|
17
17
|
# @!attribute [rw] tags
|
18
18
|
# @return [Array<String>] an array of tags describing characteristics of this campaign.
|
19
19
|
field :tags, type: Array, default: []
|
20
|
+
# @!attributes [rw] max_players
|
21
|
+
# @return [Integer] the maximum number of players allowed in this campaign.
|
22
|
+
field :max_players, type: Integer, default: 5
|
20
23
|
|
21
24
|
# @!attribute [rw] creator
|
22
25
|
# @return [Arkaan::Campaign] the account creating the campaign, and considered "game master".
|
@@ -10,7 +10,7 @@ module Arkaan
|
|
10
10
|
module ClassMethods
|
11
11
|
|
12
12
|
# Creates the field with the given name, set of possible values, and options.
|
13
|
-
# @param
|
13
|
+
# @param field_name [String] the name of the enumerated field.
|
14
14
|
# @param values [Array<Symbol>] the possible values of the enumerated field.
|
15
15
|
# @param options [Hash<Symbol, Any>] the possible options for the field.
|
16
16
|
def enum_field(field_name, values, options = {})
|
@@ -121,6 +121,8 @@ module Arkaan
|
|
121
121
|
return params.select { |key, value| fields.include?(key) }
|
122
122
|
end
|
123
123
|
|
124
|
+
# Creates a custom error from an existing Arkaan exception class.
|
125
|
+
# @param exception {StandardError} the exception to transform in a usable error.
|
124
126
|
def handle_arkaan_exception(exception)
|
125
127
|
custom_error(exception.status, "#{exception.action}.#{exception.field}.#{exception.error}")
|
126
128
|
end
|
data/lib/arkaan/utils/errors.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
module Arkaan
|
2
2
|
module Utils
|
3
|
+
# Module gathering all the exception classes used throughout the utils module, mainly linked to HTTP errors.
|
4
|
+
# @author Vincent Courtois <courtois.vincent@outlook.com>
|
3
5
|
module Errors
|
4
6
|
autoload :BadRequest, 'arkaan/utils/errors/bad_request'
|
5
7
|
autoload :Forbidden , 'arkaan/utils/errors/forbidden'
|
6
8
|
autoload :NotFound , 'arkaan/utils/errors/not_found'
|
9
|
+
autoload :HTTPError , 'arkaan/utils/errors/http_error'
|
7
10
|
end
|
8
11
|
end
|
9
12
|
end
|
@@ -1,21 +1,12 @@
|
|
1
1
|
module Arkaan
|
2
2
|
module Utils
|
3
3
|
module Errors
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
attr_accessor :action
|
8
|
-
|
9
|
-
attr_accessor :error
|
4
|
+
# A bad request error is raised when the data given to a model makes this model invalid.
|
5
|
+
# @author Vincent Courtois <courtois.vincent@outlook.com>
|
6
|
+
class BadRequest < Arkaan::Utils::Errors::HTTPError
|
10
7
|
|
11
8
|
def initialize(action:, field:, error:)
|
12
|
-
|
13
|
-
@field = field
|
14
|
-
@error = error
|
15
|
-
end
|
16
|
-
|
17
|
-
def status
|
18
|
-
return 400
|
9
|
+
super(action, field, error, 400)
|
19
10
|
end
|
20
11
|
end
|
21
12
|
end
|
@@ -1,21 +1,12 @@
|
|
1
1
|
module Arkaan
|
2
2
|
module Utils
|
3
3
|
module Errors
|
4
|
-
|
5
|
-
|
4
|
+
# A forbidden error occurs when a user tries to perform an action he's not allowed to.
|
5
|
+
# @author Vincent Courtois <courtois.vincent@outlook.com>
|
6
|
+
class Forbidden < Arkaan::Utils::Errors::HTTPError
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
attr_accessor :error
|
10
|
-
|
11
|
-
def initialize(action:, field:, error:)
|
12
|
-
@action = action
|
13
|
-
@field = field
|
14
|
-
@error = error
|
15
|
-
end
|
16
|
-
|
17
|
-
def status
|
18
|
-
return 403
|
8
|
+
def initialize (field:, action:, error:)
|
9
|
+
super(action, field, error, 403)
|
19
10
|
end
|
20
11
|
end
|
21
12
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Arkaan
|
2
|
+
module Utils
|
3
|
+
module Errors
|
4
|
+
# Standard class parent to all specialized http errors.
|
5
|
+
# @author Vincent Courtois <courtois.vincent@outlook.com>
|
6
|
+
class HTTPError < StandardError
|
7
|
+
|
8
|
+
# @!attribute [rw] field
|
9
|
+
# @return [String, Symbol] the name of the field in error in the model.
|
10
|
+
attr_accessor :field
|
11
|
+
# @!attribute [rw] action
|
12
|
+
# @return [String] the name of the action the user was trying to perform on the model (often crate or update).
|
13
|
+
attr_accessor :action
|
14
|
+
# @attribute [rw] error
|
15
|
+
# @return [String] the label of the error returned by the model.
|
16
|
+
attr_accessor :error
|
17
|
+
# @attribute [rw] status
|
18
|
+
# @return [Integer] the HTTP status code as a number (eg: 400, 422 or 500)
|
19
|
+
attr_accessor :status
|
20
|
+
|
21
|
+
def initialize (action, field, error, status)
|
22
|
+
@action = action
|
23
|
+
@field = field.to_s
|
24
|
+
@error = error
|
25
|
+
@status = status
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -1,21 +1,12 @@
|
|
1
1
|
module Arkaan
|
2
2
|
module Utils
|
3
3
|
module Errors
|
4
|
-
|
5
|
-
|
4
|
+
# A not found error occurs when a user tries to reach a resource that does not exist.
|
5
|
+
# @author Vincent Courtois <courtois.vincent@outlook.com>
|
6
|
+
class NotFound < Arkaan::Utils::Errors::HTTPError
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
attr_accessor :error
|
10
|
-
|
11
|
-
def initialize(action:, field:, error:)
|
12
|
-
@action = action
|
13
|
-
@field = field
|
14
|
-
@error = error
|
15
|
-
end
|
16
|
-
|
17
|
-
def status
|
18
|
-
return 404
|
8
|
+
def initialize (field:, action:, error:)
|
9
|
+
super(action, field, error, 404)
|
19
10
|
end
|
20
11
|
end
|
21
12
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arkaan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vincent Courtois
|
@@ -247,6 +247,7 @@ files:
|
|
247
247
|
- lib/arkaan/utils/errors.rb
|
248
248
|
- lib/arkaan/utils/errors/bad_request.rb
|
249
249
|
- lib/arkaan/utils/errors/forbidden.rb
|
250
|
+
- lib/arkaan/utils/errors/http_error.rb
|
250
251
|
- lib/arkaan/utils/errors/not_found.rb
|
251
252
|
- lib/arkaan/utils/micro_service.rb
|
252
253
|
- lib/arkaan/utils/seeder.rb
|