rest_my_case 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c970f203b3b22d52c6722769641cbb473816fd0
4
- data.tar.gz: 0a8078be8d6ed74ff5c8107eb647f19d4db96090
3
+ metadata.gz: 24f1ea66d95ea0375eb3a27f226eacd76f615c18
4
+ data.tar.gz: aaff479de083593b50440e49c84cf68e3911a2ec
5
5
  SHA512:
6
- metadata.gz: c3cbe0da32ebd73ffe647b19e984ed60bc2ee1782bade92ad35172fedf2e20ce460f55b79195625b8e5133ce1271a05847ea69f5952aa2aebfdd016f7f83f01b
7
- data.tar.gz: 899768ca4c9a86720102ce5eadd60d7e957fd32cfd7551dcc22f2f2ee62b4c771a8d2856d4091713c3a8d85584a0fe3ca93efc73b7a0d307afa8660546d77519
6
+ metadata.gz: 0ee5095a6139908f84ebf44c9e1e665f84dc794a43d08432813cfec5aaedb7de233515f7e64a9eee482f15a5f28002aceb14cba0d39123316c183437903095af
7
+ data.tar.gz: 0afb19fa366ac967335d80b7bcfe054b1deffaacfb064a00b296e7345d41f59bb7d239998bbb95506226c78ab43815aae0e040e88da7465d77eb8f59fec684d9
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --tty
2
+ --color
3
+ --format documentation
4
+ --format html -o "tmp/rspec_result.html"
data/README.md CHANGED
@@ -1,2 +1,2 @@
1
- # rest_my_case
2
- Quick and light "The Clean Architecture" use case implementation
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,35 +1,51 @@
1
+ require "rest_my_case/judges/base"
2
+
1
3
  module RestMyCase
2
4
 
3
5
  class Base
4
6
 
5
7
  def self.depends(*use_cases)
6
- local_dependencies.push *use_cases
7
- end
8
-
9
- # List of use case classes that the current class depends on
10
- def self.local_dependencies
11
- @local_dependencies ||= []
8
+ dependencies.push *use_cases
12
9
  end
13
10
 
14
- # List of use cases that the current class depends on, plus its parent class
15
- # This list will be used during .perform
16
11
  def self.dependencies
17
- local_dependencies.concat superclass.dependencies
12
+ @dependencies ||= []
18
13
  end
19
14
 
20
15
  def self.perform(attributes = {})
21
- Judge.execute_the_sentence self, Context.new(attributes)
16
+ unless attributes.respond_to?(:to_hash)
17
+ raise ArgumentError.new('Must respond_to method #to_hash')
18
+ end
19
+
20
+ Judges::Base.execute_the_sentence(self, attributes.to_hash)
21
+ end
22
+
23
+ def self.context_accessor(*methods)
24
+ context_writer(*methods)
25
+ context_reader(*methods)
26
+ end
27
+
28
+ def self.context_writer(*methods)
29
+ methods.each do |method|
30
+ define_method("#{method}=") { |value| context.send "#{method}=", value }
31
+ end
22
32
  end
23
33
 
34
+ def self.context_reader(*methods)
35
+ methods.each { |method| define_method(method) { context.send(method) } }
36
+ end
37
+
38
+ ##################### INSTANCE METHODS BELLOW ###################
39
+
24
40
  attr_reader :context, :should_abort, :should_skip
25
41
 
26
42
  def initialize(context)
27
- @context = context
28
-
29
- @should_abort = @should_skip = false
43
+ @context = context
44
+ @should_skip = false
45
+ @should_abort = false
30
46
  end
31
47
 
32
- def before; end
48
+ def setup; end
33
49
 
34
50
  def perform; end
35
51
 
@@ -37,44 +53,28 @@ module RestMyCase
37
53
 
38
54
  def final; end
39
55
 
40
- # Calls #abort and populates the context's errors
41
56
  def fail(message = '')
