service_pattern 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4ef5026129535dada95ee484e4c6a61fcd5ed689
4
+ data.tar.gz: '095d82698ccadbdad6368273a07ee5cf53b306c7'
5
+ SHA512:
6
+ metadata.gz: d951dcb2f5c8de6e999f1b486dbafc153fbaea1422151d9376014bce8e2b20187af1dace781335254e3cdde3f9ef02ec57cbcb5b06cd9eedb6eb8f2b5b5c1527
7
+ data.tar.gz: 37873b53aa79092c4d7bfc47102aa53bcde76daa5d6946a61448490b6680e3b7ccf1315e486fc1239a3cdf16ba9f1de8532779e6113583dfabe67b615bf755c9
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017 kaspernj
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,16 @@
1
+ # ServicePattern
2
+
3
+ Easy callback service pattern for Ruby on Rails.
4
+
5
+ ## Usage
6
+ How to use my plugin.
7
+
8
+ ## Installation
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem "service_pattern"
13
+ ```
14
+
15
+ ## License
16
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ begin
2
+ require "bundler/setup"
3
+ rescue LoadError
4
+ puts "You must `gem install bundler` and `bundle install` to run rake tasks"
5
+ end
6
+
7
+ require "rdoc/task"
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = "rdoc"
11
+ rdoc.title = "ServicePattern"
12
+ rdoc.options << "--line-numbers"
13
+ rdoc.rdoc_files.include("README.md")
14
+ rdoc.rdoc_files.include("lib/**/*.rb")
15
+ end
16
+
17
+ require "bundler/gem_tasks"
18
+
19
+ require "best_practice_project"
20
+ BestPracticeProject.load_tasks
@@ -0,0 +1,19 @@
1
+ class ServicePattern::Service
2
+ def self.call(*args)
3
+ service = new(*args)
4
+
5
+ begin
6
+ return service.execute!
7
+ rescue => e
8
+ ServicePattern::ServiceResponse.new(errors: ["#{e.class.name}: #{e.message}"], success: false)
9
+ end
10
+ end
11
+
12
+ def self.execute!(*args)
13
+ new(*args).execute!
14
+ end
15
+
16
+ def execute!(*_args)
17
+ raise NoMethodError, "You should implement the `execute!` method on your service"
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ class ServicePattern::ServiceResponse
2
+ attr_reader :errors, :result
3
+
4
+ def initialize(args)
5
+ @errors = args[:errors] || []
6
+ @result = args[:result]
7
+
8
+ if args.key?(:success)
9
+ @success = args.fetch(:success)
10
+ elsif args.key?(:errors) && @errors.any?
11
+ @success = false
12
+ elsif @result
13
+ @success = true
14
+ else
15
+ raise "Couldn't figure out if it was a success"
16
+ end
17
+ end
18
+
19
+ def success?
20
+ @success
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module ServicePattern
2
+ VERSION = "0.0.1".freeze
3
+ end
@@ -0,0 +1,6 @@
1
+ module ServicePattern
2
+ path = "#{File.dirname(__FILE__)}/service_pattern"
3
+
4
+ autoload :Service, "#{path}/service"
5
+ autoload :ServiceResponse, "#{path}/service_response"
6
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :service_pattern do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: service_pattern
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - kaspernj
8
+ autorequire:
9
+ bindir: bin
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'
41
+ description: ServicePattern for Ruby on Rails.
42
+ email:
43
+ - kaspernj@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - MIT-LICENSE
49
+ - README.md
50
+ - Rakefile
51
+ - lib/service_pattern.rb
52
+ - lib/service_pattern/service.rb
53
+ - lib/service_pattern/service_response.rb
54
+ - lib/service_pattern/version.rb
55
+ - lib/tasks/service_pattern_tasks.rake
56
+ homepage: https://www.github.com/kaspernj/service_pattern
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.6.8
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: ServicePattern for Ruby on Rails.
80
+ test_files: []