fss 0.0.1
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 +7 -0
- data/.editorconfig +8 -0
- data/LICENSE +21 -0
- data/README.md +35 -0
- data/fss.gemspec +17 -0
- data/lib/fss.rb +53 -0
- metadata +64 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cb5f9b51ba6086f64dcab4676f9b8e02047007e8510469f6876a8d5e6f3cee5f
|
4
|
+
data.tar.gz: 4541dcb7006a41f433792453074b9d5ea6b35f8a5ed6a87b226c8bc65b58645c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dbbb957d8c847e8a6a118700d81f15f41fe5f4031a73f39a1cefb3275fc3126b64514745ce7ec294443ce67f826ed8637b8ab632fccbaedec8f115eb2f70923b
|
7
|
+
data.tar.gz: f484cd63f0979c8926cd9d2f12b36a41a7e678e7575a22876db40270f00305870f05e20c5136de21bc12211de3ade88cf4b7101c9fa696f0a329b53d6f078fda
|
data/.editorconfig
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2009 thoughtbot, inc.
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Form-Service-Serializer
|
2
|
+
|
3
|
+
Handling forms, services and serialization the nice way.
|
4
|
+
|
5
|
+
## Getting started
|
6
|
+
|
7
|
+
FSS is a Rails controller's concern providing DSL for handling API-only commands in a simple way.
|
8
|
+
Tested against Rails `>= 5.2.1` and Ruby `>= 2.5.1`.
|
9
|
+
Forms need to be `reform` ones and serializers need to be `fast_jsonapi`
|
10
|
+
|
11
|
+
You can add it to your Gemfile with:
|
12
|
+
|
13
|
+
```sh
|
14
|
+
gem 'fss'
|
15
|
+
```
|
16
|
+
|
17
|
+
Then run bundle command to install it.
|
18
|
+
|
19
|
+
After that you're able to add to your controller:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
include Fss::Commandable
|
23
|
+
```
|
24
|
+
|
25
|
+
Now, in your controller method bodies you're able to do following:
|
26
|
+
|
27
|
+
```rb
|
28
|
+
command_result = command restaurant_params do
|
29
|
+
form RestaurantForm
|
30
|
+
service Services::Restaurant::CreateRestaurant, current_user
|
31
|
+
serializer RestaurantSerializer
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
From the given example `restaurant_params` are being passed to form and service calls.
|
data/fss.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.add_dependency 'dry-monads', '~> 1.1'
|
3
|
+
s.authors = [
|
4
|
+
'Tomasz Marciniak'
|
5
|
+
]
|
6
|
+
s.description = 'Handling forms, services and serialization the nice way.'
|
7
|
+
s.email = 'tmarciniakm@gmail.com'
|
8
|
+
s.extra_rdoc_files = %w[LICENSE README.md]
|
9
|
+
s.files = `git ls-files`.split("\n")
|
10
|
+
s.license = 'MIT'
|
11
|
+
s.name = 'fss'
|
12
|
+
s.require_paths = ['lib']
|
13
|
+
s.required_ruby_version = Gem::Requirement.new('>= 2.5.1')
|
14
|
+
s.summary = 'Handling forms, services and serialization the nice way.'
|
15
|
+
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
16
|
+
s.version = '0.0.1'
|
17
|
+
end
|
data/lib/fss.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
module Fss
|
2
|
+
VERSION = '0.0.1'.freeze
|
3
|
+
# Controller concern for handling commands
|
4
|
+
module Commandable
|
5
|
+
include ActiveSupport::Concern
|
6
|
+
include Dry::Monads::Result::Mixin
|
7
|
+
|
8
|
+
def command(command_params)
|
9
|
+
@command_params = command_params
|
10
|
+
yield
|
11
|
+
end
|
12
|
+
|
13
|
+
def form(form_class)
|
14
|
+
execute_form form_class
|
15
|
+
end
|
16
|
+
|
17
|
+
def service(service_class, *params)
|
18
|
+
execute_service service_class, command_params, *params if validation_result.success?
|
19
|
+
end
|
20
|
+
|
21
|
+
def serializer(serializer_class)
|
22
|
+
execute_serialization serializer_class, service_result.value! if service_result.success?
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def command_params
|
28
|
+
@command_params
|
29
|
+
end
|
30
|
+
|
31
|
+
def execute_form(form_class)
|
32
|
+
result = form_class.validate(command_params) ? Success(command_params) : Failure(form_class.errors)
|
33
|
+
@validation_result = result
|
34
|
+
end
|
35
|
+
|
36
|
+
def validation_result
|
37
|
+
@validation_result
|
38
|
+
end
|
39
|
+
|
40
|
+
def execute_service(service_class, *params)
|
41
|
+
result = service_class.call(*params)
|
42
|
+
@service_result = result
|
43
|
+
end
|
44
|
+
|
45
|
+
def service_result
|
46
|
+
@service_result
|
47
|
+
end
|
48
|
+
|
49
|
+
def execute_serialization(serializer_class, params)
|
50
|
+
Success(serializer_class.new(params))
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fss
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tomasz Marciniak
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-11-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: dry-monads
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.1'
|
27
|
+
description: Handling forms, services and serialization the nice way.
|
28
|
+
email: tmarciniakm@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.md
|
34
|
+
files:
|
35
|
+
- ".editorconfig"
|
36
|
+
- LICENSE
|
37
|
+
- README.md
|
38
|
+
- fss.gemspec
|
39
|
+
- lib/fss.rb
|
40
|
+
homepage:
|
41
|
+
licenses:
|
42
|
+
- MIT
|
43
|
+
metadata: {}
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 2.5.1
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 2.7.7
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: Handling forms, services and serialization the nice way.
|
64
|
+
test_files: []
|