42
- abort
43
-
44
- @context.errors[self.class.name].push message
57
+ abort && @context.errors[self.class.name].push(message)
45
58
  end
46
59
 
47
- # Calls #fail and also prevents the next line of code to be ran
48
60
  def fail!(message = '')
49
- fail message
50
-
51
- raise Errors::Abort
61
+ fail(message) && raise(Errors::Abort)
52
62
  end
53
63
 
54
- # Prevents the next use case to be ran and will trigger the rollback process
55
64
  def abort
56
65
  @should_abort = true
57
66
  end
58
67
 
59
- # Calls #abort and prevents the next line of code to be ran
60
68
  def abort!
61
- abort
62
-
63
- raise Errors::Abort
69
+ abort && raise(Errors::Abort)
64
70
  end
65
71
 
66
- # To be used during the #before method:
67
- # Prevents the current use case to be
68
- # ran (during perform), but not the next ones
69
72
  def skip
70
73
  @should_skip = true
71
74
  end
72
75
 
73
- # Calls #skip and prevents the next line of code to be ran
74
76
  def skip!
75
- skip
76
-
77
- raise Errors::Skip
77
+ skip && raise(Errors::Skip)
78
78
  end
79
79
 
80
80
  end
@@ -0,0 +1,13 @@
1
+ module RestMyCase
2
+
3
+ class Configuration
4
+
5
+ attr_accessor :parent_dependencies_first
6
+
7
+ def initialize
8
+ @parent_dependencies_first = false
9
+ end
10
+
11
+ end
12
+
13
+ end
@@ -1,23 +1,19 @@
1
+ require 'ostruct'
2
+
1
3
  module RestMyCase
2
4
 
3
5
  class Context < OpenStruct
4
6
 
5
- attr_reader :errors
6
-
7
- def initialize(attributes)
8
- if !attributes.is_a?(::Hash) && !attributes.is_a?(Context)
9
- raise ArgumentError.new('Must be a Hash or Context')
10
- end
11
-
12
- super Helpers.stringify_keys(attributes)
13
-
14
- @errors = Hash.new { |hash, key| hash[key] = [] }
7
+ def errors
8
+ @errors ||= Hash.new { |hash, key| hash[key] = [] }
15
9
  end
16
10
 
17
11
  def valid?
18
- @errors.empty?
12
+ errors.empty?
19
13
  end
20
14
 
15
+ alias :ok? :valid?
16
+
21
17
  def serializable_hash(options = nil)
22
18
  marshal_dump
23
19
  end
@@ -1,11 +1,32 @@
1
+ require "rest_my_case/context"
2
+
1
3
  module RestMyCase
2
4
 
3
5
  module DefenseAttorney
4
6
 
5
- extend self
7
+ def self.build_use_cases_for_the(defendant, attributes)
8
+ shared_context = Context.new attributes
9
+
10
+ dependencies(defendant).map do |use_case|
11
+ use_case.new(shared_context)
12
+ end
13
+ end
14
+
15
+ def self.dependencies(use_case)
16
+ return [] unless use_case.respond_to?(:dependencies)
17
+
18
+ if parent_dependencies_first?(use_case)
19
+ dependencies(use_case.superclass) | use_case.dependencies
20
+ else
21
+ use_case.dependencies | dependencies(use_case.superclass)
22
+ end
23
+ end
6
24
 
7
- def build_use_cases_for_the(defendant, context)
25
+ protected ###################### PROTECTED #########################
8
26
 
27
+ def self.parent_dependencies_first?(use_case)
28
+ # use_case.parent_dependencies_first ||
29
+ RestMyCase.configuration.parent_dependencies_first
9
30
  end
10
31
 
11
32
  end
