bottled_services 0.1.3 → 1.0.0.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.idea/.rakeTasks +7 -0
- data/.idea/bottled_services.iml +87 -0
- data/.idea/misc.xml +4 -0
- data/.idea/modules.xml +8 -0
- data/.idea/vcs.xml +6 -0
- data/README.md +8 -0
- data/bottled_services.gemspec +12 -12
- data/lib/bottled_services/bottled_service.rb +175 -21
- data/lib/bottled_services/bottled_service_error.rb +5 -0
- data/lib/bottled_services/bottled_service_response.rb +60 -0
- data/lib/bottled_services/version.rb +1 -1
- data/lib/bottled_services.rb +2 -0
- metadata +16 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de0de00c206aa6d9a770b4a0aab6ed06b2d681cd
|
4
|
+
data.tar.gz: 382045664c8297a6a5689c518bbdff5a1f48f7bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eaf180bbdf501820ae69559e534cc3af4068fde4d7f657dd0e82de9e41359278d5c28a1ac9a35d3541465941d65320bf1a8df633dfde93842073829d63856e95
|
7
|
+
data.tar.gz: cedbbbbc0ce5b3b746553bd31004a08ceccac8e1bf2c08796765046ac8aef4531df1c68a4d18ea6877ced989f22c4523c356588bb53c49763104c7d1325f35fb
|
data/.idea/.rakeTasks
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<Settings><!--This file was automatically generated by Ruby plugin.
|
3
|
+
You are allowed to:
|
4
|
+
1. Remove rake task
|
5
|
+
2. Add existing rake tasks
|
6
|
+
To add existing rake tasks automatically delete this file and reload the project.
|
7
|
+
--><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Build bottled_services-0.1.3.gem into the pkg directory" fullCmd="build" taksId="build" /><RakeTask description="Remove any temporary products" fullCmd="clean" taksId="clean" /><RakeTask description="Remove any generated files" fullCmd="clobber" taksId="clobber" /><RakeTask description="Build and install bottled_services-0.1.3.gem into system gems" fullCmd="install" taksId="install" /><RakeGroup description="" fullCmd="" taksId="install"><RakeTask description="Build and install bottled_services-0.1.3.gem into system gems without network access" fullCmd="install:local" taksId="local" /></RakeGroup><RakeTask description="Create tag v0.1.3 and build and push bottled_services-0.1.3.gem to Rubygems" fullCmd="release[remote]" taksId="release[remote]" /><RakeTask description="Run RSpec code examples" fullCmd="spec" taksId="spec" /><RakeTask description="" fullCmd="default" taksId="default" /><RakeTask description="" fullCmd="release" taksId="release" /><RakeGroup description="" fullCmd="" taksId="release"><RakeTask description="" fullCmd="release:guard_clean" taksId="guard_clean" /><RakeTask description="" fullCmd="release:rubygem_push" taksId="rubygem_push" /><RakeTask description="" fullCmd="release:source_control_push" taksId="source_control_push" /></RakeGroup></RakeGroup></Settings>
|
@@ -0,0 +1,87 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="RUBY_MODULE" version="4">
|
3
|
+
<component name="ModuleRunConfigurationManager">
|
4
|
+
<shared />
|
5
|
+
<local>
|
6
|
+
<configuration default="false" name="BottledServiceResponse: bottled_services" type="RSpecRunConfigurationType" factoryName="RSpec" temporary="true">
|
7
|
+
<predefined_log_file id="RUBY_RSPEC" enabled="true" />
|
8
|
+
<module name="bottled_services" />
|
9
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
|
10
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="WORK DIR" VALUE="$MODULE_DIR$" />
|
11
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SHOULD_USE_SDK" VALUE="false" />
|
12
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ALTERN_SDK_NAME" VALUE="" />
|
13
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="myPassParentEnvs" VALUE="true" />
|
14
|
+
<envs>
|
15
|
+
<env name="JRUBY_OPTS" value="-X+O" />
|
16
|
+
</envs>
|
17
|
+
<EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="true" />
|
18
|
+
<EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
|
19
|
+
<EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov">
|
20
|
+
<COVERAGE_PATTERN ENABLED="true">
|
21
|
+
<PATTERN REGEXPS="/.rvm/" INCLUDED="false" />
|
22
|
+
</COVERAGE_PATTERN>
|
23
|
+
</EXTENSION>
|
24
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TESTS_FOLDER_PATH" VALUE="" />
|
25
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="$MODULE_DIR$/spec/bottled_services_spec.rb" />
|
26
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_RUNNER_PATH" VALUE="" />
|
27
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="**/*_spec.rb" />
|
28
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="BottledServiceResponse" />
|
29
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_TEST_TYPE" VALUE="TEST_SCRIPT" />
|
30
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_ARGS" VALUE="" />
|
31
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUNNER_VERSION" VALUE="" />
|
32
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="USE_CUSTOM_SPEC_RUNNER" VALUE="false" />
|
33
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="DRB" VALUE="false" />
|
34
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ZEUS" VALUE="false" />
|
35
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPRING" VALUE="false" />
|
36
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="FULL_BACKTRACE" VALUE="false" />
|
37
|
+
<method />
|
38
|
+
</configuration>
|
39
|
+
<configuration default="false" name="Run spec 'bottled_services_spec': bottled_services" type="RSpecRunConfigurationType" factoryName="RSpec" temporary="true">
|
40
|
+
<predefined_log_file id="RUBY_RSPEC" enabled="true" />
|
41
|
+
<module name="bottled_services" />
|
42
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
|
43
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="WORK DIR" VALUE="$MODULE_DIR$" />
|
44
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SHOULD_USE_SDK" VALUE="false" />
|
45
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ALTERN_SDK_NAME" VALUE="" />
|
46
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="myPassParentEnvs" VALUE="true" />
|
47
|
+
<envs>
|
48
|
+
<env name="JRUBY_OPTS" value="-X+O" />
|
49
|
+
</envs>
|
50
|
+
<EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="true" />
|
51
|
+
<EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
|
52
|
+
<EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov">
|
53
|
+
<COVERAGE_PATTERN ENABLED="true">
|
54
|
+
<PATTERN REGEXPS="/.rvm/" INCLUDED="false" />
|
55
|
+
</COVERAGE_PATTERN>
|
56
|
+
</EXTENSION>
|
57
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TESTS_FOLDER_PATH" VALUE="" />
|
58
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="$MODULE_DIR$/spec/bottled_services_spec.rb" />
|
59
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_RUNNER_PATH" VALUE="" />
|
60
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="**/*_spec.rb" />
|
61
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="" />
|
62
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_TEST_TYPE" VALUE="TEST_SCRIPT" />
|
63
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_ARGS" VALUE="" />
|
64
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUNNER_VERSION" VALUE="" />
|
65
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="USE_CUSTOM_SPEC_RUNNER" VALUE="false" />
|
66
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="DRB" VALUE="false" />
|
67
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ZEUS" VALUE="false" />
|
68
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPRING" VALUE="false" />
|
69
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="FULL_BACKTRACE" VALUE="false" />
|
70
|
+
<method />
|
71
|
+
</configuration>
|
72
|
+
</local>
|
73
|
+
</component>
|
74
|
+
<component name="NewModuleRootManager">
|
75
|
+
<content url="file://$MODULE_DIR$" />
|
76
|
+
<orderEntry type="jdk" jdkName="RVM: ruby-2.3.1 [rails5.0]" jdkType="RUBY_SDK" />
|
77
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
78
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler (v1.13.6, RVM: ruby-2.3.1 [rails5.0]) [gem]" level="application" />
|
79
|
+
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.2.5, RVM: ruby-2.3.1 [rails5.0]) [gem]" level="application" />
|
80
|
+
<orderEntry type="library" scope="PROVIDED" name="rake (v10.5.0, RVM: ruby-2.3.1 [rails5.0]) [gem]" level="application" />
|
81
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec (v3.5.0, RVM: ruby-2.3.1 [rails5.0]) [gem]" level="application" />
|
82
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.5.4, RVM: ruby-2.3.1 [rails5.0]) [gem]" level="application" />
|
83
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.5.0, RVM: ruby-2.3.1 [rails5.0]) [gem]" level="application" />
|
84
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.5.0, RVM: ruby-2.3.1 [rails5.0]) [gem]" level="application" />
|
85
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.5.0, RVM: ruby-2.3.1 [rails5.0]) [gem]" level="application" />
|
86
|
+
</component>
|
87
|
+
</module>
|
data/.idea/misc.xml
ADDED
data/.idea/modules.xml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project version="4">
|
3
|
+
<component name="ProjectModuleManager">
|
4
|
+
<modules>
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/bottled_services.iml" filepath="$PROJECT_DIR$/.idea/bottled_services.iml" />
|
6
|
+
</modules>
|
7
|
+
</component>
|
8
|
+
</project>
|
data/.idea/vcs.xml
ADDED
data/README.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# BottledServices
|
2
2
|
|
3
|
+
## The best thing to happen since bottled water
|
4
|
+
|
5
|
+
Ok, thats a drastic exaggeration, but now I have your attention lets get down to it.
|
6
|
+
bottled_services are here to make your life easier, its that simple. Using services keeps our code cleaner, DRYer, and reusable. With this gem creating and using services is now as easy and pain-free as can be thanks to the bottled_services generator and the BottledService Class from which all bottled services are children of, all you need to worry about is adding your business logic, let bottled_services handle the rest.
|
7
|
+
|
8
|
+
## Notice:
|
9
|
+
This Readme explains the use of BottledServices up to version 0.1.3, currently 1.0.0.alpha is the latest version and contains breaking changes, the Readme will be updated along with the release of 1.0.0
|
10
|
+
|
3
11
|
## Installation
|
4
12
|
|
5
13
|
Add this line to your application's Gemfile:
|
data/bottled_services.gemspec
CHANGED
@@ -4,24 +4,24 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'bottled_services/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'bottled_services'
|
8
8
|
spec.version = BottledServices::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['John_Hayes-Reed']
|
10
|
+
spec.email = ['john.hayes.reed@gmail.com']
|
11
11
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
12
|
+
spec.summary = 'A gourmet Service Object design pattern gem.'
|
13
|
+
spec.description = 'This gem provides a module to be the base for service objects that follow the single responsibility pattern and come with a variety of features that make using Service Objects to improve source code and seperate business logic into easy to handle components easier than ever.'
|
14
|
+
spec.homepage = 'https://github.com/John-Hayes-Reed/bottled_services'
|
15
|
+
spec.license = 'MIT'
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
18
|
f.match(%r{^(test|spec|features)/})
|
19
19
|
end
|
20
|
-
spec.bindir =
|
20
|
+
spec.bindir = 'exe'
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
-
spec.require_paths = [
|
22
|
+
spec.require_paths = ['lib']
|
23
23
|
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
26
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
27
27
|
end
|
@@ -1,34 +1,188 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
# A module that when included will provide features to create Service Objects.
|
2
|
+
#
|
3
|
+
# @note Bottled Services follow the single responsibility pattern and allow for
|
4
|
+
# only a single public instance method: #call. This is where all business
|
5
|
+
# logic should be handled. The definition of any other public instance methods
|
6
|
+
# will result in an error raise.
|
7
|
+
#
|
8
|
+
# @note Bottled Services provide a class ::att method to be used in the Service
|
9
|
+
# Object, this method should be used to define what attributes a Service
|
10
|
+
# Object may receive.
|
11
|
+
# @see ::att for more information.
|
12
|
+
#
|
13
|
+
# @note As of version 1.0.0 all Bottled Services will return a ServiceResponse
|
14
|
+
# object. This is to create a consistency in what is expected from service
|
15
|
+
# objects and create a convention for all Service Objects to abide why. Before
|
16
|
+
# 1.0.0 the returned response could be anything from an object to a boolean,
|
17
|
+
# but this inconsistency lead to purposefully having to look inside the class
|
18
|
+
# to know what would come back, using a ServiceResponse removes this ambiguity
|
19
|
+
# and makes the Service Objects easier to use through predictable behaviour.
|
20
|
+
#
|
21
|
+
# @note A Bottled Service should always return using either the #success or
|
22
|
+
# #failure methods, which will build an appropriate BottledServiceResponse
|
23
|
+
# object.
|
24
|
+
#
|
25
|
+
# @example A Basic Service Object.
|
26
|
+
# class PersistUser
|
27
|
+
# include BottledService
|
28
|
+
#
|
29
|
+
# att :user, type: :user, required: true
|
30
|
+
# att :params
|
31
|
+
#
|
32
|
+
# def call
|
33
|
+
# user.attributes = params if params.present?
|
34
|
+
# fail user: user unless user.save
|
35
|
+
|
36
|
+
# # notify BottledObservers of successful save.
|
37
|
+
# user.modified
|
38
|
+
# user.publish
|
39
|
+
#
|
40
|
+
# success user: user
|
41
|
+
# end
|
42
|
+
# end
|
43
|
+
module BottledService
|
44
|
+
# Sets up a Bottled Service class on inclusion.
|
45
|
+
#
|
46
|
+
# @param base [*]
|
47
|
+
#
|
48
|
+
# @raise [BottledServiceError::IllegalMethodDefined] if any public
|
49
|
+
# instance method other than #call is defined.
|
50
|
+
# @return [void]
|
51
|
+
def self.included(base)
|
52
|
+
base.extend(ClassMethods)
|
53
|
+
|
54
|
+
class << base
|
55
|
+
attr_accessor :required_arguments
|
56
|
+
# @!method required_arguments
|
57
|
+
# Gets a list of required arguments for a given Service Object.
|
58
|
+
define_method :required_arguments do
|
59
|
+
@required_arguments ||= []
|
7
60
|
end
|
8
|
-
|
9
|
-
|
10
|
-
|
61
|
+
end
|
62
|
+
attr_accessor :required_arguments
|
63
|
+
|
64
|
+
raise BottledServiceError::IllegalMethodDefined if
|
65
|
+
base.instance_methods(false).any? { |method| method != :call }
|
66
|
+
end
|
67
|
+
|
68
|
+
# The class methods made available to all Bottled Services.
|
69
|
+
module ClassMethods
|
70
|
+
# Defines an attributes that is added to the Bottled Service attributes
|
71
|
+
# white list, allowing it to be passed when a Bottled Service is called.
|
72
|
+
#
|
73
|
+
# @note passing parameters to a Bottled Service that have not been defined
|
74
|
+
# using this method will result in an error being raised.
|
75
|
+
#
|
76
|
+
# @param attribute_key [Symbol] Key for a given attribute.
|
77
|
+
# @param options [Hash] Optional requirements for a given attribute.
|
78
|
+
# @option options [*] :type Strict type for the attribute.
|
79
|
+
# @option options [True, False] :required Boolean flag representing
|
80
|
+
# requirement.
|
81
|
+
#
|
82
|
+
# @return [void]
|
83
|
+
def att(attribute_key, **options)
|
84
|
+
send :attr_accessor, attribute_key
|
85
|
+
send :private, attribute_key
|
86
|
+
send :private, :"#{attribute_key}="
|
87
|
+
|
88
|
+
required_arguments if @required_arguments.nil?
|
89
|
+
@required_arguments << attribute_key if options[:required]
|
90
|
+
|
91
|
+
return if options[:type].nil?
|
92
|
+
define_method "#{attribute_key}=" do |value|
|
93
|
+
if value.is_a?(options[:type])
|
94
|
+
instance_variable_set "@#{attribute_key}", value
|
95
|
+
else
|
96
|
+
raise BottledServiceError::IllegalTypeError,
|
97
|
+
"#{attribute_key} should be a #{options[:type]}"
|
98
|
+
end
|
11
99
|
end
|
100
|
+
send :private, :"#{attribute_key}="
|
12
101
|
end
|
13
|
-
|
14
|
-
|
102
|
+
|
103
|
+
# Initializes a new Service Object and executes its business logic.
|
104
|
+
#
|
105
|
+
# @param attribute_list [Hash] Attributes to pass to the Service Object.
|
106
|
+
#
|
107
|
+
# @return [ServiceResponse] @see #sucess, #fail
|
108
|
+
def call(**attribute_list)
|
109
|
+
if block_given?
|
110
|
+
new(**attribute_list).call(&Proc.new)
|
111
|
+
else
|
112
|
+
new(**attribute_list).call
|
113
|
+
end
|
15
114
|
end
|
16
115
|
end
|
17
116
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
117
|
+
private
|
118
|
+
|
119
|
+
# Instantiates a new Service Object
|
120
|
+
#
|
121
|
+
# @param attribute_list [Hash]
|
122
|
+
#
|
123
|
+
# @raise [BottledServiceError::RequiredArgumentNotFound]
|
124
|
+
# @see #verify_required_arguments
|
125
|
+
# @return [*] A new Service Object instance.
|
126
|
+
def initialize(**attribute_list)
|
127
|
+
@required_arguments = self.class.required_arguments
|
128
|
+
verify_required_arguments(*attribute_list.keys)
|
129
|
+
|
130
|
+
attribute_list.each do |key, value|
|
131
|
+
send(:"#{key}=", value)
|
23
132
|
end
|
24
133
|
end
|
25
134
|
|
26
|
-
|
27
|
-
|
28
|
-
|
135
|
+
# Verifies that all required arguments have been passed to the Service Object.
|
136
|
+
#
|
137
|
+
# @example With missing arguments.
|
138
|
+
# @required_arguments #=> [:user, :params]
|
139
|
+
# verify_required_arguments :user
|
140
|
+
# #=> BottledServiceError::RequiredArgumentNotFound
|
141
|
+
#
|
142
|
+
# @example With all required keys.
|
143
|
+
# @required_arguments #=> [:user, :params]
|
144
|
+
# verify_required_arguments :user, :params
|
145
|
+
# #=> nil
|
146
|
+
#
|
147
|
+
# @example With no required arguments defined.
|
148
|
+
# @required_arguments #=> []
|
149
|
+
# verify_required_arguments :user, :params
|
150
|
+
# #=> nil
|
151
|
+
#
|
152
|
+
# @param keys [Array<Symbol>] The keys of arguments passed to Service Object.
|
153
|
+
#
|
154
|
+
# @raise [BottledServiceError::RequiredArgumentNotFound]
|
155
|
+
# @return [void]
|
156
|
+
def verify_required_arguments(*keys)
|
157
|
+
return if @required_arguments.empty?
|
158
|
+
|
159
|
+
required_missing = false
|
160
|
+
required_missing = true if keys.empty? && !@required_arguments.empty?
|
161
|
+
|
162
|
+
@required_arguments.each do |arg|
|
163
|
+
required_missing = true unless keys.include? arg
|
29
164
|
end
|
165
|
+
|
166
|
+
return unless required_missing
|
167
|
+
raise BottledServiceError::RequiredArgumentNotFound
|
168
|
+
end
|
169
|
+
|
170
|
+
# Creates a response that represents a successful execution of the Service
|
171
|
+
# Object.
|
172
|
+
#
|
173
|
+
# @param args [Hash]
|
174
|
+
#
|
175
|
+
# @return [BottledServiceResponse]
|
176
|
+
def success(**args)
|
177
|
+
BottledServiceResponse.new true, args
|
30
178
|
end
|
31
179
|
|
32
|
-
|
33
|
-
|
180
|
+
# Creates a response that represents a failed execution of the Service Object.
|
181
|
+
#
|
182
|
+
# @param args [Hash]
|
183
|
+
#
|
184
|
+
# @return [BottledServiceResponse]
|
185
|
+
def failure(**args)
|
186
|
+
BottledServiceResponse.new false, args
|
187
|
+
end
|
34
188
|
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# A class that represents the outcome response of a BottledService service
|
2
|
+
# object.
|
3
|
+
class BottledServiceResponse
|
4
|
+
attr_reader :response_success
|
5
|
+
|
6
|
+
# Instantiates a new response object.
|
7
|
+
#
|
8
|
+
# @param success [true, false] true if the response represents a successful
|
9
|
+
# execution, false if a failed execution.
|
10
|
+
# @param options [Hash] All attributes of the response object.
|
11
|
+
#
|
12
|
+
# @return [void]
|
13
|
+
def initialize(success, **options)
|
14
|
+
@response_success = success
|
15
|
+
@attribute_keys = options.keys
|
16
|
+
options.each do |option_key, option_val|
|
17
|
+
singleton_class.send :attr_reader, option_key
|
18
|
+
instance_variable_set :"@#{option_key}", option_val
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Shows if the response represents a successful execution.
|
23
|
+
#
|
24
|
+
# @return [true, false]
|
25
|
+
def succeeded?
|
26
|
+
@response_success
|
27
|
+
end
|
28
|
+
|
29
|
+
# Shows if the response represents a failed execution.
|
30
|
+
#
|
31
|
+
# @return [true, false]
|
32
|
+
def failed?
|
33
|
+
!succeeded?
|
34
|
+
end
|
35
|
+
|
36
|
+
# Outputs all attributes that the Response object holds.
|
37
|
+
#
|
38
|
+
# @return [Hash]
|
39
|
+
def attributes
|
40
|
+
{}.tap do |attributes_hash|
|
41
|
+
@attribute_keys.each do |key|
|
42
|
+
attributes_hash[key] = send(key)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Outputs the keys for all available attributes.
|
48
|
+
#
|
49
|
+
# @return [Array]
|
50
|
+
def keys
|
51
|
+
@attribute_keys
|
52
|
+
end
|
53
|
+
|
54
|
+
# Outputs all available attribute values.
|
55
|
+
#
|
56
|
+
# @return [Array]
|
57
|
+
def values
|
58
|
+
attributes.values
|
59
|
+
end
|
60
|
+
end
|
data/lib/bottled_services.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bottled_services
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0.alpha
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John_Hayes-Reed
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,8 +52,10 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
-
description: This gem provides
|
56
|
-
|
55
|
+
description: This gem provides a module to be the base for service objects that follow
|
56
|
+
the single responsibility pattern and come with a variety of features that make
|
57
|
+
using Service Objects to improve source code and seperate business logic into easy
|
58
|
+
to handle components easier than ever.
|
57
59
|
email:
|
58
60
|
- john.hayes.reed@gmail.com
|
59
61
|
executables: []
|
@@ -61,6 +63,11 @@ extensions: []
|
|
61
63
|
extra_rdoc_files: []
|
62
64
|
files:
|
63
65
|
- ".gitignore"
|
66
|
+
- ".idea/.rakeTasks"
|
67
|
+
- ".idea/bottled_services.iml"
|
68
|
+
- ".idea/misc.xml"
|
69
|
+
- ".idea/modules.xml"
|
70
|
+
- ".idea/vcs.xml"
|
64
71
|
- ".rspec"
|
65
72
|
- ".travis.yml"
|
66
73
|
- CODE_OF_CONDUCT.md
|
@@ -74,6 +81,8 @@ files:
|
|
74
81
|
- bottled_services.gemspec
|
75
82
|
- lib/bottled_services.rb
|
76
83
|
- lib/bottled_services/bottled_service.rb
|
84
|
+
- lib/bottled_services/bottled_service_error.rb
|
85
|
+
- lib/bottled_services/bottled_service_response.rb
|
77
86
|
- lib/bottled_services/version.rb
|
78
87
|
- lib/generators/bottled_service/bottled_service_generator.rb
|
79
88
|
homepage: https://github.com/John-Hayes-Reed/bottled_services
|
@@ -91,13 +100,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
91
100
|
version: '0'
|
92
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
102
|
requirements:
|
94
|
-
- - "
|
103
|
+
- - ">"
|
95
104
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
105
|
+
version: 1.3.1
|
97
106
|
requirements: []
|
98
107
|
rubyforge_project:
|
99
108
|
rubygems_version: 2.5.1
|
100
109
|
signing_key:
|
101
110
|
specification_version: 4
|
102
|
-
summary: A gourmet
|
111
|
+
summary: A gourmet Service Object design pattern gem.
|
103
112
|
test_files: []
|