magical-service 0.0.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 +7 -0
- data/MIT-LICENSE +22 -0
- data/lib/magical/service.rb +3 -0
- data/lib/magical/service/action_service.rb +43 -0
- data/lib/magical/service/action_service/base.rb +33 -0
- data/lib/magical/service/core/gears.rb +76 -0
- data/lib/magical/service/core/gears/control_panel.rb +22 -0
- data/lib/magical/service/core/gears/no_assignment_error.rb +12 -0
- data/lib/magical/service/core/machinery.rb +12 -0
- data/lib/magical/service/version.rb +7 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3a040a05f30209e49ae39fbc07f975b38e8bb3338b8a6bdbfd689fc26ed3a79d
|
4
|
+
data.tar.gz: ec7f416f17be7b1ac1ebf10a67f845c7237833e94783a6148125d9a204c2b571
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bcac906045a938dfbf05247eb15e65f1c883c52063ac7b5f7e80d48469084a98f5cfc3a0677a3a0fb45a5dbfaa9c0149eff315b12ef1c818e3d7a8ad93d3f400
|
7
|
+
data.tar.gz: 79791bca59bb5bbd285e588d316b6bab96d983568b491f23af6087f826e21c8e9c53af3129bd5e6a5084f110834a5cc1b4033814af88a2f496e04c3465d7927b
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright 2018 Magica Azula
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'action_service/base'
|
4
|
+
|
5
|
+
# action service module
|
6
|
+
module ActionService
|
7
|
+
# # a service example:
|
8
|
+
#
|
9
|
+
# class BarService < ActionService::Base
|
10
|
+
# before_confection do
|
11
|
+
# define_params :default_param # optional
|
12
|
+
# define_options :default_option # optional
|
13
|
+
# define_stages %i[one two three] # optional
|
14
|
+
# define_delivery :four
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# stage :one do
|
18
|
+
# # body omitted
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# stage :two do
|
22
|
+
# stage_helper(foo, bar)
|
23
|
+
# # body omitted
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# stage :three do
|
27
|
+
# # body omitted
|
28
|
+
# stage_helper2(baz)
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# stage :four do
|
32
|
+
# # body omitted
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
# # one-line support action
|
36
|
+
# mainstay(:stage_helper) { |foo, bar| # body omitted }
|
37
|
+
#
|
38
|
+
# # multi-line support action
|
39
|
+
# mainstay(:stage_helper2) do |baz|
|
40
|
+
# # body omitted
|
41
|
+
# end
|
42
|
+
# end
|
43
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'magical/service/core/gears'
|
4
|
+
require 'magical/service/core/machinery'
|
5
|
+
|
6
|
+
module ActionService
|
7
|
+
# Service base conveniences for your service objects.
|
8
|
+
#
|
9
|
+
# This class allows you to define services based on a
|
10
|
+
# suggested convention, with will execute through a single action.
|
11
|
+
# Then your service can define stages of forced void return and a
|
12
|
+
# delivery method, which will process data and return it
|
13
|
+
#
|
14
|
+
# class MyService < ActionService::Base
|
15
|
+
# before_confection do
|
16
|
+
# define_stages %i[one two] # optional
|
17
|
+
# define_delivery :three
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# stage :one do { # body omitted }
|
21
|
+
# stage :two do { # body omitted }
|
22
|
+
# stage :three do { # body omitted }
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# Then your service can do all the process by simply calling:
|
26
|
+
#
|
27
|
+
# MyService.provide(params: {}, options: {})
|
28
|
+
#
|
29
|
+
class Base
|
30
|
+
extend Core::Gears
|
31
|
+
extend Core::Machinery
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'gears/control_panel'
|
4
|
+
require_relative 'gears/no_assignment_error'
|
5
|
+
|
6
|
+
module Core
|
7
|
+
# service gears
|
8
|
+
module Gears
|
9
|
+
def provide(params: {}, options: {})
|
10
|
+
validates_confection do
|
11
|
+
@params = params unless default_attribute?(:params, params)
|
12
|
+
@options = options unless default_attribute?(:options, options)
|
13
|
+
end
|
14
|
+
|
15
|
+
chain do
|
16
|
+
clear_virtual_instance_variables
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def before_confection(&block)
|
21
|
+
config.instance_eval(&block)
|
22
|
+
end
|
23
|
+
|
24
|
+
def chain
|
25
|
+
config.stages.each { |method| send(*method) } if stages?
|
26
|
+
|
27
|
+
result = send(*config.delivery)
|
28
|
+
yield
|
29
|
+
result
|
30
|
+
end
|
31
|
+
|
32
|
+
def clear_virtual_instance_variables
|
33
|
+
remove_instance_variable(:@params) if defined?(@params)
|
34
|
+
remove_instance_variable(:@options) if defined?(@options)
|
35
|
+
end
|
36
|
+
|
37
|
+
def config
|
38
|
+
@config ||= ControlPanel.new
|
39
|
+
end
|
40
|
+
|
41
|
+
def default_attribute?(attribute, value)
|
42
|
+
!config.send(attribute).nil? && value.is_a?(Hash) && value.empty?
|
43
|
+
end
|
44
|
+
|
45
|
+
def defined_stages?
|
46
|
+
config.stages.all? { |phase| respond_to?(phase) }
|
47
|
+
end
|
48
|
+
|
49
|
+
def delivery?
|
50
|
+
defined?(@config) && !config.delivery.nil? && respond_to?(config.delivery)
|
51
|
+
end
|
52
|
+
|
53
|
+
def not_defined_error(action)
|
54
|
+
NoAssignmentError.new(action, self)
|
55
|
+
end
|
56
|
+
|
57
|
+
def options
|
58
|
+
defined?(@options) ? @options : (@options = config.options)
|
59
|
+
end
|
60
|
+
|
61
|
+
def params
|
62
|
+
defined?(@params) ? @params : (@params = config.params)
|
63
|
+
end
|
64
|
+
|
65
|
+
def stages?
|
66
|
+
defined?(@config) && !config.stages.nil?
|
67
|
+
end
|
68
|
+
|
69
|
+
def validates_confection
|
70
|
+
raise not_defined_error('some :stages') if stages? && !defined_stages?
|
71
|
+
raise not_defined_error(':delivery') unless delivery?
|
72
|
+
|
73
|
+
yield
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Core
|
4
|
+
module Gears
|
5
|
+
# Gears Control Panel which handles the basic services configuration
|
6
|
+
class ControlPanel
|
7
|
+
ATTRIBUTES = %i[stages delivery params options].freeze
|
8
|
+
|
9
|
+
attr_accessor(*ATTRIBUTES)
|
10
|
+
|
11
|
+
ATTRIBUTES.each do |attr|
|
12
|
+
define_method attr do
|
13
|
+
instance_variable_get("@#{attr}")
|
14
|
+
end
|
15
|
+
|
16
|
+
define_method "define_#{attr}" do |value|
|
17
|
+
instance_variable_set("@#{attr}", value)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Core
|
4
|
+
module Gears
|
5
|
+
# error of action not assigned
|
6
|
+
class NoAssignmentError < StandardError
|
7
|
+
def initialize(action, service)
|
8
|
+
super("#{action} wasn't assign for the service: #{service}")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: magical-service
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Heirian
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-12-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.8'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubocop
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.61.1
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.61.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: simplecov
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.16.1
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.16.1
|
55
|
+
description: Magical Service is an experiment that aims to assist the construction
|
56
|
+
of service objects through stages as a single action.
|
57
|
+
email: shinkcc@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- MIT-LICENSE
|
63
|
+
- lib/magical/service.rb
|
64
|
+
- lib/magical/service/action_service.rb
|
65
|
+
- lib/magical/service/action_service/base.rb
|
66
|
+
- lib/magical/service/core/gears.rb
|
67
|
+
- lib/magical/service/core/gears/control_panel.rb
|
68
|
+
- lib/magical/service/core/gears/no_assignment_error.rb
|
69
|
+
- lib/magical/service/core/machinery.rb
|
70
|
+
- lib/magical/service/version.rb
|
71
|
+
homepage: https://github.com/magica-azula/magical-service
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '2.5'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.7.8
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: Magical Service helps build a service object through a single action
|
95
|
+
test_files: []
|