service_it 1.1.0 → 1.2.0
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 +4 -4
- data/README.md +3 -1
- data/lib/service_it/base.rb +27 -31
- data/lib/service_it/version.rb +1 -1
- data/spec/service_it_spec.rb +4 -2
- data/spec/spec_helper.rb +7 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3f5602ec47b3704b58581e2367192e409ff098a3232f25d925cf1256f82d434
|
4
|
+
data.tar.gz: a9c85fe22387bcca449b0242905f204e2b30473c6259246cf345341c549712f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df4426ddc277a66097a73e40228e722fffcb69c9e114041143936f1c377fa98d440651bacf4f20d8a06e62fff1a2a769bcd66395657aa959ad7b5a47c64aa9ff
|
7
|
+
data.tar.gz: 2d356875f6f388617705b4b8f6799a616a8046553385f3c0da94b087f4b077d1dbf7bba7e43792fe495aa1e89040c067a8351f0dae19ee74190d3cb3beb4151c
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# ServiceIt
|
2
2
|
[](https://badge.fury.io/rb/service_it) [](https://travis-ci.org/iago-silva/service_it) [](https://codeclimate.com/github/iago-silva/service_it) [](https://codeclimate.com/github/iago-silva/service_it/test_coverage)
|
3
3
|
|
4
|
+
Its benefit is to facilitate the creation of Service Objects, providing you the basic and enough to have a complete one and letting you free to use on your own way.
|
5
|
+
|
4
6
|
- [ServiceIt](#serviceit)
|
5
7
|
- [Installation](#installation)
|
6
8
|
- [With Bundler](#with-bundler)
|
@@ -16,7 +18,7 @@
|
|
16
18
|
|
17
19
|
Add this line to your `Gemfile`:
|
18
20
|
|
19
|
-
gem 'service_it', '~> 1.
|
21
|
+
gem 'service_it', '~> 1.2.0'
|
20
22
|
|
21
23
|
And then execute:
|
22
24
|
|
data/lib/service_it/base.rb
CHANGED
@@ -6,38 +6,22 @@ module ServiceIt
|
|
6
6
|
# Documentation:
|
7
7
|
# https://github.com/iago-silva/service_it
|
8
8
|
class Base
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def new_instance(args)
|
27
|
-
instance = new
|
28
|
-
|
29
|
-
args.each do |key, value|
|
30
|
-
instance.instance_variable_set("@#{key}", value)
|
31
|
-
|
32
|
-
class_eval do
|
33
|
-
private
|
34
|
-
|
35
|
-
attr_accessor key.to_sym
|
36
|
-
end
|
37
|
-
end
|
9
|
+
# Call your service
|
10
|
+
#
|
11
|
+
# Example:
|
12
|
+
# Foo.call(arg1: 1, arg2: 2)
|
13
|
+
#
|
14
|
+
# Arguments:
|
15
|
+
# args: (Hash)
|
16
|
+
#
|
17
|
+
# Return:
|
18
|
+
# perform's return
|
19
|
+
def self.call(**args)
|
20
|
+
new(args).perform
|
21
|
+
end
|
38
22
|
|
39
|
-
|
40
|
-
|
23
|
+
def initialize(args)
|
24
|
+
args.each { |key, value| set_private_ivar(key, value) }
|
41
25
|
end
|
42
26
|
|
43
27
|
# Implement this method to run your service
|
@@ -45,5 +29,17 @@ module ServiceIt
|
|
45
29
|
raise NotImplementedError,
|
46
30
|
"Please implement 'perform' method in your #{self.class.name}"
|
47
31
|
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def set_private_ivar(key, value)
|
36
|
+
instance_variable_set("@#{key}", value)
|
37
|
+
|
38
|
+
self.class.class_eval do
|
39
|
+
private
|
40
|
+
|
41
|
+
attr_reader key.to_sym
|
42
|
+
end
|
43
|
+
end
|
48
44
|
end
|
49
45
|
end
|
data/lib/service_it/version.rb
CHANGED
data/spec/service_it_spec.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe ServiceIt do
|
4
6
|
describe SayMyName do
|
5
7
|
let(:name) { 'Heisenberg' }
|
6
|
-
let(:call) { SayMyName.call(name: 'Heisenberg') }
|
7
8
|
|
8
9
|
it 'says Heisenberg' do
|
9
|
-
|
10
|
+
result = SayMyName.call(name: name)
|
11
|
+
expect(result).to eq(name)
|
10
12
|
end
|
11
13
|
end
|
12
14
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
SimpleCov.minimum_coverage 100
|
4
|
-
SimpleCov.start do
|
5
|
-
add_filter '/spec/'
|
6
|
-
end
|
1
|
+
# frozen_string_literal: true
|
7
2
|
|
8
3
|
$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
|
9
4
|
|
10
5
|
require 'service_it'
|
6
|
+
require 'simplecov'
|
11
7
|
|
12
8
|
Dir['./spec/support/**/*.rb'].each { |f| require f }
|
9
|
+
|
10
|
+
SimpleCov.minimum_coverage 100
|
11
|
+
SimpleCov.start do
|
12
|
+
add_filter '/spec/'
|
13
|
+
end
|