@@ -0,0 +1,86 @@
1
+ require "rest_my_case/defense_attorney"
2
+
3
+ module RestMyCase
4
+ module Judges
5
+
6
+ class Base
7
+
8
+ def self.execute_the_sentence(defendant, attributes)
9
+ new_trial = self.new(defendant, attributes)
10
+
11
+ new_trial.run_setup_methods
12
+ new_trial.run_perform_methods
13
+ new_trial.run_rollback_methods
14
+ new_trial.run_final_methods
15
+ end
16
+
17
+ def initialize(defendant, attributes)
18
+ @use_cases =
19
+ DefenseAttorney.build_use_cases_for_the(defendant, attributes)
20
+
21
+ @performed_use_cases = []
22
+ @use_case_that_aborted = false
23
+ end
24
+
25
+ protected #################### PROTECTED ####################
26
+
27
+ def run_setup_methods
28
+ @use_cases.each do |use_case|
29
+ break if method_setup_has_aborted use_case
30
+ end
31
+ end
32
+
33
+ def run_perform_methods
34
+ return nil if @use_case_that_aborted
35
+
36
+ @use_cases.each do |use_case|
37
+ break if method_perform_has_aborted use_case
38
+ end
39
+ end
40
+
41
+ def run_rollback_methods
42
+ return nil unless @use_case_that_aborted
43
+
44
+ @performed_use_cases.revert.each do |use_case|
45
+ run_method(:rollback, use_case)
46
+ end
47
+ end
48
+
49
+ def run_final_methods
50
+ @use_cases.each { |use_case| run_method(:final, use_case) }
51
+ end
52
+
53
+ private #################### PRIVATE ######################
54
+
55
+ def method_setup_has_aborted(use_case)
56
+ method_aborts?(:setup, use_case)
57
+ end
58
+
59
+ def method_perform_has_aborted(use_case)
60
+ return false if use_case.should_skip
61
+
62
+ @performed_use_cases.push use_case
63
+
64
+ method_aborts?(:perform, use_case)
65
+ end
66
+
67
+ def method_aborts?(method_name, use_case)
68
+ begin
69
+ run_method(method_name, use_case)
70
+
71
+ use_case.should_abort
72
+ rescue Errors::Skip => exception
73
+ false
74
+ rescue Errors::Abort => exception
75
+ @use_case_that_aborted = use_case
76
+ end
77
+ end
78
+
79
+ def run_method(method_name, use_case)
80
+ use_case.send(method_name)
81
+ end
82
+
83
+ end
84
+
85
+ end
86
+ end
@@ -1,3 +1,3 @@
1
1
  module RestMyCase
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
data/lib/rest_my_case.rb CHANGED
@@ -1,7 +1,24 @@
1
+ require "rest_my_case/configuration"
1
2
  require "rest_my_case/version"
2
- require "rest_my_case/context"
3
3
  require "rest_my_case/errors"
4
- require "rest_my_case/judge"
5
4
  require "rest_my_case/base"
6
5
 
7
- module RestMyCase; end
6
+ module RestMyCase
7
+
8
+ def self.configure(&block)
9
+ yield(Config)
10
+ end
11
+
12
+ def self.configure
13
+ yield configuration
14
+ end
15
+
16
+ def self.configuration
17
+ @configuration ||= Configuration.new
18
+ end
19
+
20
+ def self.reset_configuration
21
+ @configuration = Configuration.new
22
+ end
23
+
24
+ end
data/rest_my_case.gemspec CHANGED
@@ -3,21 +3,23 @@ lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'rest_my_case/version'
5
5
 
