service_pattern 0.0.1 → 0.0.2

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: 4ef5026129535dada95ee484e4c6a61fcd5ed689
4
- data.tar.gz: '095d82698ccadbdad6368273a07ee5cf53b306c7'
3
+ metadata.gz: d6787a4f53bfdd57a07123e7eced76fdce0857cd
4
+ data.tar.gz: 1dede4fdc6bfcd28b8fef48927f8d1362c0a0dfa
5
5
  SHA512:
6
- metadata.gz: d951dcb2f5c8de6e999f1b486dbafc153fbaea1422151d9376014bce8e2b20187af1dace781335254e3cdde3f9ef02ec57cbcb5b06cd9eedb6eb8f2b5b5c1527
7
- data.tar.gz: 37873b53aa79092c4d7bfc47102aa53bcde76daa5d6946a61448490b6680e3b7ccf1315e486fc1239a3cdf16ba9f1de8532779e6113583dfabe67b615bf755c9
6
+ metadata.gz: 1de0f2175621e1ab35333e41ce768bb0b44bc92468b0c5266faee84658bff910fa1fdceb766dcfe649b16a4711ced4c34b40569e9602c847d6706ac72f6b05f0
7
+ data.tar.gz: 5332d4b8173004adee2ba1e6061e793cf3c7ee39cee66b2cac2df390218260c63dddbd5204903e545b7622d7061e4dd799768e26dafc7630773389133a28cc0b
@@ -0,0 +1 @@
1
+ class ServicePattern::CantExecuteError < RuntimeError; end
@@ -1,4 +1,4 @@
1
- class ServicePattern::ServiceResponse
1
+ class ServicePattern::Response
2
2
  attr_reader :errors, :result
3
3
 
4
4
  def initialize(args)
@@ -3,14 +3,27 @@ class ServicePattern::Service
3
3
  service = new(*args)
4
4
 
5
5
  begin
6
- return service.execute!
6
+ can_execute_response = service.can_execute?
7
+
8
+ puts "can_execute_response: #{can_execute_response.success?} (#{can_execute_response.errors})"
9
+
10
+ return can_execute_response unless can_execute_response.success?
11
+ service.execute!
7
12
  rescue => e
8
- ServicePattern::ServiceResponse.new(errors: ["#{e.class.name}: #{e.message}"], success: false)
13
+ ServicePattern::Response.new(errors: ["#{e.class.name}: #{e.message}"], success: false)
9
14
  end
10
15
  end
11
16
 
12
17
  def self.execute!(*args)
13
- new(*args).execute!
18
+ service = new(*args)
19
+
20
+ can_execute_response = service.can_execute?
21
+ raise ServicePattern::CantExecuteError, can_execute_response.errors.join(". ") unless can_execute_response.success?
22
+ service.execute!
23
+ end
24
+
25
+ def can_execute?
26
+ ServicePattern::Response.new(success: true)
14
27
  end
15
28
 
16
29
  def execute!(*_args)
@@ -1,3 +1,3 @@
1
1
  module ServicePattern
2
- VERSION = "0.0.1".freeze
2
+ VERSION = "0.0.2".freeze
3
3
  end
@@ -1,6 +1,7 @@
1
1
  module ServicePattern
2
2
  path = "#{File.dirname(__FILE__)}/service_pattern"
3
3
 
4
+ autoload :CantExecuteError, "#{path}/cant_execute_error"
5
+ autoload :Response, "#{path}/response"
4
6
  autoload :Service, "#{path}/service"
5
- autoload :ServiceResponse, "#{path}/service_response"
6
7
  end
metadata CHANGED
@@ -1,43 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: service_pattern
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - kaspernj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-11 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rails
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: 4.0.0
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: 4.0.0
27
- - !ruby/object:Gem::Dependency
28
- name: sqlite3
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
11
+ date: 2017-05-19 00:00:00.000000000 Z
12
+ dependencies: []
41
13
  description: ServicePattern for Ruby on Rails.
42
14
  email:
43
15
  - kaspernj@gmail.com
@@ -49,8 +21,9 @@ files:
49
21
  - README.md
50
22
  - Rakefile
51
23
  - lib/service_pattern.rb
24
+ - lib/service_pattern/cant_execute_error.rb
25
+ - lib/service_pattern/response.rb
52
26
  - lib/service_pattern/service.rb
53
- - lib/service_pattern/service_response.rb
54
27
  - lib/service_pattern/version.rb
55
28
  - lib/tasks/service_pattern_tasks.rake
56
29
  homepage: https://www.github.com/kaspernj/service_pattern