service_it 0.1.6 → 0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 614561e699e7f8c0ae4f2fba193f64318d5c68f8658fce2c5319cf92bc2194e5
4
- data.tar.gz: 3069a058004f09a212c2f759ceb13918757621aa9d621a1f1798391c37bea935
3
+ metadata.gz: be1085eaf772f8657824e4495bdb6bb3ffe89362368fd922b7202ed8a7293966
4
+ data.tar.gz: d27ac5b1a0f82925d1d13849a9a556c84565d5427765a3ebf925971e3c1a627a
5
5
  SHA512:
6
- metadata.gz: 49a2c89469386d1ad13489e0637dbf82f739e5dfe6c02eb166441d6b4e04c28c3d89e47588f8b0c71dc26bf7ae9c7f934ece6308e298189ec29264de3b347a13
7
- data.tar.gz: 61546e88499409d96b13bfb88405065e8a1b75c2e6b0f58343955d428e63daeb13a643472ce7777d0a24ee866f60a5cd85d7c0326dc89a3f5561307cac2f4275
6
+ metadata.gz: 6eb0d062f6453045d96ef3549e01a8c6347eec3f4cf689b7fc96882f169171a2e8e7ac03634813fdec713ea3291ce475f0c867da06de6b96b6c89f4250bb0f09
7
+ data.tar.gz: 585172ed14df1120bc16d551f8336c9fbf4bb84f5355c488084a0cd012af64880ecbb1fd4eb8e3469da712167059c97a16b7ddaaafd104fdcb45bbbe76dec4ae
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,12 @@
1
+ require:
2
+ - rubocop-rspec
3
+ - rubocop-performance
4
+
5
+ inherit_mode:
6
+ merge:
7
+ - Exclude
8
+
9
+ AllCops:
10
+ TargetRubyVersion: 2.2
11
+ Exclude:
12
+ - 'lib/generators/rails/templates/**/*'
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ sudo: false
2
+
3
+ cache: bundler
4
+
5
+ language: ruby
6
+
7
+ rvm:
8
+ - 2.2
9
+
10
+ script:
11
+ - bundle exec rspec
12
+ - bundle exec rubocop
data/Gemfile.lock CHANGED
@@ -1,40 +1,56 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- service_it (0.1.6)
4
+ service_it (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- coderay (1.1.2)
9
+ ast (2.4.0)
10
10
  diff-lcs (1.3)
11
- method_source (0.9.2)
12
- pry (0.12.2)
13
- coderay (~> 1.1.0)
14
- method_source (~> 0.9.0)
15
- rake (12.3.2)
16
- rspec (3.7.0)
17
- rspec-core (~> 3.7.0)
18
- rspec-expectations (~> 3.7.0)
19
- rspec-mocks (~> 3.7.0)
20
- rspec-core (3.7.1)
21
- rspec-support (~> 3.7.0)
22
- rspec-expectations (3.7.0)
11
+ jaro_winkler (1.5.2)
12
+ parallel (1.17.0)
13
+ parser (2.6.2.1)
14
+ ast (~> 2.4.0)
15
+ psych (3.1.0)
16
+ rainbow (3.0.0)
17
+ rspec (3.8.0)
18
+ rspec-core (~> 3.8.0)
19
+ rspec-expectations (~> 3.8.0)
20
+ rspec-mocks (~> 3.8.0)
21
+ rspec-core (3.8.0)
22
+ rspec-support (~> 3.8.0)
23
+ rspec-expectations (3.8.3)
23
24
  diff-lcs (>= 1.2.0, < 2.0)
24
- rspec-support (~> 3.7.0)
25
- rspec-mocks (3.7.0)
25
+ rspec-support (~> 3.8.0)
26
+ rspec-mocks (3.8.0)
26
27
  diff-lcs (>= 1.2.0, < 2.0)
27
- rspec-support (~> 3.7.0)
28
- rspec-support (3.7.1)
28
+ rspec-support (~> 3.8.0)
29
+ rspec-support (3.8.0)
30
+ rubocop (0.67.2)
31
+ jaro_winkler (~> 1.5.1)
32
+ parallel (~> 1.10)
33
+ parser (>= 2.5, != 2.5.1.1)
34
+ psych (>= 3.1.0)
35
+ rainbow (>= 2.2.2, < 4.0)
36
+ ruby-progressbar (~> 1.7)
37
+ unicode-display_width (>= 1.4.0, < 1.6)
38
+ rubocop-performance (1.1.0)
39
+ rubocop (>= 0.67.0)
40
+ rubocop-rspec (1.32.0)
41
+ rubocop (>= 0.60.0)
42
+ ruby-progressbar (1.10.0)
43
+ unicode-display_width (1.5.0)
29
44
 
30
45
  PLATFORMS
31
46
  ruby
32
47
 
33
48
  DEPENDENCIES
34
49
  bundler
35
- pry
36
- rake
37
50
  rspec
51
+ rubocop
52
+ rubocop-performance
53
+ rubocop-rspec
38
54
  service_it!
39
55
 
40
56
  BUNDLED WITH
data/README.md CHANGED
@@ -1,11 +1,6 @@
1
- # ServiceIt
1
+ # ServiceIt [![Gem Version](https://badge.fury.io/rb/service_it.svg)](https://badge.fury.io/rb/service_it) [![Build Status](https://travis-ci.org/iago-silva/service_it.svg?branch=master)](https://travis-ci.org/iago-silva/service_it) [![Code Climate](https://codeclimate.com/github/iago-silva/service_it.png)](https://codeclimate.com/github/iago-silva/service_it) [![Downloads](https://img.shields.io/gem/dt/service_it.svg)](https://rubygems.org/gems/service_it) [![License](https://img.shields.io/badge/license-MIT-green.svg)](http://opensource.org/licenses/MIT)
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/service_it.svg)](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>
3
+ Provide you a way to delegate responsibilities in your project using callables
9
4
 
10
5
  <br/>
11
6
 
@@ -13,7 +8,7 @@
13
8
 
14
9
  Add this line to your application's Gemfile:
15
10
 
16
- gem 'service_it', '0.1.6'
11
+ gem 'service_it', '~> 0.1.6'
17
12
 
18
13
  And then execute:
19
14
 
@@ -22,40 +17,46 @@ And then execute:
22
17
  Or install it yourself as:
23
18
 
24
19
  $ gem install service_it
20
+
21
+ ## Generator
22
+
23
+ $ rails g service NAME
25
24
 
26
25
  ## Usage
27
26
 
28
- Inherit your class of `Service` and implement `perform` method
29
27
  ```ruby
30
- class Foo < Service
31
- def perform
32
- # here you can use params that became instance variables
33
- end
28
+ # app/services/foo.rb
29
+ class Foo < ServiceIt::Base
30
+ def perform
31
+ # here you can use params that became instance variables
34
32
  end
33
+ end
35
34
  ```
36
35
 
37
36
  Call your service from anywhere
38
37
  ```ruby
39
- Foo.call(params)
38
+ Foo.call(params)
40
39
  ```
41
40
 
42
41
  ## Example
43
42
 
44
- Simple example to change status of a "transaction" to complete
43
+ Simple example to change status of a _transaction_ to complete
44
+
45
+ $ rails g service CompleteTransaction
45
46
 
46
47
  ```ruby
47
- # app/services/complete_transation_service.rb
48
- class CompleteTransation < Service
49
- def perform
50
- @transation.update(:status, :complete)
51
- end
48
+ # app/services/complete_transaction.rb
49
+ class CompleteTransaction < ServiceIt::Base
50
+ def perform
51
+ @transaction.update(:status, :complete)
52
52
  end
53
+ end
53
54
  ```
54
55
 
55
56
  ```ruby
56
- if CompleteTransation.call(transation: @transation)
57
- puts 'Transation complete!'
58
- end
57
+ if CompleteTransaction.call(transaction: transaction)
58
+ puts 'Transaction complete!'
59
+ end
59
60
  ```
60
61
 
61
62
  ## Contributing
data/Rakefile CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'rspec/core/rake_task'
2
- require 'bundler/gem_tasks'
3
2
 
4
3
  RSpec::Core::RakeTask.new(:spec)
5
4
 
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Creates a service
3
+
4
+ Example:
5
+ rails g service Foo
6
+
7
+ This will create:
8
+ app/services/foo.rb
@@ -0,0 +1,13 @@
1
+ module Rails
2
+ module Generators
3
+ # Generates a service by command line
4
+ class ServiceGenerator < NamedBase
5
+ source_root File.expand_path('templates', __dir__)
6
+
7
+ def create_service_file
8
+ template 'service.rb',
9
+ File.join('app/services', class_path, "#{file_name}.rb")
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,4 @@
1
+ class <%= class_name %> < ServiceIt::Base
2
+ def perform
3
+ end
4
+ end
@@ -0,0 +1,41 @@
1
+ module ServiceIt
2
+ # Inherit this class and implement perform method
3
+ #
4
+ # Documentation:
5
+ # https://github.com/iago-silva/service_it#usage
6
+ class Base
7
+ class << self
8
+ # Call your service
9
+ #
10
+ # Example:
11
+ # Foo.call(arg1: 1, arg2: 2)
12
+ #
13
+ # Arguments:
14
+ # args: (Hash)
15
+ #
16
+ # Return:
17
+ # perform's return
18
+ def call(**args)
19
+ new_instance(args).perform
20
+ end
21
+
22
+ private
23
+
24
+ def new_instance(args)
25
+ instance = new
26
+
27
+ args.each do |key, value|
28
+ instance.instance_variable_set("@#{key}", value)
29
+ end
30
+
31
+ instance
32
+ end
33
+ end
34
+
35
+ # Implement this method to run your service
36
+ def perform
37
+ raise NotImplementedError,
38
+ "Please implement 'perform' method in your #{self.class.name}"
39
+ end
40
+ end
41
+ end
data/lib/service_it.rb CHANGED
@@ -1 +1 @@
1
- require "service"
1
+ require 'service_it/base'
data/service_it.gemspec CHANGED
@@ -3,24 +3,28 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'service_it'
6
- s.version = '0.1.6'
6
+ s.version = '0.2.0'
7
7
  s.date = '2018-07-27'
8
8
  s.authors = ['Iago Silva']
9
9
  s.email = 'iago.silva@interage.in'
10
10
  s.homepage = 'https://github.com/iago-silva/service_it'
11
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'
12
+ s.summary = 'Simple gem for Rails that allows you to isolate a piece of
13
+ code and call it from anywhere'
14
+ s.description = 'Provide you a way to delegate responsibilities in your
15
+ project using callables'
16
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']
17
+ s.test_files = `git ls-files -- spec/*`.split("\n")
18
+ s.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
21
 
22
22
  s.add_development_dependency 'bundler'
23
- s.add_development_dependency 'rake'
24
23
  s.add_development_dependency 'rspec'
25
- s.add_development_dependency 'pry'
24
+
25
+ if RUBY_VERSION >= '2.2.0'
26
+ s.add_development_dependency 'rubocop'
27
+ s.add_development_dependency 'rubocop-performance'
28
+ s.add_development_dependency 'rubocop-rspec'
29
+ end
26
30
  end
@@ -0,0 +1,10 @@
1
+ describe ServiceIt do
2
+ describe SayMyName do
3
+ let(:name) { 'Heisenberg' }
4
+ let(:perform) { described_class.call(name: name) }
5
+
6
+ it 'says Heisenberg' do
7
+ expect(perform).to eq(name)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
2
+
3
+ require 'service_it'
4
+
5
+ Dir['./spec/support/**/*.rb'].each { |f| require f }
@@ -0,0 +1,5 @@
1
+ class SayMyName < ServiceIt::Base
2
+ def perform
3
+ @name
4
+ end
5
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: service_it
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Iago Silva
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,7 +39,21 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
42
+ name: rubocop
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: rubocop-performance
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - ">="
@@ -53,7 +67,7 @@ dependencies:
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
- name: pry
70
+ name: rubocop-rspec
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - ">="
@@ -67,27 +81,31 @@ dependencies:
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
69
83
  description: |-
70
- Its main objective is to provide you a way to delegate
71
- responsibilities in your project
84
+ Provide you a way to delegate responsibilities in your
85
+ project using callables
72
86
  email: iago.silva@interage.in
73
- executables:
74
- - console
75
- - setup
87
+ executables: []
76
88
  extensions: []
77
89
  extra_rdoc_files: []
78
90
  files:
79
91
  - ".gitignore"
92
+ - ".rspec"
93
+ - ".rubocop.yml"
94
+ - ".travis.yml"
80
95
  - Gemfile
81
96
  - Gemfile.lock
82
97
  - LICENSE.txt
83
98
  - README.md
84
99
  - Rakefile
85
- - bin/console
86
- - bin/setup
87
- - lib/service.rb
100
+ - lib/generators/rails/USAGE
101
+ - lib/generators/rails/service_generator.rb
102
+ - lib/generators/rails/templates/service.rb
88
103
  - lib/service_it.rb
104
+ - lib/service_it/base.rb
89
105
  - service_it.gemspec
90
- - spec/service_spec.rb
106
+ - spec/service_it_spec.rb
107
+ - spec/spec_helper.rb
108
+ - spec/support/test_classes.rb
91
109
  homepage: https://github.com/iago-silva/service_it
92
110
  licenses:
93
111
  - MIT
@@ -111,7 +129,9 @@ rubyforge_project:
111
129
  rubygems_version: 2.7.3
112
130
  signing_key:
113
131
  specification_version: 4
114
- summary: A simple gem for Rails that allows you to isolate a snippet of code and call
132
+ summary: Simple gem for Rails that allows you to isolate a piece of code and call
115
133
  it from anywhere
116
134
  test_files:
117
- - spec/service_spec.rb
135
+ - spec/service_it_spec.rb
136
+ - spec/spec_helper.rb
137
+ - spec/support/test_classes.rb
data/bin/console DELETED
@@ -1,13 +0,0 @@
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 DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
data/lib/service.rb DELETED
@@ -1,39 +0,0 @@
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/spec/service_spec.rb DELETED
@@ -1,17 +0,0 @@
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