services_base 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1a6c9556231cf5b53f1e17362a3a3d35e4ca9792
4
- data.tar.gz: be28c11b0980042cc3df8fbd92ade87509825d7b
3
+ metadata.gz: d38d697b9e9bd7f2c9f293a7f19142299b3aaaf2
4
+ data.tar.gz: 3327ca26383ffa8af40a3ae39831824c548f03e0
5
5
  SHA512:
6
- metadata.gz: 58fa5fe8fda0a7d13a7ea0a3703324bc631d4d5f1249888b375298d8cf587eb1b9d0ceaef298901b2de44c11be382c59b293aa9326ecc539ef6c2f022f262e25
7
- data.tar.gz: e8ec7e84e59be28abd2672c4b74ffe688b555c52dd41e95e031e9f4c86ae0ac2418246d0c20146bb8aebd8c3a276dce807b60df528494f3932591b8363de16ca
6
+ metadata.gz: a128d2158525202c356a78cdfd5ba3da0a7d2c91eadbf3001cd87131a439ad7a23c8dcea47699140637f2d595c454a3cf3a9ca65180c108ab7dd9fa863617e7e
7
+ data.tar.gz: 3617ee100b4ad20aa0cfc5f38b1fefc8ccb0baf69b37e7206f2e257cabe13ae1d01b7577af39a1f98830b656099967c5c8670c44d1b0c0b581bf8426834e5557
data/.gitignore CHANGED
@@ -7,3 +7,5 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ *.gem
11
+
data/Guardfile CHANGED
@@ -11,32 +11,4 @@ guard :rspec, cmd: "bundle exec rspec" do
11
11
  # Ruby files
12
12
  ruby = dsl.ruby
13
13
  dsl.watch_spec_files_for(ruby.lib_files)
14
-
15
- # # Rails files
16
- # rails = dsl.rails(view_extensions: %w(erb haml slim))
17
- # dsl.watch_spec_files_for(rails.app_files)
18
- # dsl.watch_spec_files_for(rails.views)
19
-
20
- # watch(rails.controllers) do |m|
21
- # [
22
- # rspec.spec.call("routing/#{m[1]}_routing"),
23
- # rspec.spec.call("controllers/#{m[1]}_controller"),
24
- # rspec.spec.call("acceptance/#{m[1]}")
25
- # ]
26
- # end
27
-
28
- # # Rails config changes
29
- # watch(rails.spec_helper) { rspec.spec_dir }
30
- # watch(rails.routes) { "#{rspec.spec_dir}/routing" }
31
- # watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
32
-
33
- # # Capybara features specs
34
- # watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
35
- # watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
36
-
37
- # # Turnip features and steps
38
- # watch(%r{^spec/acceptance/(.+)\.feature$})
39
- # watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
40
- # Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
41
- # end
42
14
  end
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # ServicesBase
2
2
 
3
- ServicesBase is a very simple Base module for implementing Service Objects and Micro-Services in Ruby.
3
+ ServicesBase is a very simple skeleton for implementing Service Objects and Micro-Services in Ruby.
4
+
5
+ It implements a Base module for your service objects (`Services::Base`) and two Response classes (`Services::Responses::Success` and `Services::Responses::Error`).
4
6
 
5
7
  It was heavily inspired by Chris Holtz's excellent article [Organize your app with service objects](http://chrisholtz.com/blog/organize-your-app-with-service-objects/). You should read it.
6
8
 
@@ -21,15 +23,22 @@ Or install it yourself as:
21
23
  $ gem install services_base
22
24
 
23
25
  ## Usage
26
+ ```ruby
27
+ class Services::MyService
28
+ include Services::Base
24
29
 
25
- class Services::MyService
26
- include ServicesBase
30
+ def call(id)
31
+ # do something
32
+ result_object = { foo: 'bar' }
27
33
 
28
- def call(id)
29
- # do something
30
- end
31
- end
34
+ # and return success
35
+ return Services::Responses::Success.new(result_object)
32
36
 
37
+ # or if there's an error:
38
+ return Services::Responses::Error.new(result_object, error_message: 'Something went wrong', error_code: 123)
39
+ end
40
+ end
41
+ ```
33
42
 
34
43
  ## License
35
44
 
