From dc842ade8ff65b278d0eb79698d9a5404e5a0559 Mon Sep 17 00:00:00 2001 From: Iago Silva Date: Sat, 5 Dec 2020 14:01:57 -0300 Subject: [PATCH] v2.0.0 --- .rspec | 2 + .rubocop.yml | 13 +++++- .travis.yml | 18 +-------- Gemfile.lock | 77 ++++++++++++++++++++---------------- README.md | 2 +- Rakefile | 1 + bin/console | 14 +++++++ bin/setup | 8 ++++ lib/service_it/base.rb | 11 +++++- lib/service_it/version.rb | 2 +- service_it.gemspec | 18 ++++++--- spec/service_it/base_spec.rb | 33 ++++++++++++++++ spec/service_it_spec.rb | 19 +-------- spec/spec_helper.rb | 8 +--- spec/support/test_classes.rb | 3 +- 15 files changed, 140 insertions(+), 89 deletions(-) create mode 100644 .rspec create mode 100755 bin/console create mode 100755 bin/setup create mode 100644 spec/service_it/base_spec.rb diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..83e16f8 --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--color +--require spec_helper diff --git a/.rubocop.yml b/.rubocop.yml index 43a2273..b89f0b9 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -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 diff --git a/.travis.yml b/.travis.yml index 5c5fe02..c9d2545 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index dc839fd..c478665 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/README.md b/README.md index 8da4a9a..930488e 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/Rakefile b/Rakefile index cffdd09..82bb534 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,6 @@ # frozen_string_literal: true +require 'bundler/gem_tasks' require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) diff --git a/bin/console b/bin/console new file mode 100755 index 0000000..a23fc9a --- /dev/null +++ b/bin/console @@ -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__) diff --git a/bin/setup b/bin/setup new file mode 100755 index 0000000..dce67d8 --- /dev/null +++ b/bin/setup @@ -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 diff --git a/lib/service_it/base.rb b/lib/service_it/base.rb index c72386d..41d75c8 100644 --- a/lib/service_it/base.rb +++ b/lib/service_it/base.rb @@ -6,6 +6,8 @@ module ServiceIt # Documentation: # https://github.com/iago-silva/service_it class Base + private_class_method :new + # Call your service # # Example: @@ -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 @@ -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 diff --git a/lib/service_it/version.rb b/lib/service_it/version.rb index 09ef517..b161b0c 100644 --- a/lib/service_it/version.rb +++ b/lib/service_it/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module ServiceIt - VERSION = '1.2.0'.freeze + VERSION = '2.0.0' end diff --git a/service_it.gemspec b/service_it.gemspec index 10c041a..42dbfaa 100644 --- a/service_it.gemspec +++ b/service_it.gemspec @@ -7,7 +7,7 @@ Gem::Specification.new do |s| s.version = ServiceIt::VERSION s.date = '2018-07-27' s.authors = ['Iago Silva'] - s.email = 'iago.silva@interage.in' + s.email = ['iago.cith@hotmail.com'] s.homepage = 'https://github.com/iago-silva/service_it' s.license = 'MIT' s.summary = 'Simple gem to keep your controllers and models slim and @@ -15,10 +15,16 @@ Gem::Specification.new do |s| 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 diff --git a/spec/service_it/base_spec.rb b/spec/service_it/base_spec.rb new file mode 100644 index 0000000..afff761 --- /dev/null +++ b/spec/service_it/base_spec.rb @@ -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 diff --git a/spec/service_it_spec.rb b/spec/service_it_spec.rb index 8455a4c..e929350 100644 --- a/spec/service_it_spec.rb +++ b/spec/service_it_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 69b07ca..6c5a388 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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 } diff --git a/spec/support/test_classes.rb b/spec/support/test_classes.rb index 72db286..04770b5 100644 --- a/spec/support/test_classes.rb +++ b/spec/support/test_classes.rb @@ -6,5 +6,4 @@ def perform end end -class MissedPerformService < ServiceIt::Base -end +class MissedPerformService < ServiceIt::Base; end