Skip to content

Commit

Permalink
v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
iago-silva committed Dec 5, 2020
1 parent 4174ee7 commit dc842ad
Show file tree
Hide file tree
Showing 15 changed files with 140 additions and 89 deletions.
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--require spec_helper
13 changes: 12 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
require: rubocop-rspec

inherit_mode:
merge:
- Exclude

AllCops:
TargetRubyVersion: 2.2
TargetRubyVersion: 2.4.0
NewCops: enable
Exclude:
- 'lib/generators/rails/templates/**/*'

Style/FrozenStringLiteralComment:
Exclude:
- 'bin/**/*'
- 'Gemfile'

RSpec/NamedSubject:
Enabled: false
18 changes: 1 addition & 17 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
sudo: false

cache: bundler

language: ruby

rvm:
- 2.2

env:
global:
- CC_TEST_REPORTER_ID=26bc71f0fff96d8eafdc0e8dbe867ab6fa5c281bde2df2a10b025ca9f9e066ea

before_script:
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build
- 2.4.0

script:
- bundle exec rspec
- bundle exec rubocop

after_script:
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
77 changes: 42 additions & 35 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,56 +1,63 @@
PATH
remote: .
specs:
service_it (1.2.0)
service_it (2.0.0)

GEM
remote: https://rubygems.org/
specs:
ast (2.4.0)
diff-lcs (1.3)
docile (1.3.1)
jaro_winkler (1.5.2)
json (2.2.0)
parallel (1.17.0)
parser (2.6.3.0)
ast (~> 2.4.0)
ast (2.4.1)
coderay (1.1.3)
diff-lcs (1.4.4)
method_source (1.0.0)
parallel (1.20.1)
parser (2.7.2.0)
ast (~> 2.4.1)
pry (0.13.1)
coderay (~> 1.1)
method_source (~> 1.0)
rainbow (3.0.0)
rspec (3.8.0)
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
rspec-mocks (~> 3.8.0)
rspec-core (3.8.0)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.3)
regexp_parser (2.0.0)
rexml (3.2.4)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
rspec-mocks (~> 3.10.0)
rspec-core (3.10.0)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-mocks (3.8.0)
rspec-support (~> 3.10.0)
rspec-mocks (3.10.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.0)
rubocop (0.68.1)
jaro_winkler (~> 1.5.1)
rspec-support (~> 3.10.0)
rspec-support (3.10.0)
rubocop (1.5.1)
parallel (~> 1.10)
parser (>= 2.5, != 2.5.1.1)
parser (>= 2.7.1.5)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.0)
rexml
rubocop-ast (>= 1.2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 1.6)
ruby-progressbar (1.10.0)
simplecov (0.16.1)
docile (~> 1.1)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)
unicode-display_width (1.5.0)
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (1.3.0)
parser (>= 2.7.1.5)
rubocop-rspec (2.0.1)
rubocop (~> 1.0)
rubocop-ast (>= 1.1.0)
ruby-progressbar (1.10.1)
unicode-display_width (1.7.0)

PLATFORMS
ruby

DEPENDENCIES
rspec
rubocop
pry (= 0.13.1)
rspec (= 3.10.0)
rubocop (= 1.5.1)
rubocop-rspec (= 2.0.1)
service_it!
simplecov

BUNDLED WITH
1.16.6
2.1.2
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# 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) [![Test Coverage](https://api.codeclimate.com/v1/badges/fcc8375ebe8fa5412381/test_coverage)](https://codeclimate.com/github/iago-silva/service_it/test_coverage)
[![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)

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.

Expand Down
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)
Expand Down
14 changes: 14 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env ruby

require 'bundler/setup'
require 'service_it'

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

# (If you use this, don't forget to add pry to your Gemfile!)
require 'pry'
Pry.start

# require "irb"
# IRB.start(__FILE__)
8 changes: 8 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
set -vx

bundle install

# Do any other automated setup that you need to do here
11 changes: 9 additions & 2 deletions lib/service_it/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ module ServiceIt
# Documentation:
# https://github.com/iago-silva/service_it
class Base
private_class_method :new