6
- Gem::Specification.new do |spec|
7
- spec.name = "rest_my_case"
8
- spec.version = RestMyCase::VERSION
9
- spec.authors = ["goncalvesjoao"]
10
- spec.email = ["goncalves.joao@gmail.com"]
11
- spec.summary = %q{Quick and light "The Clean Architecture" use case implementation.}
12
- spec.description = %q{Very light Ruby gem with everything you need in a "The Clean Architecture" use case scenario}
13
- spec.homepage = "https://github.com/goncalvesjoao/rest_my_case"
14
- spec.license = "MIT"
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "rest_my_case"
8
+ gem.version = RestMyCase::VERSION
9
+ gem.authors = ["goncalvesjoao"]
10
+ gem.email = ["goncalves.joao@gmail.com"]
11
+ gem.summary = %q{Quick and light "The Clean Architecture" use case implementation.}
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"
15
15
 
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
16
+ gem.files = `git ls-files -z`.split("\x0")
17
+ gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.7"
22
- spec.add_development_dependency "rake", "~> 10.0"
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'
23
25
  end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe RestMyCase::Base do
4
+
5
+ context "When a use case depends on other use cases" do
6
+
7
+ it ".dependencies should list the class's dependencies" do
8
+ expect(Posts::Create::Base.dependencies).to \
9
+ eq [Posts::Create::BuildPost, Posts::SavePost]
10
+ end
11
+
12
+ end
13
+
14
+ context "When a use case inherits from another that also has its own dependencies" do
15
+
16
+ it ".dependencies should only list the class's dependencies" do
17
+ expect(Comments::Create::SendEmail.dependencies).to eq [Comments::FindOne]
18
+ end
19
+
20
+ end
21
+
22
+ describe ".context_accessor" do
23
+
24
+ let(:context) { RestMyCase::Context.new(id: 1, comment: 'my comment', session: -1) }
25
+ let(:use_case) { Comments::FindOne.new(context) }
26
+
27
+ it "Should create getters targeting to context" do
28
+ expect(use_case.respond_to?(:comment)).to be true
29
+ end
30
+
31
+ it "Should create setters targeting to context" do
32
+ expect(use_case.respond_to?(:comment=)).to be true
33
+ end
34
+
35
+ it "Getter should delegate to context" do
36
+ expect(use_case.comment).to eq context.comment
37
+ end
38
+
39
+ it "Setter should delegate to context" do
40
+ use_case.comment = 'your comment'
41
+ expect(use_case.context.comment).to eq 'your comment'
42
+ end
43
+
44
+ end
45
+
46
+ describe ".context_writer" do
47
+
48
+ let(:use_case) { Comments::FindOne.new(RestMyCase::Context.new) }
49
+
50
+ it "Should create setters targeting to context" do
51
+ expect(use_case.respond_to?(:id)).to be false
52
+ expect(use_case.respond_to?(:id=)).to be true
53
+ end
54
+
55
+ it "Setter should delegate to context" do
56
+ use_case.id = 2
57
+
58
+ expect(use_case.context.id).to eq 2
59
+ end
60
+
61
+ end
62
+
63
+ describe ".context_reader" do
64
+
65
+ let(:context) { RestMyCase::Context.new(id: 1, comment: 'my comment', session: -1) }
66
+ let(:use_case) { Comments::FindOne.new(context) }
67
+
68
+ it "Should create getters targeting to context" do
69
+ expect(use_case.respond_to?(:session)).to be true
70
+ expect(use_case.respond_to?(:session=)).to be false
71
+ end
72
+
73
+ it "Getter should delegate to context" do
74
+ expect(use_case.session).to eq context.session
75
+ end
76
+
77
+ end
78
+
79
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe RestMyCase::DefenseAttorney do
4
+
5
+ describe ".dependencies" do
6
+
7
+ context "When a use case depends on other use cases" do
8
+
9
+ let(:use_cases) do
10
+ RestMyCase::DefenseAttorney.dependencies Posts::Create::Base
11
+ end
12
+
13
+ it "use_cases should be in the proper order" do
14
+ expect(use_cases).to eq [Posts::Create::BuildPost, Posts::SavePost]
15
+ end
16
+
17
+ end
18
+
19
+ context "When a use case depends on other use cases" do
20
+
21
+ let(:use_cases) do
22
+ RestMyCase::DefenseAttorney.dependencies Comments::Create::SendEmail
23
+ end
24
+
25
+ it "use_cases should be in the proper order" do
26
+ expect(use_cases).to \
27
+ eq [Comments::FindOne, SendEmail::ToAdmins, SendEmail::ToUser, SendEmail::OneMoreDependency]
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+
34
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe RestMyCase::Judges::Base do
4
+
5
+ describe "#build_use_cases_for_the_defendant" do
6
+
7
+ # context "When a use case depends on other use cases" do
8
+ # before { @result = defense_attorney.build_use_cases_for_the_defendant }
9
+ # let(:attributes) { { id: 1, comment: 'my comment', session: -1 } }
10
+ # let(:defense_attorney) do
11
+ # RestMyCase::DefenseAttorney.new(Comments::Create::Base, attributes)
12
+ # end
13
+
14
+ # it "Should instanciate 3 objects" do
15
+ # expect(@result.length).to be 3
16
+ # end
17
+
18
+ # it "dass" do
19
+ # expect(@result[0]).to be_a Comments::Create::BuildComment
20
+ # expect(@result[1]).to be_a Comments::SaveComment
21
+ # expect(@result[2]).to be_a Comments::Create::SendEmail
22
+ # end
23
+
24
+ # end
25
+
26
+ end
27
+
28
+ end
@@ -0,0 +1,21 @@
1
+ require "simplecov"
2
+
3
+ SimpleCov.start do
4
+ root("lib/")
5
+ coverage_dir("../tmp/coverage/")
6
+ end
7
+
8
+ require 'pry'
9
+ require 'rest_my_case'
10
+ $: << File.expand_path('../', File.dirname(__FILE__))
11
+
12
+ Dir["./spec/**/support/**/*.rb"].each do |file|
13
+ require file
14
+ end
15
+
16
+ RSpec.configure do |config|
17
+ config.run_all_when_everything_filtered = true
18
+ config.filter_run :focus
19
+
20
+ config.order = 'random'
21
+ end
@@ -0,0 +1,14 @@
1
+ require_relative 'use_case'
2
+ require_relative 'to_admins'
3
+ require_relative 'to_user'
4
+
5
+ module SendEmail
6
+
7
+ class Base < UseCase
8
+
9
+ depends ToAdmins,
10
+ ToUser
11
+
12
+ end
13
+
14
+ end
@@ -0,0 +1,6 @@
1
+ module SendEmail
2
+
3
+ class FetchAdmins < RestMyCase::Base
4
+ end
5
+
6
+ end
@@ -0,0 +1,6 @@
1
+ module SendEmail
2
+
3
+ class OneMoreDependency < RestMyCase::Base
4
+ end
5
+
6
+ end
@@ -0,0 +1,11 @@
1
+ require_relative 'fetch_admins'
2
+
3
+ module SendEmail
4
+
5
+ class ToAdmins < RestMyCase::Base
6
+
7
+ depends FetchAdmins
8
+
9
+ end
10
+
11
+ end
@@ -0,0 +1,6 @@
1
+ module SendEmail
2
+
3
+ class ToUser < RestMyCase::Base
4
+ end
5
+
6
+ end
@@ -0,0 +1,11 @@
1
+ require_relative 'one_more_dependency'
2
+
3
+ module SendEmail
4
+
5
+ class UseCase < RestMyCase::Base
6
+
7
+ depends OneMoreDependency
8
+
9
+ end
10
+
11
+ end
@@ -0,0 +1,18 @@
1
+ require_relative '../use_case'
2
+ require_relative 'build_comment'
3
+ require_relative 'send_email'
4
+ require_relative '../save_comment'
5
+
6
+ module Comments
7
+ module Create
8
+
9
+ class Base < UseCase
10
+
11
+ depends BuildComment,
12
+ SaveComment,
13
+ SendEmail
14
+
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,8 @@
1
+ module Comments
2
+ module Create
3
+
4
+ class BuildComment < UseCase
5
+ end
6
+
7
+ end
8
+ end
@@ -0,0 +1,13 @@
1
+ require_relative '../find_one'
2
+
3
+ module Comments
4
+ module Create
5
+
6
+ class SendEmail < ::SendEmail::Base
7
+
8
+ depends FindOne
9
+
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,8 @@
1
+ require_relative 'use_case'
2
+
3
+ module Comments
4
+
5
+ class FindOne < UseCase
6
+ end
7
+
8
+ end
@@ -0,0 +1,6 @@
1
+ module Comments
2
+
3
+ class SaveComment < UseCase
4
+ end
5
+
6
+ end
@@ -0,0 +1,11 @@
1
+ module Comments
2
+
3
+ class UseCase < RestMyCase::Base
4
+
5
+ context_writer :id
6
+ context_reader :session
7
+ context_accessor :comment
8
+
9
+ end
10
+
11
+ end
@@ -0,0 +1,16 @@
1
+ require_relative '../use_case'
2
+ require_relative 'build_post'
3
+ require_relative '../save_post'
4
+
5
+ module Posts
6
+ module Create
7
+
8
+ class Base < UseCase
9
+
10
+ depends BuildPost,
11
+ SavePost
12
+
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,8 @@
1
+ module Posts
2
+ module Create
3
+
4
+ class BuildPost < UseCase
5
+ end
6
+
7
+ end
8
+ end
@@ -0,0 +1,6 @@
1
+ module Posts
2
+
3
+ class SavePost < UseCase
4
+ end
5
+
6
+ end
@@ -0,0 +1,6 @@
1
+ module Posts
2
+
3
+ class UseCase < RestMyCase::Base
4
+ end
5
+
6
+ end
metadata CHANGED
@@ -1,43 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest_my_case
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - goncalvesjoao
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-10 00:00:00.000000000 Z
11
+ date: 2015-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: pry
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.7'
19
+ version: '0.10'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.7'
26
+ version: '0.10'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '10.1'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '10.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.9'
41
69
  description: Very light Ruby gem with everything you need in a "The Clean Architecture"
