blacksheep 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +15 -15
- data/blacksheep.gemspec +1 -1
- data/lib/blacksheep/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f9f95a300f2d7c84826615cb86a66fabe8ecdd680edabf6b9e960973d8f5f83
|
4
|
+
data.tar.gz: 3cdfd65ec9647bed1ff5df0261b000227f395d379a9c310e8def4de9b0439c83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac515283bff176a47ffa4b6159e169c7a3776bc1e2d0f587182e479420b805b0633e2f909a9720bbff15bcc68776ce9f180e51e6a014e2e2ef2ae261b6114d94
|
7
|
+
data.tar.gz: 1c7008322b347109e570b87f8a83b6512a7380c4021e779655fb80f8bd426efc9aad3a1a606c73dd09e7735f2a85dd927e5f8f472ce5650323ec7d90283c82cf
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -24,24 +24,24 @@ Or install it yourself as:
|
|
24
24
|
|
25
25
|
### Actions
|
26
26
|
|
27
|
-
Core
|
27
|
+
Core of blacksheep is the `Blacksheep::Action`. It provides basic functionality to handle rest API actions - but can handle other actions as well. The core methods of actions are:
|
28
28
|
|
29
|
-
* #perform
|
30
|
-
* #call
|
29
|
+
* #perform with a block that implements the action
|
30
|
+
* #call on an action instance for processing and a potential block for result matching (see dcorators below).
|
31
31
|
|
32
32
|
`#perform` takes a block that is executed with the params passed. #perform has the following api:
|
33
33
|
`#perform(params, current_user: (default to nil), **options)`
|
34
34
|
|
35
|
-
`#call` can be used when a Blacksheep::Action is sublassed as an action processing its opertation in a call method with the same signature of `#perform`
|
35
|
+
`#call` can be used when a Blacksheep::Action is sublassed as an action processing its opertation in a call method with the same signature of `#perform`. When using the `ResultMatcher` decorator a block can be used for result matching.
|
36
36
|
|
37
37
|
|
38
38
|
```ruby
|
39
|
-
|
39
|
+
#perform sample
|
40
40
|
action_result = Blacksheep::Action.new.perform(params) do |params|
|
41
41
|
# do somethin with the params that return a `Blacksheep::ActionResult`
|
42
42
|
end
|
43
43
|
|
44
|
-
|
44
|
+
#call sample
|
45
45
|
action_result = MyAction.new.call(params, current_user: current_user)
|
46
46
|
```
|
47
47
|
|
@@ -50,14 +50,14 @@ action_result = MyAction.new.call(params, current_user: current_user)
|
|
50
50
|
|
51
51
|
### Decorators
|
52
52
|
|
53
|
-
This alone does not give any benefit.
|
53
|
+
This alone does not give any benefit. Modifying the action with decorators adds additional functionality:
|
54
54
|
|
55
55
|
* `JsonTransformer`
|
56
56
|
* `Localizer`
|
57
57
|
* `DefaultErrorHandler`
|
58
58
|
* `ResultMatcher`
|
59
59
|
|
60
|
-
The decaorators can be configured
|
60
|
+
The decaorators can be configured globally by defining them in an initializer.
|
61
61
|
|
62
62
|
```ruby
|
63
63
|
# Defining decorator wheras innermost is first
|
@@ -74,7 +74,7 @@ A localizer sets the I18n locale when passed in a request parameter named `_loca
|
|
74
74
|
|
75
75
|
#### Blacksheep::Decorators::DefaultErrorHandler
|
76
76
|
|
77
|
-
A default error handler can be used in API opertions. The handler catches an error and returns
|
77
|
+
A default error handler can be used in API opertions. The handler catches an error and returns an ActionResult such as…
|
78
78
|
|
79
79
|
```ruby
|
80
80
|
def handle_exception(exception)
|
@@ -93,20 +93,20 @@ def handle_exception(exception)
|
|
93
93
|
end
|
94
94
|
```
|
95
95
|
|
96
|
-
You can write your own
|
96
|
+
You can write your own ErrorHandler by including the module `Blacksheep::Decorators::ErrorHandler` and implementing the method `#handle_exception(<Exception>)`.
|
97
97
|
|
98
98
|
|
99
99
|
#### Blacksheep::Decorators::JsonTransformer
|
100
100
|
|
101
|
-
Assuming the params is a json payload with a specific caseing (e.g. camelCase when used in a JS application such as
|
102
|
-
The request has to define the case passed (and hence desired response casing) in the parameter `_case`. If the case is requests as `camel` then
|
101
|
+
Assuming the params is a json payload with a specific caseing (e.g. camelCase when used in a JS application such as Vue) the JsonTransfomer takes the params and transforms it's keys into snake_case as used in ruby often.
|
102
|
+
The request has to define the case passed (and hence desired response casing) in the parameter `_case`. If the case is requests as `camel` then parameter keys are transformed to `snake_case` before beeing passed into the action and are transformed back into CamelCase when leaving the operation.
|
103
103
|
|
104
104
|
If JsonTransfomer is used the action should return a simple JSON structure which is transfformed and stored in an ActionResult.
|
105
105
|
|
106
106
|
|
107
107
|
#### Blacksheep::Decorators::ResultMatcher
|
108
108
|
|
109
|
-
This decorator can be used when implementing your own actions by subclassing `Blacksheep::Action` and using the `#call` style for processing. Adding the
|
109
|
+
This decorator can be used when implementing your own actions by subclassing `Blacksheep::Action` and using the `#call` style for processing. Adding the `ResultMatcher` decorator enables to write a matcher block such as…
|
110
110
|
|
111
111
|
```ruby
|
112
112
|
MyAction.new.call(params) do |m|
|
@@ -122,7 +122,7 @@ MyAction.new.call(params) do |m|
|
|
122
122
|
end
|
123
123
|
```
|
124
124
|
|
125
|
-
The action has to return a Blacksheep::ActionResult which is
|
125
|
+
The action has to return a Blacksheep::ActionResult which is checked for status `:ok` for success case and any other status in failure case.
|
126
126
|
|
127
127
|
|
128
128
|
## Development
|
@@ -134,7 +134,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
134
134
|
```
|
135
135
|
gem build blacksheep
|
136
136
|
gem push blacksheep-0.x.y.gem
|
137
|
-
|
137
|
+
``
|
138
138
|
|
139
139
|
## Contributing
|
140
140
|
|
data/blacksheep.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
19
|
if spec.respond_to?(:metadata)
|
20
20
|
spec.metadata["homepage_uri"] = spec.homepage
|
21
|
-
|
21
|
+
spec.metadata["source_code_uri"] = "https://github.com/verticonaut/blacksheep"
|
22
22
|
# spec.metadata["changelog_uri"] = "Put your gem's CHANGELOG.md URL here."
|
23
23
|
else
|
24
24
|
raise "RubyGems 2.0 or newer is required to protect against " \
|
data/lib/blacksheep/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blacksheep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Schweizer
|
@@ -99,6 +99,7 @@ licenses:
|
|
99
99
|
- MIT
|
100
100
|
metadata:
|
101
101
|
homepage_uri: http://verticonaut.me
|
102
|
+
source_code_uri: https://github.com/verticonaut/blacksheep
|
102
103
|
post_install_message:
|
103
104
|
rdoc_options: []
|
104
105
|
require_paths:
|