hexx 1.1.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +7 -1
  3. data/README.rdoc +77 -181
  4. data/Rakefile +7 -21
  5. data/lib/hexx/models/base_coercer.rb +36 -0
  6. data/lib/hexx/models.rb +12 -57
  7. data/lib/hexx/service/invalid.rb +48 -0
  8. data/lib/hexx/service/message.rb +57 -0
  9. data/lib/hexx/service/messages.rb +34 -0
  10. data/lib/hexx/service/parameters.rb +45 -0
  11. data/lib/hexx/service/transactions.rb +30 -0
  12. data/lib/hexx/service/validations.rb +18 -0
  13. data/lib/hexx/service.rb +21 -0
  14. data/lib/hexx/version.rb +2 -2
  15. data/lib/hexx.rb +8 -2
  16. data/spec/hexx/models_spec.rb +6 -9
  17. data/spec/hexx/service/invalid_spec.rb +51 -0
  18. data/spec/hexx/service/message_spec.rb +99 -0
  19. data/spec/hexx/service_spec.rb +183 -0
  20. data/spec/{support/initializers → initializers}/coveralls.rb +0 -0
  21. data/spec/{support/initializers → initializers}/focus.rb +0 -0
  22. data/spec/{support/initializers → initializers}/garbage_collection.rb +0 -0
  23. data/spec/{support/initializers → initializers}/i18n.rb +2 -0
  24. data/spec/{support/initializers → initializers}/random_order.rb +0 -0
  25. data/spec/{support/initializers → initializers}/rspec.rb +0 -0
  26. data/spec/spec_helper.rb +3 -5
  27. metadata +31 -117
  28. data/CHANGELOG.rdoc +0 -12
  29. data/bin/hexx +0 -54
  30. data/lib/generators/base.rb +0 -59
  31. data/lib/generators/controller/controller.rb +0 -114
  32. data/lib/generators/controller/templates/controller.erb +0 -10
  33. data/lib/generators/controller/templates/controller_action.erb +0 -7
  34. data/lib/generators/controller/templates/controller_action_spec.erb +0 -21
  35. data/lib/generators/controller/templates/controller_spec.erb +0 -20
  36. data/lib/generators/controller/templates/responder_controller.erb +0 -40
  37. data/lib/generators/controller/templates/responder_controller_spec.erb +0 -65
  38. data/lib/generators/controller/templates/routing_action_spec.erb +0 -13
  39. data/lib/generators/controller/templates/routing_spec.erb +0 -11
  40. data/lib/generators/controller/templates/views_errors.erb +0 -3
  41. data/lib/generators/controller/templates/views_messages.erb +0 -3
  42. data/lib/generators/dependency/dependency.rb +0 -50
  43. data/lib/generators/dependency/templates/dependency_setting.erb +0 -4
  44. data/lib/generators/dependency/templates/dependency_setting_spec.erb +0 -39
  45. data/lib/generators/dependency/templates/initializer.erb +0 -4
  46. data/lib/generators/dependency/templates/initializer_setting.erb +0 -4
  47. data/lib/generators/dependency/templates/module_spec.erb +0 -22
  48. data/lib/generators/domain/domain.rb +0 -24
  49. data/lib/generators/domain/templates/spec.erb +0 -84
  50. data/lib/generators/install/install.rb +0 -133
  51. data/lib/generators/install/templates/bin/rails.erb +0 -11
  52. data/lib/generators/install/templates/config/routes.erb +0 -6
  53. data/lib/generators/install/templates/json_schemas/error.erb +0 -14
  54. data/lib/generators/install/templates/json_schemas/get_errors.erb +0 -18
  55. data/lib/generators/install/templates/json_schemas/success.erb +0 -14
  56. data/lib/generators/install/templates/lib/engine.erb +0 -12
  57. data/lib/generators/install/templates/lib/lib.erb +0 -10
  58. data/lib/generators/install/templates/lib/task.erb +0 -60
  59. data/lib/generators/install/templates/lib/version.erb +0 -4
  60. data/lib/generators/install/templates/matchers/controllers.erb +0 -14
  61. data/lib/generators/install/templates/matchers/json_schema.erb +0 -10
  62. data/lib/generators/install/templates/root/Gemfile.erb +0 -9
  63. data/lib/generators/install/templates/root/Guardfile.erb +0 -14
  64. data/lib/generators/install/templates/root/LICENSE.erb +0 -21
  65. data/lib/generators/install/templates/root/README.erb +0 -68
  66. data/lib/generators/install/templates/root/Rakefile.erb +0 -45
  67. data/lib/generators/install/templates/root/coveralls.erb +0 -1
  68. data/lib/generators/install/templates/root/gemspec.erb +0 -33
  69. data/lib/generators/install/templates/root/gitignore.erb +0 -28
  70. data/lib/generators/install/templates/root/rspec.erb +0 -1
  71. data/lib/generators/install/templates/root/rubocop.erb +0 -65
  72. data/lib/generators/install/templates/root/travis.erb +0 -3
  73. data/lib/generators/install/templates/spec/caching.erb +0 -12
  74. data/lib/generators/install/templates/spec/coveralls.erb +0 -4
  75. data/lib/generators/install/templates/spec/database_cleaner.erb +0 -28
  76. data/lib/generators/install/templates/spec/factory_girl_rails.erb +0 -5
  77. data/lib/generators/install/templates/spec/focus.erb +0 -5
  78. data/lib/generators/install/templates/spec/garbage_collection.erb +0 -11
  79. data/lib/generators/install/templates/spec/i18n.erb +0 -1
  80. data/lib/generators/install/templates/spec/migrations.erb +0 -3
  81. data/lib/generators/install/templates/spec/rails.erb +0 -6
  82. data/lib/generators/install/templates/spec/random_order.erb +0 -4
  83. data/lib/generators/install/templates/spec/rspec.erb +0 -10
  84. data/lib/generators/install/templates/spec/spec_helper.erb +0 -9
  85. data/lib/generators/install/templates/spec/timecop.erb +0 -1
  86. data/lib/generators/request/request.rb +0 -52
  87. data/lib/generators/request/templates/request_spec.erb +0 -66
  88. data/lib/generators/use_case/templates/use_case.erb +0 -54
  89. data/lib/generators/use_case/templates/use_case_spec.erb +0 -74
  90. data/lib/generators/use_case/use_case.rb +0 -31
  91. data/lib/hexx/exceptions/not_found_error.rb +0 -18
  92. data/lib/hexx/exceptions/runtime_error.rb +0 -27
  93. data/lib/hexx/exceptions/use_case_invalid.rb +0 -18
  94. data/lib/hexx/message.rb +0 -20
  95. data/lib/hexx/settings.rb +0 -47
  96. data/lib/hexx/use_case.rb +0 -256
  97. data/spec/hexx/exceptions/not_found_error_spec.rb +0 -21
  98. data/spec/hexx/exceptions/runtime_error_spec.rb +0 -43
  99. data/spec/hexx/exceptions/use_case_invalid_spec.rb +0 -21
  100. data/spec/hexx/message_spec.rb +0 -31
  101. data/spec/hexx/settings_spec.rb +0 -51
  102. data/spec/hexx/use_case_spec.rb +0 -274
  103. 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,3 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.1