42
70
  use case scenario
43
71
  email:
@@ -47,6 +75,7 @@ extensions: []
47
75
  extra_rdoc_files: []
48
76
  files:
49
77
  - ".gitignore"
78
+ - ".rspec"
50
79
  - Gemfile
51
80
  - LICENSE
52
81
  - LICENSE.txt
@@ -54,13 +83,33 @@ files:
54
83
  - Rakefile
55
84
  - lib/rest_my_case.rb
56
85
  - lib/rest_my_case/base.rb
86
+ - lib/rest_my_case/configuration.rb
57
87
  - lib/rest_my_case/context.rb
58
88
  - lib/rest_my_case/defense_attorney.rb
59
89
  - lib/rest_my_case/errors.rb
60
- - lib/rest_my_case/helpers.rb
61
- - lib/rest_my_case/judge.rb
90
+ - lib/rest_my_case/judges/base.rb
62
91
  - lib/rest_my_case/version.rb
63
92
  - rest_my_case.gemspec
93
+ - spec/rest_my_case/base_spec.rb
94
+ - spec/rest_my_case/defense_attorney_spec.rb
95
+ - spec/rest_my_case/judges/base_spec.rb
96
+ - spec/spec_helper.rb
97
+ - spec/support/_send_email/base.rb
98
+ - spec/support/_send_email/fetch_admins.rb
99
+ - spec/support/_send_email/one_more_dependency.rb
100
+ - spec/support/_send_email/to_admins.rb
101
+ - spec/support/_send_email/to_user.rb
102
+ - spec/support/_send_email/use_case.rb
103
+ - spec/support/comments/create/base.rb
104
+ - spec/support/comments/create/build_comment.rb
105
+ - spec/support/comments/create/send_email.rb
106
+ - spec/support/comments/find_one.rb
107
+ - spec/support/comments/save_comment.rb
108
+ - spec/support/comments/use_case.rb
109
+ - spec/support/posts/create/base.rb
110
+ - spec/support/posts/create/build_post.rb
111
+ - spec/support/posts/save_post.rb
112
+ - spec/support/posts/use_case.rb
64
113
  homepage: https://github.com/goncalvesjoao/rest_my_case