# Call your service
#
# Example:
Expand All @@ -21,7 +23,10 @@ def self.call(**args)
end

def initialize(args)
args.each { |key, value| set_private_ivar(key, value) }
args.each do |key, value|
define_ivar(key, value)
define_private_reader(key)
end
end

# Implement this method to run your service
Expand All @@ -32,9 +37,11 @@ def perform

private

def set_private_ivar(key, value)
def define_ivar(key, value)
instance_variable_set("@#{key}", value)
end

def define_private_reader(key)
self.class.class_eval do
private

Expand Down
2 changes: 1 addition & 1 deletion lib/service_it/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module ServiceIt
VERSION = '1.2.0'.freeze
VERSION = '2.0.0'
end
18 changes: 12 additions & 6 deletions service_it.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@ Gem::Specification.new do |s|
s.version = ServiceIt::VERSION
s.date = '2018-07-27'
s.authors = ['Iago Silva']
s.email = 'iago.[email protected]'
s.email = ['iago.[email protected]']
s.homepage = 'https://github.com/iago-silva/service_it'
s.license = 'MIT'
s.summary = 'Simple gem to keep your controllers and models slim and
readable'
s.description = 'Service objects are a holy grail to keep your controllers and
models slim and readable'

s.files = Dir['lib/**/*', '*.md']
s.test_files = Dir['spec/**/*']
s.required_ruby_version = Gem::Requirement.new('>= 2.4.0')

s.add_development_dependency 'rspec'
s.add_development_dependency 'rubocop'
s.add_development_dependency 'simplecov'
s.metadata['homepage_uri'] = s.homepage
s.metadata['source_code_uri'] = s.homepage

s.files = Dir['lib/**/*', '*.md']
s.test_files = Dir['spec/**/*']

s.add_development_dependency 'pry', '0.13.1'
s.add_development_dependency 'rspec', '3.10.0'
s.add_development_dependency 'rubocop', '1.5.1'
s.add_development_dependency 'rubocop-rspec', '2.0.1'
end
33 changes: 33 additions & 0 deletions spec/service_it/base_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

describe ServiceIt::Base do
context 'when calls new method' do
subject { described_class.new }

it 'raises NoMethodError exception' do
expect { subject }.to raise_error(NoMethodError)
end
end

describe SayMyName do
context 'when I ask what is my name' do
subject { described_class.call(name: name) }

let(:name) { 'Heisenberg' }

it 'says Heisenberg' do
expect(subject).to eq(name)
end
end
end

describe MissedPerformService do
context 'when perform method is not defined' do
subject { described_class.call }

it 'raises NotImplementedError exception' do
expect { subject }.to raise_error(NotImplementedError)
end
end
end
end
19 changes: 2 additions & 17 deletions spec/service_it_spec.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
# frozen_string_literal: true

require 'spec_helper'

describe ServiceIt do
describe SayMyName do
let(:name) { 'Heisenberg' }

it 'says Heisenberg' do
result = SayMyName.call(name: name)
expect(result).to eq(name)
end
end

context 'when perform method is not defined' do
it 'raises an NotImplementedError exception' do
expect do
MissedPerformService.call
end.to raise_error(NotImplementedError)
end
it 'has a version number' do
expect(ServiceIt::VERSION).not_to be nil
end
end
8 changes: 1 addition & 7 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,5 @@
$LOAD_PATH.unshift File.expand_path('../lib', __dir__)

require 'service_it'
require 'simplecov'

Dir['./spec/support/**/*.rb'].each { |f| require f }

SimpleCov.minimum_coverage 100
SimpleCov.start do
add_filter '/spec/'
end
Dir['./spec/support/**/*.rb'].sort.each { |f| require f }
3 changes: 1 addition & 2 deletions spec/support/test_classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ def perform
end
end

class MissedPerformService < ServiceIt::Base
end
class MissedPerformService < ServiceIt::Base; end

0 comments on commit dc842ad

Please sign in to comment.