@@ -0,0 +1,22 @@
1
+ # Significantly inspired by http://chrisholtz.com/blog/organize-your-app-with-service-objects/
2
+ module Services
3
+ module Base
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ base.include InstanceMethods
7
+ end
8
+
9
+ module ClassMethods
10
+ def call(*args, &block)
11
+ @instance ||= self.new
12
+ @instance.call *args, &block
13
+ end
14
+ end
15
+
16
+ module InstanceMethods
17
+ def call(*args, &block)
18
+ raise NotImplementedError
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,20 @@
1
+ module Services
2
+ module Responses
3
+ class Base
4
+ attr_reader :result
5
+
6
+ def initialize(result = nil)
7
+ @result = result
8
+ end
9
+
10
+ def success?
11
+ raise NotImplementedError
12
+ end
13
+
14
+ def error?
15
+ !success?
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,15 @@
1
+ module Services
2
+ module Responses
3
+ class Error < Services::Responses::Base
4
+ attr_accessor :error_message, :error_code
5
+
6
+ def initialize(result, error_message: nil, error_code: nil)
7
+ @result, @error_message, @error_code = result, error_message, error_code
8
+ end
9
+
10
+ def success?
11
+ false
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ module Services
2
+ module Responses
3
+ class Success < Services::Responses::Base
4
+ def success?
5
+ true
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Services
2
+ VERSION = "0.2.0"
3
+ end
@@ -1,22 +1,5 @@
1
- require "services_base/version"
2
-
3
- # Significantly inspired by http://chrisholtz.com/blog/organize-your-app-with-service-objects/
4
- module ServicesBase
5
- def self.included(base)
6
- base.extend ClassMethods
7
- base.include InstanceMethods
8
- end
9
-
10
- module ClassMethods
11
- def call(*args, &block)
12
- @instance ||= self.new
13
- @instance.call *args, &block
14
- end
15
- end
16
-
17
- module InstanceMethods
18
- def call(*args, &block)
19
- raise NotImplementedError
20
- end
21
- end
22
- end
1
+ require "services/version"
2
+ require "services/base"
3
+ require "services/responses/base"
4
+ require "services/responses/error"
5
+ require "services/responses/success"
@@ -1,16 +1,16 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'services_base/version'
4
+ require 'services/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "services_base"
8
- spec.version = ServicesBase::VERSION
8
+ spec.version = Services::VERSION
9
9
  spec.authors = ["Carl Mercier"]
10
10
  spec.email = ["carl@varagesale.com"]
11
11
 
12
- spec.summary = %q{Simple Base module for implementing consistent Service Objects and Micro-Services in Ruby}
13
- spec.description = %q{Simple Base module for implementing consistent Service Objects and Micro-Services in Ruby}
12
+ spec.summary = %q{Simple skeleton for implementing consistent Service Objects and Micro-Services in Ruby}
13
+ spec.description = %q{Simple skeleton for implementing consistent Service Objects and Micro-Services in Ruby}
14
14
  spec.homepage = "https://github.com/varagesale/services_base"
15
15
  spec.license = "MIT"
16
16
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: services_base
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carl Mercier
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-01 00:00:00.000000000 Z
11
+ date: 2016-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,7 +80,7 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- description: Simple Base module for implementing consistent Service Objects and Micro-Services
83
+ description: Simple skeleton for implementing consistent Service Objects and Micro-Services
84
84
  in Ruby
85
85
  email:
86
86
  - carl@varagesale.com
@@ -98,8 +98,12 @@ files:
98
98
  - Rakefile
99
99
  - bin/console
100
100
  - bin/setup
101
+ - lib/services/base.rb
102
+ - lib/services/responses/base.rb
103
+ - lib/services/responses/error.rb
104
+ - lib/services/responses/success.rb
105
+ - lib/services/version.rb
101
106
  - lib/services_base.rb
102
- - lib/services_base/version.rb
103
107
  - services_base.gemspec
104
108
  homepage: https://github.com/varagesale/services_base
105
109
  licenses:
@@ -124,6 +128,6 @@ rubyforge_project:
124
128
  rubygems_version: 2.5.1
125
129
  signing_key:
126
130
  specification_version: 4
127
- summary: Simple Base module for implementing consistent Service Objects and Micro-Services
131
+ summary: Simple skeleton for implementing consistent Service Objects and Micro-Services
128
132
  in Ruby
129
133
  test_files: []
@@ -1,3 +0,0 @@
1
- module ServicesBase
2
- VERSION = "0.1.0"
3
- end