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 +4 -4
- data/.rubocop.yml +30 -0
- data/.travis.yml +13 -0
- data/LICENSE +1 -1
- data/README.md +4 -2
- data/Rakefile +5 -0
- data/console +0 -3
- data/lib/rest_my_case/base.rb +7 -7
- data/lib/rest_my_case/context/base.rb +2 -2
- data/lib/rest_my_case/defense_attorney/base.rb +1 -1
- data/lib/rest_my_case/errors.rb +2 -0
- data/lib/rest_my_case/judge/base.rb +10 -12
- data/lib/rest_my_case/trial/court.rb +1 -1
- data/lib/rest_my_case/trial/defendant.rb +1 -2
- data/lib/rest_my_case/version.rb +1 -1
- data/lib/rest_my_case.rb +11 -11
- data/rest_my_case.gemspec +12 -10
- data/spec/rest_my_case/base_spec.rb +11 -11
- data/spec/spec_helper.rb +4 -0
- data/spec/support/perform.rb +4 -4
- data/spec/support/rest_my_case_base.rb +2 -2
- metadata +31 -2
- data/LICENSE.txt +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d82932cb42f7f06eaa0a2ffd09fc866ae7217047
|
4
|
+
data.tar.gz: 35df440b5058dde4f650d7cc20a1f4f116c9c45f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
data/README.md
CHANGED
@@ -1,2 +1,4 @@
|
|
1
|
-
# RestMyCase
|
2
|
-
|
1
|
+
# RestMyCase [](https://codeclimate.com/github/goncalvesjoao/rest_my_case) [](https://travis-ci.org/goncalvesjoao/rest_my_case) [](https://codeclimate.com/github/goncalvesjoao/rest_my_case) [](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
data/console
CHANGED
data/lib/rest_my_case/base.rb
CHANGED
@@ -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
|
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
|
-
|
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 &&
|
75
|
+
abort && fail(Errors::Abort)
|
76
76
|
end
|
77
77
|
|
78
|
-
def
|
78
|
+
def error(message = '')
|
79
79
|
abort && context.errors[self.class.name].push(message)
|
80
80
|
end
|
81
81
|
|
82
|
-
def
|
83
|
-
|
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 &&
|
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
|
-
|
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
|
-
|
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
|
-
|
23
|
+
dependencies_including_itself_last(use_case_class, nil)
|
24
24
|
end
|
25
25
|
|
26
26
|
private ########################### PRIVATE ##############################
|
data/lib/rest_my_case/errors.rb
CHANGED
@@ -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 =
|
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 =
|
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.
|
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
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
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
|
-
|
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)
|
data/lib/rest_my_case/version.rb
CHANGED
data/lib/rest_my_case.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
require 'ostruct'
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'rest_my_case/version'
|
4
|
+
require 'rest_my_case/errors'
|
5
5
|
|
6
|
-
require
|
7
|
-
require
|
6
|
+
require 'rest_my_case/config/base'
|
7
|
+
require 'rest_my_case/config/general'
|
8
8
|
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
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
|
14
|
-
require
|
15
|
-
require
|
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
|
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 =
|
7
|
+
gem.name = 'rest_my_case'
|
8
8
|
gem.version = RestMyCase::VERSION
|
9
|
-
gem.authors = [
|
10
|
-
gem.email = [
|
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 =
|
14
|
-
gem.license =
|
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 = [
|
19
|
+
gem.require_paths = ['lib']
|
20
20
|
|
21
|
-
gem.add_development_dependency
|
22
|
-
gem.add_development_dependency
|
23
|
-
gem.add_development_dependency
|
24
|
-
gem.add_development_dependency
|
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 #
|
99
|
+
context "When a use case calls #error during the setup process" do
|
100
100
|
before do
|
101
101
|
@context = Perform::CreatePost.perform \
|
102
|
-
|
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 #
|
121
|
+
context "When a use case calls #error! during the setup process" do
|
122
122
|
before do
|
123
123
|
@context = Perform::CreatePost.perform \
|
124
|
-
|
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 #
|
222
|
+
context "When a use case calls #error during the setup process" do
|
223
223
|
before do
|
224
224
|
@context = Perform::CreatePost.perform \
|
225
|
-
|
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 #
|
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
|
-
|
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 #
|
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
|
-
|
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
|
-
|
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
data/spec/support/perform.rb
CHANGED
@@ -4,8 +4,8 @@ module Perform
|
|
4
4
|
def flow_control(method)
|
5
5
|
id = "#{self.class.name}_#{method}"
|
6
6
|
|
7
|
-
context.
|
8
|
-
context.
|
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
|
-
|
19
|
-
|
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;
|
6
|
+
def perform; error('no name present!'); end
|
7
7
|
end
|
8
8
|
|
9
9
|
class ValidateBody < RestMyCase::Base
|
10
|
-
def perform;
|
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.
|
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.
|