65
114
  licenses:
66
115
  - MIT
@@ -85,4 +134,24 @@ rubygems_version: 2.4.2
85
134
  signing_key:
86
135
  specification_version: 4
87
136
  summary: Quick and light "The Clean Architecture" use case implementation.
88
- test_files: []
137
+ test_files:
138
+ - spec/rest_my_case/base_spec.rb
139
+ - spec/rest_my_case/defense_attorney_spec.rb
140
+ - spec/rest_my_case/judges/base_spec.rb
141
+ - spec/spec_helper.rb
142
+ - spec/support/_send_email/base.rb
143
+ - spec/support/_send_email/fetch_admins.rb
144
+ - spec/support/_send_email/one_more_dependency.rb
145
+ - spec/support/_send_email/to_admins.rb
146
+ - spec/support/_send_email/to_user.rb
147
+ - spec/support/_send_email/use_case.rb
148
+ - spec/support/comments/create/base.rb
149
+ - spec/support/comments/create/build_comment.rb
150
+ - spec/support/comments/create/send_email.rb
151
+ - spec/support/comments/find_one.rb
152
+ - spec/support/comments/save_comment.rb
153
+ - spec/support/comments/use_case.rb
154
+ - spec/support/posts/create/base.rb
155
+ - spec/support/posts/create/build_post.rb
156
+ - spec/support/posts/save_post.rb
157
+ - spec/support/posts/use_case.rb
@@ -1,11 +0,0 @@
1
- module RestMyCase
2
-
3
- module Helpers
4
-
5
- def self.stringify_keys(attributes)
6
- attributes.to_hash
7
- end
8
-
9
- end
10
-
11
- end
@@ -1,70 +0,0 @@
1
- require "rest_my_case/defense_attorney"
2
-
3
- module RestMyCase
4
-
5
- module Judge
6
-
7
- extend self
8
-
9
- def execute_the_sentence(defendant, context)
10
- @use_case_that_aborted = false
11
-
12
- @use_cases = DefenseAttorney.build_use_cases_for_the defendant, context
13
-
14
- run_before_methods
15
-
16
- run_perform_methods
17
-
18
- run_rollback_methods
19
-
20
- run_final_methods
21
- end
22
-
23
- protected #################### PROTECTED ####################
24
-
25
- def run_before_methods
26
- @use_cases.each do |use_case|
27
- break if run_method(:before, use_case) == 'abort'
28
- end
29
- end
30
-
31
- def run_perform_methods
32
- return nil if @use_case_that_aborted
33
-
34
- @use_cases.each do |use_case|
35
- break if run_method(:perform, use_case) == 'abort'
36
- end
37
- end
38
-
39
- def run_rollback_methods
40
- return nil unless @use_case_that_aborted
41
-
42
- # Revert the list, remove all use cases until you find
43
- # the use_case_that_aborted and run .map(&:rollback)
44
- # on the remaining elements
45
- end
46
-
47
- def run_final_methods
48
- @use_cases.map(&:final)
49
- end
50
-
51
- private #################### PRIVATE ######################
52
-
53
- def run_method(method_name, use_case)
54
- begin
55
- return 'skip' if use_case.should_skip
56
-
57
- use_case.send(method_name)
58
-
59
- use_case.should_abort ? 'abort' : 'ok'
60
- rescue Errors::Skip => exception
61
- 'skip'
62
- rescue Errors::Abort => exception
63
- @use_case_that_aborted = use_case
64
- 'abort'
65
- end
66
- end
67
-
68
- end
69
-
70
- end