hexx 1.1.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +7 -1
- data/README.rdoc +77 -181
- data/Rakefile +7 -21
- data/lib/hexx/models/base_coercer.rb +36 -0
- data/lib/hexx/models.rb +12 -57
- data/lib/hexx/service/invalid.rb +48 -0
- data/lib/hexx/service/message.rb +57 -0
- data/lib/hexx/service/messages.rb +34 -0
- data/lib/hexx/service/parameters.rb +45 -0
- data/lib/hexx/service/transactions.rb +30 -0
- data/lib/hexx/service/validations.rb +18 -0
- data/lib/hexx/service.rb +21 -0
- data/lib/hexx/version.rb +2 -2
- data/lib/hexx.rb +8 -2
- data/spec/hexx/models_spec.rb +6 -9
- data/spec/hexx/service/invalid_spec.rb +51 -0
- data/spec/hexx/service/message_spec.rb +99 -0
- data/spec/hexx/service_spec.rb +183 -0
- data/spec/{support/initializers → initializers}/coveralls.rb +0 -0
- data/spec/{support/initializers → initializers}/focus.rb +0 -0
- data/spec/{support/initializers → initializers}/garbage_collection.rb +0 -0
- data/spec/{support/initializers → initializers}/i18n.rb +2 -0
- data/spec/{support/initializers → initializers}/random_order.rb +0 -0
- data/spec/{support/initializers → initializers}/rspec.rb +0 -0
- data/spec/spec_helper.rb +3 -5
- metadata +31 -117
- data/CHANGELOG.rdoc +0 -12
- data/bin/hexx +0 -54
- data/lib/generators/base.rb +0 -59
- data/lib/generators/controller/controller.rb +0 -114
- data/lib/generators/controller/templates/controller.erb +0 -10
- data/lib/generators/controller/templates/controller_action.erb +0 -7
- data/lib/generators/controller/templates/controller_action_spec.erb +0 -21
- data/lib/generators/controller/templates/controller_spec.erb +0 -20
- data/lib/generators/controller/templates/responder_controller.erb +0 -40
- data/lib/generators/controller/templates/responder_controller_spec.erb +0 -65
- data/lib/generators/controller/templates/routing_action_spec.erb +0 -13
- data/lib/generators/controller/templates/routing_spec.erb +0 -11
- data/lib/generators/controller/templates/views_errors.erb +0 -3
- data/lib/generators/controller/templates/views_messages.erb +0 -3
- data/lib/generators/dependency/dependency.rb +0 -50
- data/lib/generators/dependency/templates/dependency_setting.erb +0 -4
- data/lib/generators/dependency/templates/dependency_setting_spec.erb +0 -39
- data/lib/generators/dependency/templates/initializer.erb +0 -4
- data/lib/generators/dependency/templates/initializer_setting.erb +0 -4
- data/lib/generators/dependency/templates/module_spec.erb +0 -22
- data/lib/generators/domain/domain.rb +0 -24
- data/lib/generators/domain/templates/spec.erb +0 -84
- data/lib/generators/install/install.rb +0 -133
- data/lib/generators/install/templates/bin/rails.erb +0 -11
- data/lib/generators/install/templates/config/routes.erb +0 -6
- data/lib/generators/install/templates/json_schemas/error.erb +0 -14
- data/lib/generators/install/templates/json_schemas/get_errors.erb +0 -18
- data/lib/generators/install/templates/json_schemas/success.erb +0 -14
- data/lib/generators/install/templates/lib/engine.erb +0 -12
- data/lib/generators/install/templates/lib/lib.erb +0 -10
- data/lib/generators/install/templates/lib/task.erb +0 -60
- data/lib/generators/install/templates/lib/version.erb +0 -4
- data/lib/generators/install/templates/matchers/controllers.erb +0 -14
- data/lib/generators/install/templates/matchers/json_schema.erb +0 -10
- data/lib/generators/install/templates/root/Gemfile.erb +0 -9
- data/lib/generators/install/templates/root/Guardfile.erb +0 -14
- data/lib/generators/install/templates/root/LICENSE.erb +0 -21
- data/lib/generators/install/templates/root/README.erb +0 -68
- data/lib/generators/install/templates/root/Rakefile.erb +0 -45
- data/lib/generators/install/templates/root/coveralls.erb +0 -1
- data/lib/generators/install/templates/root/gemspec.erb +0 -33
- data/lib/generators/install/templates/root/gitignore.erb +0 -28
- data/lib/generators/install/templates/root/rspec.erb +0 -1
- data/lib/generators/install/templates/root/rubocop.erb +0 -65
- data/lib/generators/install/templates/root/travis.erb +0 -3
- data/lib/generators/install/templates/spec/caching.erb +0 -12
- data/lib/generators/install/templates/spec/coveralls.erb +0 -4
- data/lib/generators/install/templates/spec/database_cleaner.erb +0 -28
- data/lib/generators/install/templates/spec/factory_girl_rails.erb +0 -5
- data/lib/generators/install/templates/spec/focus.erb +0 -5
- data/lib/generators/install/templates/spec/garbage_collection.erb +0 -11
- data/lib/generators/install/templates/spec/i18n.erb +0 -1
- data/lib/generators/install/templates/spec/migrations.erb +0 -3
- data/lib/generators/install/templates/spec/rails.erb +0 -6
- data/lib/generators/install/templates/spec/random_order.erb +0 -4
- data/lib/generators/install/templates/spec/rspec.erb +0 -10
- data/lib/generators/install/templates/spec/spec_helper.erb +0 -9
- data/lib/generators/install/templates/spec/timecop.erb +0 -1
- data/lib/generators/request/request.rb +0 -52
- data/lib/generators/request/templates/request_spec.erb +0 -66
- data/lib/generators/use_case/templates/use_case.erb +0 -54
- data/lib/generators/use_case/templates/use_case_spec.erb +0 -74
- data/lib/generators/use_case/use_case.rb +0 -31
- data/lib/hexx/exceptions/not_found_error.rb +0 -18
- data/lib/hexx/exceptions/runtime_error.rb +0 -27
- data/lib/hexx/exceptions/use_case_invalid.rb +0 -18
- data/lib/hexx/message.rb +0 -20
- data/lib/hexx/settings.rb +0 -47
- data/lib/hexx/use_case.rb +0 -256
- data/spec/hexx/exceptions/not_found_error_spec.rb +0 -21
- data/spec/hexx/exceptions/runtime_error_spec.rb +0 -43
- data/spec/hexx/exceptions/use_case_invalid_spec.rb +0 -21
- data/spec/hexx/message_spec.rb +0 -31
- data/spec/hexx/settings_spec.rb +0 -51
- data/spec/hexx/use_case_spec.rb +0 -274
- data/spec/support/exception_matchers.rb +0 -7
@@ -1,45 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require "bundler/setup"
|
3
|
-
rescue LoadError
|
4
|
-
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
|
5
|
-
end
|
6
|
-
|
7
|
-
begin
|
8
|
-
require "rdoc/task"
|
9
|
-
rescue LoadError
|
10
|
-
require "rdoc/rdoc"
|
11
|
-
require "rake/rdoctask"
|
12
|
-
RDoc::Task = Rake::RDocTask
|
13
|
-
end
|
14
|
-
|
15
|
-
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
-
rdoc.rdoc_dir = "rdoc"
|
17
|
-
rdoc.title = "<%= module_name %>"
|
18
|
-
rdoc.options << "--line-numbers"
|
19
|
-
rdoc.rdoc_files.include "README.rdoc"
|
20
|
-
rdoc.rdoc_files.include "lib/**/*.rb"
|
21
|
-
end
|
22
|
-
|
23
|
-
Bundler::GemHelper.install_tasks
|
24
|
-
|
25
|
-
APP_RAKEFILE = File.expand_path "../spec/dummy/Rakefile", __FILE__
|
26
|
-
load "rails/tasks/engine.rake"
|
27
|
-
|
28
|
-
require "bundler/gem_tasks"
|
29
|
-
require "rspec/core/rake_task"
|
30
|
-
|
31
|
-
RSpec::Core::RakeTask.new :spec
|
32
|
-
|
33
|
-
task :default do
|
34
|
-
system "mkdir spec/dummy/tmp/cache -p -v"
|
35
|
-
system "bundle exec rake db:migrate RAILS_ENV=test"
|
36
|
-
system "bundle exec rspec spec"
|
37
|
-
end
|
38
|
-
|
39
|
-
task :check do
|
40
|
-
system "coveralls report"
|
41
|
-
system "rubocop"
|
42
|
-
system "metric_fu"
|
43
|
-
system "inch --pedantic"
|
44
|
-
system "rails_best_practices"
|
45
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
service_name: travis-ci
|
@@ -1,33 +0,0 @@
|
|
1
|
-
$:.push File.expand_path("../lib", __FILE__)
|
2
|
-
require "<%= gem_name %>/version"
|
3
|
-
|
4
|
-
Gem::Specification.new do |s|
|
5
|
-
s.name = "<%= gem_name %>"
|
6
|
-
s.version = <%= module_name %>::VERSION
|
7
|
-
s.author = "Andrew Kozin"
|
8
|
-
s.email = "andrew.kozin@gmail.com"
|
9
|
-
s.homepage = "https://github.com/nepalez/<%= gem_name %>"
|
10
|
-
s.summary = "TODO: Summary of <%= module_name %>."
|
11
|
-
s.description = "TODO: Description of <%= module_name %>."
|
12
|
-
s.license = "MIT"
|
13
|
-
s.platform = Gem::Platform::RUBY
|
14
|
-
s.required_ruby_version = "~> 2.1"
|
15
|
-
|
16
|
-
s.files = Dir["{app,config,db,lib}/**/*"]
|
17
|
-
s.test_files = Dir["spec/**/*", "Rakefile", ".rubocop.yml"]
|
18
|
-
s.extra_rdoc_files = Dir["CHANGELOG.rdoc", "LICENSE.rdoc", "README.rdoc"]
|
19
|
-
|
20
|
-
s.add_runtime_dependency "hexx", "~> 1.0.2"
|
21
|
-
s.add_runtime_dependency "jbuilder"
|
22
|
-
s.add_runtime_dependency "rails"
|
23
|
-
|
24
|
-
s.add_development_dependency "database_cleaner"
|
25
|
-
s.add_development_dependency "factory_girl_rails"
|
26
|
-
s.add_development_dependency "inch"
|
27
|
-
s.add_development_dependency "json-schema"
|
28
|
-
s.add_development_dependency "metric_fu"
|
29
|
-
s.add_development_dependency "rspec-rails"
|
30
|
-
s.add_development_dependency "rubocop"
|
31
|
-
s.add_development_dependency "sqlite3"
|
32
|
-
s.add_development_dependency "timecop"
|
33
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
*.a
|
2
|
-
*.bundle
|
3
|
-
*.gem
|
4
|
-
*.o
|
5
|
-
*.rbc
|
6
|
-
*.so
|
7
|
-
.bundle
|
8
|
-
.config
|
9
|
-
.yardoc
|
10
|
-
_yardoc
|
11
|
-
coverage
|
12
|
-
doc/
|
13
|
-
Gemfile.lock
|
14
|
-
InstalledFiles
|
15
|
-
lib/bundler/man
|
16
|
-
log
|
17
|
-
mkmf.log
|
18
|
-
pkg
|
19
|
-
rdoc
|
20
|
-
spec/dummy/.sass-cache
|
21
|
-
spec/dummy/db/*.sqlite3
|
22
|
-
spec/dummy/db/*.sqlite3-journal
|
23
|
-
spec/dummy/log
|
24
|
-
spec/dummy/tmp
|
25
|
-
spec/reports
|
26
|
-
test/tmp
|
27
|
-
test/version_tmp
|
28
|
-
tmp
|
@@ -1 +0,0 @@
|
|
1
|
-
--color
|
@@ -1,65 +0,0 @@
|
|
1
|
-
AllCops:
|
2
|
-
Exclude:
|
3
|
-
- 'spec/dummy/**/*'
|
4
|
-
- 'Rakefile'
|
5
|
-
|
6
|
-
Lint/HandleExceptions:
|
7
|
-
Exclude:
|
8
|
-
- 'spec/**/*'
|
9
|
-
|
10
|
-
Lint/RescueException:
|
11
|
-
Exclude:
|
12
|
-
- 'spec/**/*'
|
13
|
-
|
14
|
-
Style/AccessorMethodName:
|
15
|
-
Exclude:
|
16
|
-
- 'spec/**/*'
|
17
|
-
|
18
|
-
Style/AsciiComments:
|
19
|
-
Enabled: false
|
20
|
-
|
21
|
-
Style/ClassAndModuleChildren:
|
22
|
-
Exclude:
|
23
|
-
- 'spec/**/*'
|
24
|
-
|
25
|
-
Style/Documentation:
|
26
|
-
Exclude:
|
27
|
-
- 'spec/**/*'
|
28
|
-
- 'db/**/*'
|
29
|
-
|
30
|
-
Style/EmptyLinesAroundBody:
|
31
|
-
Enabled: false
|
32
|
-
|
33
|
-
Style/EmptyLineBetweenDefs:
|
34
|
-
Exclude:
|
35
|
-
- 'spec/**/*'
|
36
|
-
|
37
|
-
Style/MethodLength:
|
38
|
-
Exclude:
|
39
|
-
- 'db/**/*'
|
40
|
-
|
41
|
-
Style/RaiseArgs:
|
42
|
-
EnforcedStyle: compact
|
43
|
-
|
44
|
-
Style/SingleLineMethods:
|
45
|
-
Exclude:
|
46
|
-
- 'spec/**/*'
|
47
|
-
|
48
|
-
Style/SpecialGlobalVars:
|
49
|
-
Exclude:
|
50
|
-
- 'Gemfile'
|
51
|
-
- '*.gemspec'
|
52
|
-
|
53
|
-
Style/StringLiterals:
|
54
|
-
EnforcedStyle: double_quotes
|
55
|
-
|
56
|
-
Style/SingleSpaceBeforeFirstArg:
|
57
|
-
Enabled: false
|
58
|
-
|
59
|
-
Style/TrailingBlankLines:
|
60
|
-
Exclude:
|
61
|
-
- 'app/views/**/*'
|
62
|
-
|
63
|
-
Style/TrivialAccessors:
|
64
|
-
Exclude:
|
65
|
-
- 'spec/**/*'
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require "rails"
|
2
|
-
require "rspec/rails"
|
3
|
-
|
4
|
-
RSpec.configure do |config|
|
5
|
-
config.around(:each, :caching) do |example|
|
6
|
-
caching = ActionController::Base.perform_caching
|
7
|
-
ActionController::Base.perform_caching = example.metadata[:caching]
|
8
|
-
example.run
|
9
|
-
Rails.cache.clear
|
10
|
-
ActionController::Base.perform_caching = caching
|
11
|
-
end
|
12
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require "database_cleaner"
|
2
|
-
require "rspec/rails"
|
3
|
-
|
4
|
-
RSpec.configure do |config|
|
5
|
-
|
6
|
-
# stop wrapping each of test examples within a transaction
|
7
|
-
config.use_transactional_fixtures = false
|
8
|
-
|
9
|
-
config.before :suite do
|
10
|
-
DatabaseCleaner.clean_with :truncation
|
11
|
-
end
|
12
|
-
|
13
|
-
config.before :each do
|
14
|
-
DatabaseCleaner.strategy = :transaction
|
15
|
-
end
|
16
|
-
|
17
|
-
config.before :each, js: true do
|
18
|
-
DatabaseCleaner.strategy = :truncation
|
19
|
-
end
|
20
|
-
|
21
|
-
config.before :each do
|
22
|
-
DatabaseCleaner.start
|
23
|
-
end
|
24
|
-
|
25
|
-
config.after :each do
|
26
|
-
DatabaseCleaner.clean
|
27
|
-
end
|
28
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
I18n.enforce_available_locales = false
|
@@ -1,9 +0,0 @@
|
|
1
|
-
ENV["RAILS_ENV"] ||= "test"
|
2
|
-
|
3
|
-
root = File.dirname File.dirname(__FILE__)
|
4
|
-
|
5
|
-
# Application files
|
6
|
-
require File.expand_path("../dummy/config/environment", __FILE__)
|
7
|
-
|
8
|
-
# Support files and Rspec settings
|
9
|
-
Dir[File.join(root, "spec/support/**/*.rb")].each { |file| require file }
|
@@ -1 +0,0 @@
|
|
1
|
-
require "timecop"
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require_relative "../base"
|
2
|
-
|
3
|
-
module Hexx
|
4
|
-
module Generators
|
5
|
-
|
6
|
-
# Request spec (acceptance test) scaffolder.
|
7
|
-
class Request < Base
|
8
|
-
|
9
|
-
def self.source_root
|
10
|
-
super __FILE__
|
11
|
-
end
|
12
|
-
|
13
|
-
def create_request_spec
|
14
|
-
template(
|
15
|
-
"request_spec.erb",
|
16
|
-
"spec/#{ requests_path }/#{ action_type }_#{ short_name }_spec.rb"
|
17
|
-
)
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
# path where params changed to 1: "items/1"
|
23
|
-
def escaped_name
|
24
|
-
@escaped_name ||= full_name.gsub(/\{.+\}/, "1")
|
25
|
-
end
|
26
|
-
|
27
|
-
# underscore path: "items_id"
|
28
|
-
def short_name
|
29
|
-
@short_name ||= full_name.gsub(/[\/|\{|\}]+/, "_").gsub(/\_$/, "")
|
30
|
-
end
|
31
|
-
|
32
|
-
# full_path: "items/{id}"
|
33
|
-
def full_name
|
34
|
-
@full_name ||= parts[1].to_s
|
35
|
-
end
|
36
|
-
|
37
|
-
# type of action: "get"
|
38
|
-
def action_type
|
39
|
-
@action_type ||= parts[0].to_s
|
40
|
-
end
|
41
|
-
|
42
|
-
# path from the request: get:items/{id} => ["get", "items/{id}"]
|
43
|
-
def parts
|
44
|
-
@parts ||= name.split(":").map(&:downcase)
|
45
|
-
end
|
46
|
-
|
47
|
-
def requests_path
|
48
|
-
"requests/#{ gem_name }/api/v1"
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
module <%= module_name %>
|
4
|
-
describe "<%= action_type.upcase %> api/v1/<%= full_name %>" do
|
5
|
-
|
6
|
-
# ==========================================================================
|
7
|
-
# Prepare context
|
8
|
-
# ==========================================================================
|
9
|
-
|
10
|
-
# let!(:something) { something }
|
11
|
-
|
12
|
-
# ==========================================================================
|
13
|
-
# Prepare variables
|
14
|
-
# ==========================================================================
|
15
|
-
|
16
|
-
# let!(:params) { { "something" => something } }
|
17
|
-
|
18
|
-
# def call_request(params)
|
19
|
-
# <%= action_type %> "<%= gem_name %>/api/v1/<%= escaped_name %>", params
|
20
|
-
# end
|
21
|
-
|
22
|
-
# ==========================================================================
|
23
|
-
# Run tests
|
24
|
-
# ==========================================================================
|
25
|
-
|
26
|
-
# context "with proper params" do
|
27
|
-
|
28
|
-
# before { call_request params }
|
29
|
-
|
30
|
-
# it "changes something" do
|
31
|
-
# expect(something).to eq something
|
32
|
-
# end
|
33
|
-
|
34
|
-
# it "responds with 200" do
|
35
|
-
# expect(response.status).to eq 200
|
36
|
-
# end
|
37
|
-
|
38
|
-
# it "receives proper json" do
|
39
|
-
# expect(response.body).to match_json_schema(:something)
|
40
|
-
# end
|
41
|
-
|
42
|
-
# it "receives something" do
|
43
|
-
# something = JSON.parse(response.body)["something"]
|
44
|
-
# expect(something).to eq something
|
45
|
-
# end
|
46
|
-
# end
|
47
|
-
|
48
|
-
# context "with wrong params" do
|
49
|
-
#
|
50
|
-
# before { params["something"] = something }
|
51
|
-
# before { call_request params }
|
52
|
-
|
53
|
-
# it "doesn't change something" do
|
54
|
-
# expect(something).to eq something
|
55
|
-
# end
|
56
|
-
|
57
|
-
# it "responds with 400" do
|
58
|
-
# expect(response.status).to eq 400
|
59
|
-
# end
|
60
|
-
|
61
|
-
# it "receives proper json" do
|
62
|
-
# expect(response.body).to match_json_schema(:get_errors)
|
63
|
-
# end
|
64
|
-
# end
|
65
|
-
end
|
66
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
module <%= module_name %>
|
2
|
-
|
3
|
-
# TODO: What does the case do?
|
4
|
-
#
|
5
|
-
# @example
|
6
|
-
# use_case = <%= class_name %>.new(TODO: TODO)
|
7
|
-
# use_case.subscribe some_listener
|
8
|
-
# use_case.run
|
9
|
-
#
|
10
|
-
# Methods:
|
11
|
-
# <tt>.new</tt>:: initializes a use case with some uuid.
|
12
|
-
# <tt>#subscribe</tt>:: subscribes listeners for <tt>#run</tt>'s notifications
|
13
|
-
# <tt>#run</tt>:: runs a case and returns TODO or +nil+
|
14
|
-
# <tt>#run!</tt>:: runs a case. Fails if no firm found.
|
15
|
-
#
|
16
|
-
# The +run+ method returns TODO (or +nil+) and notifies its listeners:
|
17
|
-
# <tt>:TODO</tt>:: when TODO.
|
18
|
-
#
|
19
|
-
class <%= class_name %> < Hexx::UseCase
|
20
|
-
|
21
|
-
# Allow necessary parameters here:
|
22
|
-
# allow_params :some_parameter, :another_one
|
23
|
-
|
24
|
-
# Add case-specific validations
|
25
|
-
# validates :some_attribute, presence: true
|
26
|
-
|
27
|
-
# Runs the case and fails if TODO.
|
28
|
-
#
|
29
|
-
# @example
|
30
|
-
# <%= class_name %>.new(TODO: TODO).run!
|
31
|
-
# # => #<<%= module_name %>::TODO ...>
|
32
|
-
#
|
33
|
-
# <%= class_name %>.new.run!
|
34
|
-
# # => fails with #<TODO ...>
|
35
|
-
#
|
36
|
-
def run!
|
37
|
-
validate!
|
38
|
-
# describe other rules here
|
39
|
-
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
# Define custom validations
|
44
|
-
# def something_valid?
|
45
|
-
# return unless something
|
46
|
-
# errors.add :some_attribute, :some_key
|
47
|
-
# end
|
48
|
-
|
49
|
-
# Define virtual attributes to validate
|
50
|
-
# def some_attribute
|
51
|
-
# @some_attribute ||= params["some_param"]
|
52
|
-
# end
|
53
|
-
end
|
54
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
module <%= module_name %>
|
4
|
-
describe <%= class_name %> do
|
5
|
-
|
6
|
-
# ==========================================================================
|
7
|
-
# Prepare context
|
8
|
-
# ==========================================================================
|
9
|
-
|
10
|
-
# let!(:something) { create :something }
|
11
|
-
|
12
|
-
# ==========================================================================
|
13
|
-
# Prepare variables
|
14
|
-
# ==========================================================================
|
15
|
-
|
16
|
-
# let!(:params) { { "key" => value } }
|
17
|
-
# let(:listener) { double "listener" }
|
18
|
-
|
19
|
-
# def prepare_case(params)
|
20
|
-
# use_case = <%= class_name %>.new params
|
21
|
-
# use_case.subscribe(listener)
|
22
|
-
# use_case
|
23
|
-
# end
|
24
|
-
|
25
|
-
# ==========================================================================
|
26
|
-
# Run tests
|
27
|
-
# ==========================================================================
|
28
|
-
|
29
|
-
describe "#run" do
|
30
|
-
|
31
|
-
# context "with valid params" do
|
32
|
-
|
33
|
-
# subject(:use_case) { prepare_case params }
|
34
|
-
|
35
|
-
# it "does something" do
|
36
|
-
# expect { use_case.run }.to change { something }.to(something)
|
37
|
-
# end
|
38
|
-
|
39
|
-
# it "returns something" do
|
40
|
-
# expect(use_case.run).to eq expected_result
|
41
|
-
# end
|
42
|
-
|
43
|
-
# it "sends 'something' to subscribers" do
|
44
|
-
# expect(listener).to receive :something do |result, messages|
|
45
|
-
# expect(result).to eq expected_result
|
46
|
-
# expect(messages).not_to be_blank
|
47
|
-
# end
|
48
|
-
# use_case.run
|
49
|
-
# end
|
50
|
-
# end
|
51
|
-
|
52
|
-
# context "with invalid params" do
|
53
|
-
|
54
|
-
# before { params[:something] = something }
|
55
|
-
# subject(:use_case) { prepare_case params }
|
56
|
-
|
57
|
-
# it "doesn't do something" do
|
58
|
-
# expect { use_case.run }.not_to change { something }
|
59
|
-
# end
|
60
|
-
|
61
|
-
# it "returns nil" do
|
62
|
-
# expect(use_case.run).to be_nil
|
63
|
-
# end
|
64
|
-
|
65
|
-
# it "sends 'error' to subscribers" do
|
66
|
-
# expect(listener).to receive :error do |messages|
|
67
|
-
# expect(messages).not_to be_blank
|
68
|
-
# end
|
69
|
-
# use_case.run
|
70
|
-
# end
|
71
|
-
# end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require_relative "../base"
|
2
|
-
|
3
|
-
module Hexx
|
4
|
-
module Generators
|
5
|
-
|
6
|
-
# Use case scaffolder.
|
7
|
-
class UseCase < Base
|
8
|
-
|
9
|
-
def self.source_root
|
10
|
-
super __FILE__
|
11
|
-
end
|
12
|
-
|
13
|
-
def add_use_case
|
14
|
-
template "use_case.erb", "app/#{ use_cases_path }/#{ file_name }.rb"
|
15
|
-
end
|
16
|
-
|
17
|
-
def add_use_case_spec
|
18
|
-
template(
|
19
|
-
"use_case_spec.erb",
|
20
|
-
"spec/#{ use_cases_path }/#{ file_name }_spec.rb"
|
21
|
-
)
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def use_cases_path
|
27
|
-
"use_cases/#{ gem_name }"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require_relative "runtime_error"
|
2
|
-
|
3
|
-
module Hexx
|
4
|
-
|
5
|
-
# An exception to be raised in case some record not found
|
6
|
-
#
|
7
|
-
# It is expected, that the object stores error messages in its <tt>errors</tt>
|
8
|
-
# collection.
|
9
|
-
#
|
10
|
-
class NotFoundError < RuntimeError
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
def default
|
15
|
-
"Not found"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module Hexx
|
2
|
-
|
3
|
-
# An exception to be raised by some method with given object.
|
4
|
-
#
|
5
|
-
# It is expected, that the object stores error messages in its <tt>errors</tt>
|
6
|
-
# collection.
|
7
|
-
#
|
8
|
-
class RuntimeError < ::RuntimeError
|
9
|
-
|
10
|
-
attr_reader :messages
|
11
|
-
|
12
|
-
def initialize(object)
|
13
|
-
fail ArgumentError unless object.is_a? UseCase
|
14
|
-
@messages ||= object.errors.messages.values.flatten
|
15
|
-
end
|
16
|
-
|
17
|
-
def message
|
18
|
-
@message ||= "#{ default }: #{ messages.join("; ") }"
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def default
|
24
|
-
"Runtime error"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require_relative "runtime_error"
|
2
|
-
|
3
|
-
module Hexx
|
4
|
-
|
5
|
-
# An exception to be raised by the <tt>UseCase#validate!</tt> method.
|
6
|
-
#
|
7
|
-
# It is expected, that the object stores error messages in its <tt>errors</tt>
|
8
|
-
# collection.
|
9
|
-
#
|
10
|
-
class UseCaseInvalid < RuntimeError
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
def default
|
15
|
-
"Use case invalid"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
data/lib/hexx/message.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
module Hexx
|
2
|
-
|
3
|
-
# A message to be returned by use_case
|
4
|
-
class Message
|
5
|
-
|
6
|
-
attr_reader :type, :text
|
7
|
-
|
8
|
-
def initialize(type:, text:)
|
9
|
-
self.type, self.text = type, text
|
10
|
-
end
|
11
|
-
|
12
|
-
def type=(value)
|
13
|
-
@type = value.to_s
|
14
|
-
end
|
15
|
-
|
16
|
-
def text=(value)
|
17
|
-
@text = value.to_s
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|