service_it 1.2.0 → 2.0.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 -43
- data/lib/service_it/base.rb +9 -2
- data/lib/service_it/version.rb +1 -1
- data/spec/service_it/base_spec.rb +33 -0
- data/spec/service_it_spec.rb +2 -17
- data/spec/spec_helper.rb +1 -7
- data/spec/support/test_classes.rb +1 -2
- metadata +38 -20
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 242be73eac2e2beb31caa752a64e14b3df89a8d5d1e86171ed0ebd17108363eb
         | 
| 4 | 
            +
              data.tar.gz: f9bf6a0a347ea667a1b1d057edc866db2a7c720699bd2227ff251f71a1e212c7
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 63383bbf3934b6a25a3ed4bef403c0e21ad2c35abb5ba81914cd6fa010fa602d948e9868927a981ed0e0870df0767c5bf304bf8297f419d7c8bfb496950445e4
         | 
| 7 | 
            +
              data.tar.gz: d44619f576bfb329151a241f40f589ff0c54248faf0bc9dce9b229bf0095a79cd6cc432feaf6ac95f3d11f9ce40483b49b84b982e3f4b57714493a8ccfe7a7ca
         | 
    
        data/README.md
    CHANGED
    
    | @@ -1,5 +1,5 @@ | |
| 1 1 | 
             
            # ServiceIt
         | 