@@ -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,4 +0,0 @@
1
- # Check test coverage
2
- require "coveralls"
3
-
4
- Coveralls.wear!
@@ -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,5 +0,0 @@
1
- require "factory_girl_rails"
2
-
3
- RSpec.configure do |config|
4
- config.include FactoryGirl::Syntax::Methods
5
- end
@@ -1,5 +0,0 @@
1
- # Run only tests tagged by :focus
2
- RSpec.configure do |config|
3
- config.filter_run focus: true
4
- config.run_all_when_everything_filtered = true
5
- end
@@ -1,11 +0,0 @@
1
- # Delayg garbage collection to the end of tests
2
- RSpec.configure do |config|
3
-
4
- config.before(:each) do
5
- GC.disable
6
- end
7
-
8
- config.after(:each) do
9
- GC.enable
10
- end
11
- end
@@ -1 +0,0 @@
1
- I18n.enforce_available_locales = false
@@ -1,3 +0,0 @@
1
- require "active_record"
2
-
3
- ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
@@ -1,6 +0,0 @@
1
- require "rspec/rails"
2
-
3
- RSpec.configure do |config|
4
- config.infer_spec_type_from_file_location!
5
- config.infer_base_class_for_anonymous_controllers = false
6
- end
@@ -1,4 +0,0 @@
1
- # Run tests in a random order
2
- RSpec.configure do |config|
3
- config.order = "random"
4
- end
@@ -1,10 +0,0 @@
1
- RSpec.configure do |config|
2
-
3
- config.mock_with :rspec do |mocks|
4
- mocks.yield_receiver_to_any_instance_implementation_blocks = false
5
- end
6
-
7
- config.expect_with :rspec do |c|
8
- c.syntax = :expect
9
- end
10
- end
@@ -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