rest_my_case 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +41 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/LICENSE.txt +22 -0
- data/README.md +2 -0
- data/Rakefile +2 -0
- data/lib/rest_my_case/base.rb +82 -0
- data/lib/rest_my_case/context.rb +29 -0
- data/lib/rest_my_case/defense_attorney.rb +13 -0
- data/lib/rest_my_case/errors.rb +11 -0
- data/lib/rest_my_case/helpers.rb +11 -0
- data/lib/rest_my_case/judge.rb +70 -0
- data/lib/rest_my_case/version.rb +3 -0
- data/lib/rest_my_case.rb +7 -0
- data/rest_my_case.gemspec +23 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4c970f203b3b22d52c6722769641cbb473816fd0
|
4
|
+
data.tar.gz: 0a8078be8d6ed74ff5c8107eb647f19d4db96090
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c3cbe0da32ebd73ffe647b19e984ed60bc2ee1782bade92ad35172fedf2e20ce460f55b79195625b8e5133ce1271a05847ea69f5952aa2aebfdd016f7f83f01b
|
7
|
+
data.tar.gz: 899768ca4c9a86720102ce5eadd60d7e957fd32cfd7551dcc22f2f2ee62b4c771a8d2856d4091713c3a8d85584a0fe3ca93efc73b7a0d307afa8660546d77519
|
data/.gitignore
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/vendor/bundle
|
26
|
+
/lib/bundler/man/
|
27
|
+
|
28
|
+
# for a library or gem, you might want to ignore these files since the code is
|
29
|
+
# intended to run in multiple environments; otherwise, check them in:
|
30
|
+
Gemfile.lock
|
31
|
+
.ruby-version
|
32
|
+
.ruby-gemset
|
33
|
+
|
34
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
35
|
+
.rvmrc
|
36
|
+
|
37
|
+
*.bundle
|
38
|
+
*.so
|
39
|
+
*.o
|
40
|
+
*.a
|
41
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 João
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
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.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
module RestMyCase
|
2
|
+
|
3
|
+
class Base
|
4
|
+
|
5
|
+
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 ||= []
|
12
|
+
end
|
13
|
+
|
14
|
+
# List of use cases that the current class depends on, plus its parent class
|
15
|
+
# This list will be used during .perform
|
16
|
+
def self.dependencies
|
17
|
+
local_dependencies.concat superclass.dependencies
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.perform(attributes = {})
|
21
|
+
Judge.execute_the_sentence self, Context.new(attributes)
|
22
|
+
end
|
23
|
+
|
24
|
+
attr_reader :context, :should_abort, :should_skip
|
25
|
+
|
26
|
+
def initialize(context)
|
27
|
+
@context = context
|
28
|
+
|
29
|
+
@should_abort = @should_skip = false
|
30
|
+
end
|
31
|
+
|
32
|
+
def before; end
|
33
|
+
|
34
|
+
def perform; end
|
35
|
+
|
36
|
+
def rollback; end
|
37
|
+
|
38
|
+
def final; end
|
39
|
+
|
40
|
+
# Calls #abort and populates the context's errors
|
41
|
+
def fail(message = '')
|
42
|
+
abort
|
43
|
+
|
44
|
+
@context.errors[self.class.name].push message
|
45
|
+
end
|
46
|
+
|
47
|
+
# Calls #fail and also prevents the next line of code to be ran
|
48
|
+
def fail!(message = '')
|
49
|
+
fail message
|
50
|
+
|
51
|
+
raise Errors::Abort
|
52
|
+
end
|
53
|
+
|
54
|
+
# Prevents the next use case to be ran and will trigger the rollback process
|
55
|
+
def abort
|
56
|
+
@should_abort = true
|
57
|
+
end
|
58
|
+
|
59
|
+
# Calls #abort and prevents the next line of code to be ran
|
60
|
+
def abort!
|
61
|
+
abort
|
62
|
+
|
63
|
+
raise Errors::Abort
|
64
|
+
end
|
65
|
+
|
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
|
+
def skip
|
70
|
+
@should_skip = true
|
71
|
+
end
|
72
|
+
|
73
|
+
# Calls #skip and prevents the next line of code to be ran
|
74
|
+
def skip!
|
75
|
+
skip
|
76
|
+
|
77
|
+
raise Errors::Skip
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module RestMyCase
|
2
|
+
|
3
|
+
class Context < OpenStruct
|
4
|
+
|
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] = [] }
|
15
|
+
end
|
16
|
+
|
17
|
+
def valid?
|
18
|
+
@errors.empty?
|
19
|
+
end
|
20
|
+
|
21
|
+
def serializable_hash(options = nil)
|
22
|
+
marshal_dump
|
23
|
+
end
|
24
|
+
|
25
|
+
alias :to_hash :serializable_hash
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,70 @@
|
|
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
|
data/lib/rest_my_case.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rest_my_case/version'
|
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"
|
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"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rest_my_case
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- goncalvesjoao
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Very light Ruby gem with everything you need in a "The Clean Architecture"
|
42
|
+
use case scenario
|
43
|
+
email:
|
44
|
+
- goncalves.joao@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- lib/rest_my_case.rb
|
56
|
+
- lib/rest_my_case/base.rb
|
57
|
+
- lib/rest_my_case/context.rb
|
58
|
+
- lib/rest_my_case/defense_attorney.rb
|
59
|
+
- lib/rest_my_case/errors.rb
|
60
|
+
- lib/rest_my_case/helpers.rb
|
61
|
+
- lib/rest_my_case/judge.rb
|
62
|
+
- lib/rest_my_case/version.rb
|
63
|
+
- rest_my_case.gemspec
|
64
|
+
homepage: https://github.com/goncalvesjoao/rest_my_case
|
65
|
+
licenses:
|
66
|
+
- MIT
|
67
|
+
metadata: {}
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 2.4.2
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
87
|
+
summary: Quick and light "The Clean Architecture" use case implementation.
|
88
|
+
test_files: []
|