| 2 | 
            -
            [](https://badge.fury.io/rb/service_it) [](https://travis-ci.org/iago-silva/service_it) [](https://codeclimate.com/github/iago-silva/service_it)  | 
| 2 | 
            +
            [](https://badge.fury.io/rb/service_it) [](https://travis-ci.org/iago-silva/service_it) [](https://codeclimate.com/github/iago-silva/service_it) 
         | 
| 3 3 |  | 
| 4 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 5 |  | 
| @@ -49,7 +49,7 @@ class Foo < ServiceIt::Base | |
| 49 49 | 
             
            end
         | 
| 50 50 | 
             
            ```
         | 
| 51 51 |  | 
| 52 | 
            -
            Call your service from anywhere
         | 
| 52 | 
            +
            Call your service from anywhere (controllers, models, migrations, ...)
         | 
| 53 53 |  | 
| 54 54 | 
             
            ```ruby
         | 
| 55 55 | 
             
            Foo.call(foo: foo, bar: bar)
         | 
| @@ -59,48 +59,8 @@ Foo.call(foo: foo, bar: bar) | |
| 59 59 |  | 
| 60 60 | 
             
            Simple example to release a _POST_
         | 
| 61 61 |  | 
| 62 | 
            -
            * Before
         | 
| 63 | 
            -
             | 
| 64 | 
            -
            ```ruby
         | 
| 65 | 
            -
            # app/controllers/post_releases_controller.rb
         | 
| 66 | 
            -
            class PostReleasesController < ApplicationController
         | 
| 67 | 
            -
             | 
| 68 | 
            -
              # [...]
         | 
| 69 | 
            -
             | 
| 70 | 
            -
              def update
         | 
| 71 | 
            -
                @post.prepare_to_release                      # <--
         | 
| 72 | 
            -
                if @post.update(released_at: Date.current)    # <--
         | 
| 73 | 
            -
                  # [...]
         | 
| 74 | 
            -
                else
         | 
| 75 | 
            -
                  # [...]
         | 
| 76 | 
            -
                end
         | 
| 77 | 
            -
              end
         | 
| 78 | 
            -
             | 
| 79 | 
            -
              # [...]
         | 
| 80 | 
            -
             | 
| 81 | 
            -
            end
         | 
| 82 | 
            -
             | 
| 83 | 
            -
            ```
         | 
| 84 | 
            -
             | 
| 85 | 
            -
            * After
         | 
| 86 | 
            -
             | 
| 87 62 | 
             
            ```ruby
         | 
| 88 | 
            -
             | 
| 89 | 
            -
            class PostReleasesController < ApplicationController
         | 
| 90 | 
            -
             | 
| 91 | 
            -
              # [...]
         | 
| 92 | 
            -
             | 
| 93 | 
            -
              def update
         | 
| 94 | 
            -
                if ReleasePost.call(post: @post)    # <--
         | 
| 95 | 
            -
                  # [...]
         | 
| 96 | 
            -
                else
         | 
| 97 | 
            -
                  # [...]
         | 
| 98 | 
            -
                end
         | 
| 99 | 
            -
              end
         | 
| 100 | 
            -
             | 
| 101 | 
            -
              # [...]
         | 
| 102 | 
            -
             | 
| 103 | 
            -
            end
         | 
| 63 | 
            +
            ReleasePost.call(post: @post)
         | 
| 104 64 | 
             
            ```
         | 
| 105 65 |  | 
| 106 66 | 
             
            ```ruby
         | 
    
        data/lib/service_it/base.rb
    CHANGED
    
    | @@ -6,6 +6,8 @@ module ServiceIt | |
| 6 6 | 
             
              # Documentation:
         | 
| 7 7 | 
             
              #   https://github.com/iago-silva/service_it
         | 
| 8 8 | 
             
              class Base
         | 
| 9 | 
            +
                private_class_method :new
         | 
| 10 | 
            +
             | 
| 9 11 | 
             
                # Call your service
         | 
| 10 12 | 
             
                #
         | 
| 11 13 | 
             
                # Example:
         | 
| @@ -21,7 +23,10 @@ module ServiceIt | |
| 21 23 | 
             
                end
         | 
| 22 24 |  | 
| 23 25 | 
             
                def initialize(args)
         | 
| 24 | 
            -
                  args.each  | 
| 26 | 
            +
                  args.each do |key, value|
         | 
| 27 | 
            +
                    define_ivar(key, value)
         | 
| 28 | 
            +
                    define_private_reader(key)
         | 
| 29 | 
            +
                  end
         | 
| 25 30 | 
             
                end
         | 
| 26 31 |  | 
| 27 32 | 
             
                # Implement this method to run your service
         | 
| @@ -32,9 +37,11 @@ module ServiceIt | |
| 32 37 |  | 
| 33 38 | 
             
                private
         | 
| 34 39 |  | 
| 35 | 
            -
                def  | 
| 40 | 
            +
                def define_ivar(key, value)
         | 
| 36 41 | 
             
                  instance_variable_set("@#{key}", value)
         | 
| 42 | 
            +
                end
         | 
| 37 43 |  | 
| 44 | 
            +
                def define_private_reader(key)
         | 
| 38 45 | 
             
                  self.class.class_eval do
         | 
| 39 46 | 
             
                    private
         | 
| 40 47 |  | 
    
        data/lib/service_it/version.rb
    CHANGED
    
    
| @@ -0,0 +1,33 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe ServiceIt::Base do
         | 
| 4 | 
            +
              context 'when calls new method' do
         | 
| 5 | 
            +
                subject { described_class.new }
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                it 'raises NoMethodError exception' do
         | 
| 8 | 
            +
                  expect { subject }.to raise_error(NoMethodError)
         | 
| 9 | 
            +
                end
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              describe SayMyName do
         | 
| 13 | 
            +
                context 'when I ask what is my name' do
         | 
| 14 | 
            +
                  subject { described_class.call(name: name) }
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                  let(:name) { 'Heisenberg' }
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                  it 'says Heisenberg' do
         | 
| 19 | 
            +
                    expect(subject).to eq(name)
         | 
| 20 | 
            +
                  end
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
              end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
              describe MissedPerformService do
         | 
| 25 | 
            +
                context 'when perform method is not defined' do
         | 
| 26 | 
            +
                  subject { described_class.call }
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                  it 'raises NotImplementedError exception' do
         | 
| 29 | 
            +
                    expect { subject }.to raise_error(NotImplementedError)
         | 
| 30 | 
            +
                  end
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
              end
         | 
| 33 | 
            +
            end
         | 
    
        data/spec/service_it_spec.rb
    CHANGED
    
    | @@ -1,22 +1,7 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 2 |  | 
| 3 | 
            -
            require 'spec_helper'
         | 
| 4 | 
            -
             | 
| 5 3 | 
             
            describe ServiceIt do
         | 
| 6 | 
            -
               | 
| 7 | 
            -
                 | 
| 8 | 
            -
             | 
| 9 | 
            -
                it 'says Heisenberg' do
         | 
| 10 | 
            -
                  result = SayMyName.call(name: name)
         | 
| 11 | 
            -
                  expect(result).to eq(name)
         | 
| 12 | 
            -
                end
         | 
| 13 | 
            -
              end
         | 
| 14 | 
            -
             | 
| 15 | 
            -
              context 'when perform method is not defined' do
         | 
| 16 | 
            -
                it 'raises an NotImplementedError exception' do
         | 
| 17 | 
            -
                  expect do
         | 
| 18 | 
            -
                    MissedPerformService.call
         | 
| 19 | 
            -
                  end.to raise_error(NotImplementedError)
         | 
| 20 | 
            -
                end
         | 
| 4 | 
            +
              it 'has a version number' do
         | 
| 5 | 
            +
                expect(ServiceIt::VERSION).not_to be nil
         | 
| 21 6 | 
             
              end
         | 
| 22 7 | 
             
            end
         | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    | @@ -3,11 +3,5 @@ | |
| 3 3 | 
             
            $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
         | 
| 4 4 |  | 
| 5 5 | 
             
            require 'service_it'
         | 
| 6 | 
            -
            require 'simplecov'
         | 
| 7 6 |  | 
| 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
         | 
| 7 | 
            +
            Dir['./spec/support/**/*.rb'].sort.each { |f| require f }
         | 
    
        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:  | 
| 4 | 
            +
              version: 2.0.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Iago Silva
         | 
| @@ -10,52 +10,67 @@ bindir: bin | |
| 10 10 | 
             
            cert_chain: []
         | 
| 11 11 | 
             
            date: 2018-07-27 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: pry
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - '='
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: 0.13.1
         | 
| 20 | 
            +
              type: :development
         | 
| 21 | 
            +
              prerelease: false
         | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - '='
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: 0.13.1
         | 
| 13 27 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 28 | 
             
              name: rspec
         | 
| 15 29 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 30 | 
             
                requirements:
         | 
| 17 | 
            -
                - -  | 
| 31 | 
            +
                - - '='
         | 
| 18 32 | 
             
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            -
                    version:  | 
| 33 | 
            +
                    version: 3.10.0
         | 
| 20 34 | 
             
              type: :development
         | 
| 21 35 | 
             
              prerelease: false
         | 
| 22 36 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 37 | 
             
                requirements:
         | 
| 24 | 
            -
                - -  | 
| 38 | 
            +
                - - '='
         | 
| 25 39 | 
             
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            -
                    version:  | 
| 40 | 
            +
                    version: 3.10.0
         | 
| 27 41 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 28 42 | 
             
              name: rubocop
         | 
| 29 43 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 44 | 
             
                requirements:
         | 
| 31 | 
            -
                - -  | 
| 45 | 
            +
                - - '='
         | 
| 32 46 | 
             
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            -
                    version:  | 
| 47 | 
            +
                    version: 1.5.1
         | 
| 34 48 | 
             
              type: :development
         | 
| 35 49 | 
             
              prerelease: false
         | 
| 36 50 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 51 | 
             
                requirements:
         | 
| 38 | 
            -
                - -  | 
| 52 | 
            +
                - - '='
         | 
| 39 53 | 
             
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            -
                    version:  | 
| 54 | 
            +
                    version: 1.5.1
         | 
| 41 55 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            -
              name:  | 
| 56 | 
            +
              name: rubocop-rspec
         | 
| 43 57 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 58 | 
             
                requirements:
         | 
| 45 | 
            -
                - -  | 
| 59 | 
            +
                - - '='
         | 
| 46 60 | 
             
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            -
                    version:  | 
| 61 | 
            +
                    version: 2.0.1
         | 
| 48 62 | 
             
              type: :development
         | 
| 49 63 | 
             
              prerelease: false
         | 
| 50 64 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 65 | 
             
                requirements:
         | 
| 52 | 
            -
                - -  | 
| 66 | 
            +
                - - '='
         | 
| 53 67 | 
             
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            -
                    version:  | 
| 68 | 
            +
                    version: 2.0.1
         | 
| 55 69 | 
             
            description: |-
         | 
| 56 70 | 
             
              Service objects are a holy grail to keep your controllers and
         | 
| 57 71 | 
             
                                models slim and readable
         | 
| 58 | 
            -
            email: | 
| 72 | 
            +
            email:
         | 
| 73 | 
            +
            - iago.cith@hotmail.com
         | 
| 59 74 | 
             
            executables: []
         | 
| 60 75 | 
             
            extensions: []
         | 
| 61 76 | 
             
            extra_rdoc_files: []
         | 
| @@ -67,13 +82,16 @@ files: | |
| 67 82 | 
             
            - lib/service_it.rb
         | 
| 68 83 | 
             
            - lib/service_it/base.rb
         | 
| 69 84 | 
             
            - lib/service_it/version.rb
         | 
| 85 | 
            +
            - spec/service_it/base_spec.rb
         | 
| 70 86 | 
             
            - spec/service_it_spec.rb
         | 
| 71 87 | 
             
            - spec/spec_helper.rb
         | 
| 72 88 | 
             
            - spec/support/test_classes.rb
         | 
| 73 89 | 
             
            homepage: https://github.com/iago-silva/service_it
         | 
| 74 90 | 
             
            licenses:
         | 
| 75 91 | 
             
            - MIT
         | 
| 76 | 
            -
            metadata: | 
| 92 | 
            +
            metadata:
         | 
| 93 | 
            +
              homepage_uri: https://github.com/iago-silva/service_it
         | 
| 94 | 
            +
              source_code_uri: https://github.com/iago-silva/service_it
         | 
| 77 95 | 
             
            post_install_message: 
         | 
| 78 96 | 
             
            rdoc_options: []
         | 
| 79 97 | 
             
            require_paths:
         | 
| @@ -82,19 +100,19 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 82 100 | 
             
              requirements:
         | 
| 83 101 | 
             
              - - ">="
         | 
| 84 102 | 
             
                - !ruby/object:Gem::Version
         | 
| 85 | 
            -
                  version:  | 
| 103 | 
            +
                  version: 2.4.0
         | 
| 86 104 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 87 105 | 
             
              requirements:
         | 
| 88 106 | 
             
              - - ">="
         | 
| 89 107 | 
             
                - !ruby/object:Gem::Version
         | 
| 90 108 | 
             
                  version: '0'
         | 
| 91 109 | 
             
            requirements: []
         | 
| 92 | 
            -
             | 
| 93 | 
            -
            rubygems_version: 2.7.9
         | 
| 110 | 
            +
            rubygems_version: 3.1.2
         | 
| 94 111 | 
             
            signing_key: 
         | 
| 95 112 | 
             
            specification_version: 4
         | 
| 96 113 | 
             
            summary: Simple gem to keep your controllers and models slim and readable
         | 
| 97 114 | 
             
            test_files:
         | 
| 98 | 
            -
            - spec/spec_helper.rb
         | 
| 99 115 | 
             
            - spec/service_it_spec.rb
         | 
| 100 116 | 
             
            - spec/support/test_classes.rb
         | 
| 117 | 
            +
            - spec/service_it/base_spec.rb
         | 
| 118 | 
            +
            - spec/spec_helper.rb
         |