service_it 0.1.5
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/.gitignore +12 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +21 -0
- data/README.md +67 -0
- data/Rakefile +6 -0
- data/bin/console +13 -0
- data/bin/setup +8 -0
- data/lib/service.rb +39 -0
- data/lib/service_it.rb +5 -0
- data/service_it.gemspec +26 -0
- data/spec/service_spec.rb +17 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ef6890fe00df3a2e46a39307a22e44f38d57584ffe489a7339fb75602a421021
|
4
|
+
data.tar.gz: 83481cd80581a33166fede658b70b956b58782a8bb0c9a7059bad7871273e98b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2dc7098bb099cde3e1bf609132416fcf8dad963f5f980c088357544975a5c92c1ca3180d552f0dfb1449b94dbf0130b39890dc17a3661b4645e6539b99662543
|
7
|
+
data.tar.gz: 89e5494f4606459e0ad1e4f75dca31bf25907a267262f31babc95cab80e0a9b5412bedf321a69f033188e805e0f89e7c495e83c4726d44425143c2313488bbc6
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Iago Silva
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# ServiceIt
|
2
|
+
|
3
|
+
[](https://badge.fury.io/rb/service_it)
|
4
|
+
|
5
|
+
<div align="center">
|
6
|
+
<img src="https://pbs.twimg.com/profile_images/1123677732/logo_avatar_large.png" height="250" width="250">
|
7
|
+
<p>Its main objective is to provide you a way to delegate responsibilities in your project</p>
|
8
|
+
</div>
|
9
|
+
|
10
|
+
<br/>
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
gem 'service_it', '0.1.5'
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install service_it
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
Inherit your class of `Service` and implement `perform` method
|
29
|
+
```ruby
|
30
|
+
class Foo < Service
|
31
|
+
def perform
|
32
|
+
# here you can use params that became instance variables
|
33
|
+
end
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
Call your service from anywhere
|
38
|
+
```ruby
|
39
|
+
Foo.call(params)
|
40
|
+
```
|
41
|
+
|
42
|
+
## Example
|
43
|
+
|
44
|
+
Simple example to change status of a "transaction" to complete
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
# app/services/complete_transation_service.rb
|
48
|
+
class CompleteTransation < Service
|
49
|
+
def perform
|
50
|
+
@transation.update(:status, :complete)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
if CompleteTransation.call(transation: @transation)
|
57
|
+
puts 'Transation complete!'
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
## Contributing
|
62
|
+
|
63
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/iago-silva/service_it.
|
64
|
+
|
65
|
+
## License
|
66
|
+
|
67
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'service_it'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
require "pry"
|
10
|
+
Pry.start
|
11
|
+
|
12
|
+
require 'irb'
|
13
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/service.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Inherit this class and implement perform method
|
2
|
+
#
|
3
|
+
# Documentation:
|
4
|
+
# https://github.com/iago-silva/service_it#usage
|
5
|
+
class Service
|
6
|
+
class << self
|
7
|
+
# Call your service
|
8
|
+
#
|
9
|
+
# Example:
|
10
|
+
# ServiceIt.call(arg1: 1, arg2: 2)
|
11
|
+
#
|
12
|
+
# Arguments:
|
13
|
+
# args: (Hash)
|
14
|
+
#
|
15
|
+
# Return:
|
16
|
+
# perform's return
|
17
|
+
def call(**args)
|
18
|
+
new_instance(args).perform
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def new_instance(args)
|
24
|
+
instance = new
|
25
|
+
|
26
|
+
args.each do |key, value|
|
27
|
+
instance.instance_variable_set("@#{key}", value)
|
28
|
+
end
|
29
|
+
|
30
|
+
instance
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Implement this method to run your service
|
35
|
+
def perform
|
36
|
+
raise NotImplementedError,
|
37
|
+
"Please implement 'perform' method in your #{self.class.name}"
|
38
|
+
end
|
39
|
+
end
|
data/lib/service_it.rb
ADDED
data/service_it.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'service_it'
|
6
|
+
s.version = '0.1.5'
|
7
|
+
s.date = '2018-07-27'
|
8
|
+
s.authors = ['Iago Silva']
|
9
|
+
s.email = 'iago.silva@interage.in'
|
10
|
+
s.homepage = 'https://github.com/iago-silva/service_it'
|
11
|
+
s.license = 'MIT'
|
12
|
+
s.summary = 'A simple gem for Rails that allows you to isolate a snippet
|
13
|
+
of code and call it from anywhere'
|
14
|
+
s.description = 'Its main objective is to provide you a way to delegate
|
15
|
+
responsibilities in your project'
|
16
|
+
|
17
|
+
s.files = `git ls-files -z`.split("\x0")
|
18
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
20
|
+
s.require_paths = ['lib']
|
21
|
+
|
22
|
+
s.add_development_dependency 'bundler'
|
23
|
+
s.add_development_dependency 'rake'
|
24
|
+
s.add_development_dependency 'rspec'
|
25
|
+
s.add_development_dependency 'pry'
|
26
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'service'
|
2
|
+
|
3
|
+
describe Service do
|
4
|
+
let(:result) { SayMyName.call(name: 'Heisenberg') }
|
5
|
+
|
6
|
+
before do
|
7
|
+
class SayMyName < Service
|
8
|
+
def perform
|
9
|
+
@name
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'say Heisenberg' do
|
15
|
+
expect(result).to eq('Heisenberg')
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: service_it
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Iago Silva
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-07-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
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
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: |-
|
70
|
+
Its main objective is to provide you a way to delegate
|
71
|
+
responsibilities in your project
|
72
|
+
email: iago.silva@interage.in
|
73
|
+
executables:
|
74
|
+
- console
|
75
|
+
- setup
|
76
|
+
extensions: []
|
77
|
+
extra_rdoc_files: []
|
78
|
+
files:
|
79
|
+
- ".gitignore"
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- lib/service.rb
|
87
|
+
- lib/service_it.rb
|
88
|
+
- service_it.gemspec
|
89
|
+
- spec/service_spec.rb
|
90
|
+
homepage: https://github.com/iago-silva/service_it
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.7.3
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: A simple gem for Rails that allows you to isolate a snippet of code and call
|
114
|
+
it from anywhere
|
115
|
+
test_files:
|
116
|
+
- spec/service_spec.rb
|