rest_my_case 1.5.0 → 1.6.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
  SHA1:
3
- metadata.gz: 4247a51223096c120fdb4055309c9fbbabd8517f
4
- data.tar.gz: a3c6837847258f454c8cb604ceed36a1e836c1ef
3
+ metadata.gz: d82932cb42f7f06eaa0a2ffd09fc866ae7217047
4
+ data.tar.gz: 35df440b5058dde4f650d7cc20a1f4f116c9c45f
5
5
  SHA512:
6
- metadata.gz: 6d7663942c2b7324ea877778295c87a19c7a18fdacb022e16136ca71b35d969b9beb473d8142a06bc9e9ef5b50540d93db4f3673232e2fd9c84700db8d6422a3
7
- data.tar.gz: 1a39bb5b4b29d394c71179cba26052066e404d418026c3c150475cb6980a99803cb70503d5ff3542b3ea16346193db95bbb8978b51a8d31c0d9172694e007da4
6
+ metadata.gz: 0495e5467c6f6331d5dd19878fc74171903f915ba5de464b3770cfdaa26df83df943b2773f857d23aec381995237ac5e5279ac912a6726bdc56b3b42829486bb
7
+ data.tar.gz: 5a28d8b8550466280cddb7352c12135b0f3f5d6bf8d90cdc5418eedbfa1908996321cb4a13d1c2d4441c23e143fea495e979354eb807a7222b9405d6123f9514
data/.rubocop.yml ADDED
@@ -0,0 +1,30 @@
1
+ Style/EmptyLinesAroundBlockBody:
2
+ Enabled: false
3
+
4
+ Style/EmptyLinesAroundMethodBody:
5
+ Enabled: false
6
+
7
+ Style/EmptyLinesAroundModuleBody:
8
+ Enabled: false
9
+
10
+ Style/EmptyLinesAroundClassBody:
11
+ Enabled: false
12
+
13
+ Style/DotPosition:
14
+ Enabled: false
15
+
16
+ Style/Encoding:
17
+ Enabled: true
18
+ EnforcedStyle: when_needed
19
+
20
+ AllCops:
21
+ Exclude:
22
+ - '**/Rakefile'
23
+ - '**/*.gemspec'
24
+ - '**/console'
25
+ - 'spec/**/*'
26
+ - 'tmp/**/*'
27
+ - 'pkg/**/*'
28
+
29
+ Documentation:
30
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.1.0
5
+
6
+ addons:
7
+ code_climate:
8
+ repo_token:
9
+ secure: "ByiO5La5wZqGf6TA/pwBTDs1CN/FBHxLiPR3tlhLi8Ij4ikXswlP5IqBwlFDxvlLeCU5cDMT+n9mpU9kQHhT2BZg/aeuEsUbELVUrTpTOnPbnptvRWGzvN7ipsuXZZI1UdL4L9YGo84vO1EQMdDS+zr2OSSP7t1U14uAjiFGwQQ="
10
+
11
+ env:
12
+ global:
13
+ secure: ByiO5La5wZqGf6TA/pwBTDs1CN/FBHxLiPR3tlhLi8Ij4ikXswlP5IqBwlFDxvlLeCU5cDMT+n9mpU9kQHhT2BZg/aeuEsUbELVUrTpTOnPbnptvRWGzvN7ipsuXZZI1UdL4L9YGo84vO1EQMdDS+zr2OSSP7t1U14uAjiFGwQQ=
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015 João
3
+ Copyright (c) 2015 João Gonçalves
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,2 +1,4 @@
1
- # RestMyCase
2
- Very light Ruby gem with everything you need in a "The Clean Architecture" use case scenario. Strongly inspired on the tdantas/usecasing gem.
1
+ # RestMyCase [![Code Climate](https://codeclimate.com/github/goncalvesjoao/rest_my_case/badges/gpa.svg)](https://codeclimate.com/github/goncalvesjoao/rest_my_case) [![Build Status](https://travis-ci.org/goncalvesjoao/rest_my_case.svg?branch=master)](https://travis-ci.org/goncalvesjoao/rest_my_case) [![Test Coverage](https://codeclimate.com/github/goncalvesjoao/rest_my_case/badges/coverage.svg)](https://codeclimate.com/github/goncalvesjoao/rest_my_case) [![Gem Version](https://badge.fury.io/rb/rest_my_case.svg)](http://badge.fury.io/rb/rest_my_case)
2
+
3
+ Very light Ruby gem with everything you need in a "The Clean Architecture" use case scenario.
4
+ Props to [@tdantas](https://github.com/tdantas) and [@junhanamaki](https://github.com/junhanamaki)
data/Rakefile CHANGED
@@ -1,2 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
2
 
3
+ require 'rspec/core/rake_task'
4
+
5
+ task :default => :test
6
+
7
+ RSpec::Core::RakeTask.new(:test)
data/console CHANGED
@@ -10,7 +10,4 @@ require 'bundler'
10
10
 
11
11
  Bundler.require(:default, 'development')
12
12
 
13
-
14
- require 'spec/support/perform'
15
-
16
13
  binding.pry
@@ -7,7 +7,7 @@ module RestMyCase
7
7
  TRIAL_COURT = Trial::Court.new Judge::Base, DefenseAttorney::Base
8
8
 
9
9
  def self.depends(*use_case_classes)
10
- dependencies.push *use_case_classes
10
+ dependencies.push(*use_case_classes)
11
11
  end
12
12
 
13
13
  def self.dependencies
@@ -18,7 +18,7 @@ module RestMyCase
18
18
  attributes ||= {}
19
19
 
20
20
  unless attributes.respond_to?(:to_hash)
21
- raise ArgumentError.new('Must respond_to method #to_hash')
21
+ fail ArgumentError, 'Must respond_to method #to_hash'
22
22
  end
23
23
 
24
24
  TRIAL_COURT.execute([self], attributes.to_hash).context
@@ -72,15 +72,15 @@ module RestMyCase
72
72
  end
73
73
 
74
74
  def abort!
75
- abort && raise(Errors::Abort)
75
+ abort && fail(Errors::Abort)
76
76
  end
77
77
 
78
- def fail(message = '')
78
+ def error(message = '')
79
79
  abort && context.errors[self.class.name].push(message)
80
80
  end
81
81
 
82
- def fail!(message = '')
83
- fail(message) && raise(Errors::Abort)
82
+ def error!(message = '')
83
+ error(message) && fail(Errors::Abort)
84
84
  end
85
85
 
86
86
  def skip
@@ -88,7 +88,7 @@ module RestMyCase
88
88
  end
89
89
 
90
90
  def skip!
91
- skip && raise(Errors::Skip)
91
+ skip && fail(Errors::Skip)
92
92
  end
93
93
 
94
94
  protected ######################## PROTECTED ###############################
@@ -3,7 +3,7 @@ module RestMyCase
3
3
 
4
4
  class Base < OpenStruct
5
5
 
6
- alias :attributes :marshal_dump
6
+ alias_method :attributes, :marshal_dump
7
7
 
8
8
  include ActiveModel::Serialization if defined?(ActiveModel)
9
9
 
@@ -19,7 +19,7 @@ module RestMyCase
19
19
  errors.empty?
20
20
  end
21
21
 
22
- alias :ok? :valid?
22
+ alias_method :ok?, :valid?
23
23
 
24
24
  end
25
25
 
@@ -20,7 +20,7 @@ module RestMyCase
20
20
  return [] unless use_case_class.respond_to? :dependencies
21
21
 
22
22
  all_dependencies(use_case_class.superclass) |
23
- dependencies_including_itself_last(use_case_class, nil)
23
+ dependencies_including_itself_last(use_case_class, nil)
24
24
  end
25
25
 
26
26
  private ########################### PRIVATE ##############################
@@ -7,5 +7,7 @@ module RestMyCase
7
7
 
8
8
  class Abort < Base; end
9
9
 
10
+ class Error < Base; end
11
+
10
12
  end
11
13
  end
@@ -6,7 +6,7 @@ module RestMyCase
6
6
  def initialize(trial_case)
7
7
  @trial_case = trial_case
8
8
  @performed_use_cases = []
9
- @use_case_that_aborted = false
9
+ @use_case_that_aborted = nil
10
10
  end
11
11
 
12
12
  def determine_the_sentence
@@ -15,7 +15,7 @@ module RestMyCase
15
15
  run_rollback_methods
16
16
  run_final_methods
17
17
 
18
- @trial_case.aborted = !!@use_case_that_aborted
18
+ @trial_case.aborted = !@use_case_that_aborted.nil?
19
19
  end
20
20
 
21
21
  protected ######################## PROTECTED #############################
@@ -37,7 +37,7 @@ module RestMyCase
37
37
  def run_rollback_methods
38
38
  return nil unless @use_case_that_aborted
39
39
 
40
- @performed_use_cases.reverse.each do |use_case|
40
+ @performed_use_cases.reverse_each do |use_case|
41
41
  method_aborts?(:rollback, use_case)
42
42
  end
43
43
  end
@@ -63,15 +63,13 @@ module RestMyCase
63
63
  end
64
64
 
65
65
  def method_aborts?(method_name, use_case)
66
- begin
67
- use_case.send(method_name)
68
-
69
- use_case.options[:should_abort] && @use_case_that_aborted = use_case
70
- rescue Errors::Skip
71
- false
72
- rescue Errors::Abort
73
- @use_case_that_aborted = use_case
74
- end
66
+ use_case.send(method_name)
67
+
68
+ use_case.options[:should_abort] && @use_case_that_aborted = use_case
69
+ rescue Errors::Skip
70
+ false
71
+ rescue Errors::Abort
72
+ @use_case_that_aborted = use_case
75
73
  end
76
74
 
77
75
  end
@@ -1,7 +1,7 @@
1
1
  module RestMyCase
2
2
  module Trial
3
3
 
4
- class Court < Struct.new(:judge_class, :defense_attorney_class)
4
+ Court = Struct.new(:judge_class, :defense_attorney_class) do
5
5
 
6
6
  def execute(use_case_classes, attributes = {})
7
7
  trial_case = Case.new(use_case_classes, attributes)
@@ -1,8 +1,7 @@
1
1
  module RestMyCase
2
2
  module Trial
3
3
 
4
- class Defendant < Struct.new(:use_case_classes)
5
- end
4
+ Defendant = Struct.new(:use_case_classes)
6
5
 
7
6
  end
8
7
  end
@@ -1,5 +1,5 @@
1
1
  module RestMyCase
2
2
 
3
- VERSION = "1.5.0"
3
+ VERSION = '1.6.0'
4
4
 
5
5
  end
data/lib/rest_my_case.rb CHANGED
@@ -1,20 +1,20 @@
1
1
  require 'ostruct'
2
2
 
3
- require "rest_my_case/version"
4
- require "rest_my_case/errors"
3
+ require 'rest_my_case/version'
4
+ require 'rest_my_case/errors'
5
5
 
6
- require "rest_my_case/config/base"
7
- require "rest_my_case/config/general"
6
+ require 'rest_my_case/config/base'
7
+ require 'rest_my_case/config/general'
8
8
 
9
- require "rest_my_case/defense_attorney/base"
10
- require "rest_my_case/context/base"
11
- require "rest_my_case/judge/base"
9
+ require 'rest_my_case/defense_attorney/base'
10
+ require 'rest_my_case/context/base'
11
+ require 'rest_my_case/judge/base'
12
12
 
13
- require "rest_my_case/trial/defendant"
14
- require "rest_my_case/trial/case"
15
- require "rest_my_case/trial/court"
13
+ require 'rest_my_case/trial/defendant'
14
+ require 'rest_my_case/trial/case'
15
+ require 'rest_my_case/trial/court'
16
16
 
17
- require "rest_my_case/base"
17
+ require 'rest_my_case/base'
18
18
 
19
19
  module RestMyCase
20
20
 
data/rest_my_case.gemspec CHANGED
@@ -4,22 +4,24 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'rest_my_case/version'
5
5
 
6
6
  Gem::Specification.new do |gem|
7
- gem.name = "rest_my_case"
7
+ gem.name = 'rest_my_case'
8
8
  gem.version = RestMyCase::VERSION
9
- gem.authors = ["goncalvesjoao"]
10
- gem.email = ["goncalves.joao@gmail.com"]
9
+ gem.authors = ['goncalvesjoao']
10
+ gem.email = ['goncalves.joao@gmail.com']
11
11
  gem.summary = %q{Quick and light "The Clean Architecture" use case implementation.}
12
12
  gem.description = %q{Very light Ruby gem with everything you need in a "The Clean Architecture" use case scenario}
13
- gem.homepage = "https://github.com/goncalvesjoao/rest_my_case"
14
- gem.license = "MIT"
13
+ gem.homepage = 'https://github.com/goncalvesjoao/rest_my_case'
14
+ gem.license = 'MIT'
15
15
 
16
16
  gem.files = `git ls-files -z`.split("\x0")
17
17
  gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
- gem.require_paths = ["lib"]
19
+ gem.require_paths = ['lib']
20
20
 
21
- gem.add_development_dependency "pry", '~> 0.10'
22
- gem.add_development_dependency "rake", '~> 10.1'
23
- gem.add_development_dependency "rspec",'~> 3.2'
24
- gem.add_development_dependency "simplecov", '~> 0.9'
21
+ gem.add_development_dependency 'pry', '~> 0.10'
22
+ gem.add_development_dependency 'rake', '~> 10.1'
23
+ gem.add_development_dependency 'rspec', '~> 3.2'
24
+ gem.add_development_dependency 'rubocop', '~> 0.30'
25
+ gem.add_development_dependency 'simplecov', '~> 0.9'
26
+ gem.add_development_dependency 'codeclimate-test-reporter', '~> 0.4'
25
27
  end
@@ -96,10 +96,10 @@ describe RestMyCase::Base do
96
96
 
97
97
  end
98
98
 
99
- context "When a use case calls #fail during the setup process" do
99
+ context "When a use case calls #error during the setup process" do
100
100
  before do
101
101
  @context = Perform::CreatePost.perform \
102
- fail: ['Perform::ValidateName_setup', 'Perform::ValidateBody_setup']
102
+ error: ['Perform::ValidateName_setup', 'Perform::ValidateBody_setup']
103
103
  end
104
104
 
105
105
  it "context should reflect an invalid state" do
@@ -118,10 +118,10 @@ describe RestMyCase::Base do
118
118
  end
119
119
  end
120
120
 
121
- context "When a use case calls #fail! during the setup process" do
121
+ context "When a use case calls #error! during the setup process" do
122
122
  before do
123
123
  @context = Perform::CreatePost.perform \
124
- fail_bang: ['Perform::ValidateName_setup']
124
+ error_bang: ['Perform::ValidateName_setup']
125
125
  end
126
126
 
127
127
  it "context should reflect an invalid state" do
@@ -219,10 +219,10 @@ describe RestMyCase::Base do
219
219
  before { Perform::Validations.silence_dependencies_abort = true }
220
220
  after { Perform::Validations.silence_dependencies_abort = nil }
221
221
 
222
- context "When a use case calls #fail during the setup process" do
222
+ context "When a use case calls #error during the setup process" do
223
223
  before do
224
224
  @context = Perform::CreatePost.perform \
225
- fail: ['Perform::ValidateName_setup', 'Perform::ValidateBody_setup']
225
+ error: ['Perform::ValidateName_setup', 'Perform::ValidateBody_setup']
226
226
  end
227
227
 
228
228
  it "context should reflect an invalid state" do
@@ -242,11 +242,11 @@ describe RestMyCase::Base do
242
242
 
243
243
  end
244
244
 
245
- context "When a use case calls #fail during the perform process" do
245
+ context "When a use case calls #error during the perform process" do
246
246
 
247
247
  before do
248
248
  @context = Perform::CreatePost.perform \
249
- fail: ['Perform::ValidateName_perform', 'Perform::ValidateBody_perform']
249
+ error: ['Perform::ValidateName_perform', 'Perform::ValidateBody_perform']
250
250
  end
251
251
 
252
252
  it "context should reflect an invalid state" do
@@ -277,11 +277,11 @@ describe RestMyCase::Base do
277
277
  end
278
278
  after { RestMyCase.reset_config }
279
279
 
280
- context "When a use case calls #fail during the perform process" do
280
+ context "When a use case calls #error during the perform process" do
281
281
 
282
282
  before do
283
283
  @context = Perform::CreatePost.perform \
284
- fail: ['Perform::ValidateName_perform', 'Perform::ValidateBody_perform', 'Perform::BuildPost_perform', 'Perform::SavePost_perform']
284
+ error: ['Perform::ValidateName_perform', 'Perform::ValidateBody_perform', 'Perform::BuildPost_perform', 'Perform::SavePost_perform']
285
285
  end
286
286
 
287
287
  it "context should reflect an invalid state" do
@@ -396,7 +396,7 @@ describe RestMyCase::Base do
396
396
 
397
397
  before do
398
398
  @context = Perform::CreatePost2.perform \
399
- fail: ['Perform::ValidateName_perform', 'Perform::ValidateBody_perform']
399
+ error: ['Perform::ValidateName_perform', 'Perform::ValidateBody_perform']
400
400
  end
401
401
 
402
402
  it "invoker should abort the process it his invokees have also aborted" do
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,7 @@
1
+ require "codeclimate-test-reporter"
2
+
3
+ CodeClimate::TestReporter.start
4
+
1
5
  require "simplecov"
2
6
 
3
7
  SimpleCov.start do
@@ -4,8 +4,8 @@ module Perform
4
4
  def flow_control(method)
5
5
  id = "#{self.class.name}_#{method}"
6
6
 
7
- context.fail ||= []
8
- context.fail_bang ||= []
7
+ context.error ||= []
8
+ context.error_bang ||= []
9
9
  context.skip ||= []
10
10
  context.skip_bang ||= []
11
11
  context.abort ||= []
@@ -15,8 +15,8 @@ module Perform
15
15
  context.rollback ||= []
16
16
  context.final ||= []
17
17
 
18
- fail if context.fail.include? id
19
- fail! if context.fail_bang.include? id
18
+ error if context.error.include? id
19
+ error! if context.error_bang.include? id
20
20
  skip if context.skip.include? id
21
21
  skip! if context.skip_bang.include? id
22
22
  abort if context.abort.include? id
@@ -3,11 +3,11 @@ module RestMyCaseBase
3
3
  class BuildPost < RestMyCase::Base; end
4
4
 
5
5
  class ValidateName < RestMyCase::Base
6
- def perform; fail('no name present!'); end
6
+ def perform; error('no name present!'); end
7
7
  end
8
8
 
9
9
  class ValidateBody < RestMyCase::Base
10
- def perform; fail('no body present!'); end
10
+ def perform; error('no body present!'); end
11
11
  end
12
12
 
13
13
  class Validations < RestMyCase::Base
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest_my_case
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - goncalvesjoao
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.30'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.30'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: simplecov
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +80,20 @@ dependencies:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0.9'
83
+ - !ruby/object:Gem::Dependency
84
+ name: codeclimate-test-reporter
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.4'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.4'
69
97
  description: Very light Ruby gem with everything you need in a "The Clean Architecture"
70
98
  use case scenario
71
99
  email:
@@ -76,9 +104,10 @@ extra_rdoc_files: []
76
104
  files:
77
105
  - ".gitignore"
78
106
  - ".rspec"
107
+ - ".rubocop.yml"
108
+ - ".travis.yml"
79
109
  - Gemfile
80
110
  - LICENSE
81
- - LICENSE.txt
82
111
  - README.md
83
112
  - Rakefile
84
113
  - console
data/LICENSE.txt DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2015 goncalvesjoao
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.