hexx 7.1.0 → 8.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.coveralls.yml +2 -0
- data/.gitignore +9 -0
- data/.metrics +5 -0
- data/.rspec +2 -0
- data/.rubocop.yml +2 -63
- data/.travis.yml +5 -0
- data/.yardopts +2 -0
- data/Gemfile +3 -0
- data/Guardfile +16 -0
- data/{LICENSE.rdoc → LICENSE} +2 -2
- data/README.md +138 -0
- data/Rakefile +8 -14
- data/config/initializer.rb +5 -0
- data/config/initializers/capture.rb +19 -0
- data/config/initializers/sandbox.rb +16 -0
- data/config/initializers/sandbox/helpers.rb +38 -0
- data/config/initializers/sandbox/matchers.rb +19 -0
- data/config/metrics/STYLEGUIDE +230 -0
- data/config/metrics/cane.yml +5 -0
- data/config/metrics/churn.yml +6 -0
- data/config/metrics/flay.yml +2 -0
- data/config/metrics/metric_fu.yml +15 -0
- data/config/metrics/pippi.yml +3 -0
- data/config/metrics/reek.yml +1 -0
- data/config/metrics/roodi.yml +24 -0
- data/config/metrics/rubocop.yml +79 -0
- data/config/metrics/saikuro.yml +3 -0
- data/config/metrics/simplecov.yml +6 -0
- data/config/metrics/yardstick.yml +37 -0
- data/hexx.gemspec +24 -0
- data/lib/hexx.rb +8 -15
- data/lib/hexx/generator.rb +71 -0
- data/lib/hexx/generator/file.rb +83 -0
- data/lib/hexx/generator/folder.rb +68 -0
- data/lib/hexx/name.rb +122 -46
- data/lib/hexx/version.rb +6 -5
- data/spec/fixtures/root/_.beta +1 -0
- data/spec/fixtures/root/__omega +0 -0
- data/spec/fixtures/root/delta.erb.erb +0 -0
- data/spec/fixtures/root/gamma.rb.erb +1 -0
- data/spec/fixtures/root/subfolder/alfa.yml +0 -0
- data/spec/spec_helper.rb +5 -10
- data/spec/tests/lib/generator_spec.rb +126 -0
- data/spec/tests/lib/name_spec.rb +113 -0
- metadata +54 -168
- data/README.rdoc +0 -371
- data/lib/hexx/coercible.rb +0 -43
- data/lib/hexx/configurable.rb +0 -101
- data/lib/hexx/creators/base.rb +0 -103
- data/lib/hexx/creators/coercion.rb +0 -82
- data/lib/hexx/creators/dependency.rb +0 -87
- data/lib/hexx/creators/module_dependency.rb +0 -57
- data/lib/hexx/creators/parameter.rb +0 -40
- data/lib/hexx/dependable.rb +0 -51
- data/lib/hexx/helpers/exceptions.rb +0 -53
- data/lib/hexx/helpers/messages.rb +0 -26
- data/lib/hexx/helpers/parameters.rb +0 -47
- data/lib/hexx/helpers/validations.rb +0 -21
- data/lib/hexx/message.rb +0 -79
- data/lib/hexx/null.rb +0 -218
- data/lib/hexx/service.rb +0 -388
- data/lib/hexx/service/with_callbacks.rb +0 -104
- data/lib/hexx/service_invalid.rb +0 -73
- data/spec/hexx/coercible_spec.rb +0 -72
- data/spec/hexx/configurable_spec.rb +0 -93
- data/spec/hexx/dependable_spec.rb +0 -125
- data/spec/hexx/helpers/exceptions_spec.rb +0 -96
- data/spec/hexx/helpers/messages_spec.rb +0 -48
- data/spec/hexx/helpers/parameters_spec.rb +0 -96
- data/spec/hexx/helpers/validations_spec.rb +0 -32
- data/spec/hexx/message_spec.rb +0 -83
- data/spec/hexx/name_spec.rb +0 -80
- data/spec/hexx/null_spec.rb +0 -152
- data/spec/hexx/service_invalid_spec.rb +0 -46
- data/spec/hexx/service_spec.rb +0 -89
- data/spec/support/initializers/focus.rb +0 -5
- data/spec/support/initializers/garbage_collection.rb +0 -11
- data/spec/support/initializers/i18n.rb +0 -3
- data/spec/support/initializers/random_order.rb +0 -4
- data/spec/support/initializers/rspec.rb +0 -5
- data/spec/support/matchers/methods.rb +0 -11
data/lib/hexx/service_invalid.rb
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
require_relative "message"
|
2
|
-
|
3
|
-
module Hexx
|
4
|
-
|
5
|
-
# The exception to be risen by invalid services.
|
6
|
-
#
|
7
|
-
# @example
|
8
|
-
# service GetItem < Hexx::Service
|
9
|
-
# allow_params :uuid
|
10
|
-
# validates :uuid, presence: true
|
11
|
-
# def run
|
12
|
-
# validate!
|
13
|
-
# end
|
14
|
-
# end
|
15
|
-
#
|
16
|
-
# service = GetItem.new
|
17
|
-
# service.run # => fails with the {Hexx::ServiceInvalid}.
|
18
|
-
class ServiceInvalid < ::RuntimeError
|
19
|
-
|
20
|
-
# @!attribute [r] service
|
21
|
-
# @return [Hexx::Service] The invalid service object.
|
22
|
-
attr_reader :service
|
23
|
-
|
24
|
-
# @!scope class
|
25
|
-
# @!method new(service)
|
26
|
-
# Initializes the exception.
|
27
|
-
#
|
28
|
-
# @example
|
29
|
-
# fail Hexx::ServiceInvalid.new service
|
30
|
-
#
|
31
|
-
# @param [Hexx::Service] service The invalid service.
|
32
|
-
# @raise [ArgumentError] if the argument is not a service object.
|
33
|
-
# @return [Hexx::ServiceInvalid] The exception.
|
34
|
-
|
35
|
-
# @api hide
|
36
|
-
def initialize(service)
|
37
|
-
@service = service
|
38
|
-
end
|
39
|
-
|
40
|
-
# @!attribute [r] message
|
41
|
-
# Returns a default text message for the exception.
|
42
|
-
#
|
43
|
-
# @example
|
44
|
-
# error = Hexx::ServiceInvalid.new service
|
45
|
-
# error.message # => "Service invalid: #<Hexx::Service... >"
|
46
|
-
#
|
47
|
-
# @return [String] The message.
|
48
|
-
def message
|
49
|
-
"Service invalid: #{ service.inspect }"
|
50
|
-
end
|
51
|
-
|
52
|
-
# @!attribute [r] messages
|
53
|
-
# Returns a list of error messages from the service.
|
54
|
-
#
|
55
|
-
# @example
|
56
|
-
# service.errors.add :base, "some error"
|
57
|
-
#
|
58
|
-
# error = Hexx::ServiceInvalid.new service
|
59
|
-
# error.messages
|
60
|
-
# # => [#<Hexx::Message @type="error" @text="some error" >]
|
61
|
-
#
|
62
|
-
# @return [Array<Hexx::Message>] The list of error messages.
|
63
|
-
def messages
|
64
|
-
errors.map { |text| Message.new type: "error", text: text }
|
65
|
-
end
|
66
|
-
|
67
|
-
private
|
68
|
-
|
69
|
-
def errors
|
70
|
-
service.errors.messages.values.flatten
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
data/spec/hexx/coercible_spec.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
module Hexx
|
4
|
-
describe Coercible do
|
5
|
-
|
6
|
-
# ==========================================================================
|
7
|
-
# Prepare environment
|
8
|
-
# ==========================================================================
|
9
|
-
|
10
|
-
before { class TestModel; extend Coercible; end }
|
11
|
-
before { module TestModule; end }
|
12
|
-
before { class TestCoercion < Struct.new(:string); end }
|
13
|
-
|
14
|
-
let(:test_model) { TestModel }
|
15
|
-
let(:test_module) { TestModule }
|
16
|
-
let(:test_coercion) { TestCoercion }
|
17
|
-
|
18
|
-
after { Hexx.send :remove_const, :TestCoercion }
|
19
|
-
after { Hexx.send :remove_const, :TestModule }
|
20
|
-
after { Hexx.send :remove_const, :TestModel }
|
21
|
-
|
22
|
-
# ==========================================================================
|
23
|
-
# Run tests
|
24
|
-
# ==========================================================================
|
25
|
-
|
26
|
-
describe ".attr_coerced" do
|
27
|
-
|
28
|
-
context "when the name is neither type nor symbol" do
|
29
|
-
|
30
|
-
it "fails with TypeError" do
|
31
|
-
expect { test_model.send :attr_coerced, 1, type: test_coercion }
|
32
|
-
.to raise_error(TypeError)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context "when the name is empty" do
|
37
|
-
|
38
|
-
it "fails with ArgumentError" do
|
39
|
-
expect { test_model.send :attr_coerced, "", type: test_coercion }
|
40
|
-
.to raise_error(ArgumentError)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context "when no type is set" do
|
45
|
-
|
46
|
-
it "fails with ArgumentError" do
|
47
|
-
expect { test_model.send :attr_coerced, :name }
|
48
|
-
.to raise_error(ArgumentError)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
context "when a type is not a class" do
|
53
|
-
|
54
|
-
it "fails with TypeError" do
|
55
|
-
expect { test_model.send :attr_coerced, :name, type: test_module }
|
56
|
-
.to raise_error(TypeError)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context "with valid arguments" do
|
61
|
-
|
62
|
-
before { test_model.send :attr_coerced, :name, type: test_coercion }
|
63
|
-
subject { test_model.new }
|
64
|
-
|
65
|
-
it "coerces an attribute with given type" do
|
66
|
-
subject.name = "some name"
|
67
|
-
expect(subject.name).to be_kind_of test_coercion
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
@@ -1,93 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
module Hexx
|
4
|
-
describe Configurable do
|
5
|
-
|
6
|
-
# Mocks gem core module to test dependencies from
|
7
|
-
before { module Test; extend Configurable; end }
|
8
|
-
after { Hexx.send :remove_const, :Test }
|
9
|
-
|
10
|
-
let(:described_module) { Test }
|
11
|
-
|
12
|
-
describe ".configure" do
|
13
|
-
|
14
|
-
it "is defined" do
|
15
|
-
expect(described_module).to respond_to :configure
|
16
|
-
end
|
17
|
-
|
18
|
-
it "yields block with self" do
|
19
|
-
described_module.configure do |config|
|
20
|
-
expect(config).to eq described_module
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe ".depends_on" do
|
26
|
-
|
27
|
-
it "is defined" do
|
28
|
-
expect(described_module).to respond_to :depends_on
|
29
|
-
end
|
30
|
-
|
31
|
-
it "accepts symbolic attributes" do
|
32
|
-
expect { described_module.depends_on :item }.not_to raise_error
|
33
|
-
end
|
34
|
-
|
35
|
-
it "accepts string attributes" do
|
36
|
-
expect { described_module.depends_on "item" }.not_to raise_error
|
37
|
-
end
|
38
|
-
|
39
|
-
it "accepts arrays" do
|
40
|
-
expect { described_module.depends_on "item", [:item] }
|
41
|
-
.not_to raise_error
|
42
|
-
end
|
43
|
-
|
44
|
-
it "accepts default option" do
|
45
|
-
expect { described_module.depends_on :item, default: Hexx::Service }
|
46
|
-
.not_to raise_error
|
47
|
-
end
|
48
|
-
|
49
|
-
it "fails when wrong object given" do
|
50
|
-
expect { described_module.depends_on 1 }.to raise_error TypeError
|
51
|
-
end
|
52
|
-
|
53
|
-
it "fails when blank object given" do
|
54
|
-
expect { described_module.depends_on "" }.to raise_error ArgumentError
|
55
|
-
end
|
56
|
-
|
57
|
-
it "adds dependencies getters" do
|
58
|
-
described_module.depends_on :item, "user"
|
59
|
-
expect(described_module).to respond_to :item
|
60
|
-
expect(described_module).to respond_to :user
|
61
|
-
end
|
62
|
-
|
63
|
-
it "adds dependencies setters" do
|
64
|
-
described_module.depends_on :item, "user"
|
65
|
-
expect(described_module).to respond_to :item=
|
66
|
-
expect(described_module).to respond_to :user=
|
67
|
-
end
|
68
|
-
|
69
|
-
context ":item" do
|
70
|
-
|
71
|
-
before { described_module.depends_on :item }
|
72
|
-
|
73
|
-
it "makes a setter to allow modules" do
|
74
|
-
described_module.item = String
|
75
|
-
expect(described_module.item).to eq String
|
76
|
-
end
|
77
|
-
|
78
|
-
it "makes a setter to require modules" do
|
79
|
-
expect { described_module.item = :String }.to raise_error TypeError
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
context ":item, default: Hexx::Service" do
|
84
|
-
|
85
|
-
before { described_module.depends_on :item, default: Hexx::Service }
|
86
|
-
|
87
|
-
it "sets default value for the item" do
|
88
|
-
expect(described_module.item).to eq Hexx::Service
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
@@ -1,125 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
module Hexx
|
4
|
-
describe Dependable do
|
5
|
-
|
6
|
-
# ==========================================================================
|
7
|
-
# Prepare environment
|
8
|
-
# ==========================================================================
|
9
|
-
|
10
|
-
before { class Test; extend Dependable; end }
|
11
|
-
before { module TestModule; end }
|
12
|
-
before { class TestClass; end }
|
13
|
-
|
14
|
-
let(:described_class) { Test }
|
15
|
-
let(:test_module) { TestModule }
|
16
|
-
let(:test_class) { TestModule }
|
17
|
-
|
18
|
-
after { Hexx.send :remove_const, :TestClass }
|
19
|
-
after { Hexx.send :remove_const, :TestModule }
|
20
|
-
after { Hexx.send :remove_const, :Test }
|
21
|
-
|
22
|
-
# ==========================================================================
|
23
|
-
# Run tests
|
24
|
-
# ==========================================================================
|
25
|
-
|
26
|
-
describe ".depends_on" do
|
27
|
-
|
28
|
-
it "is private" do
|
29
|
-
expect { described_class.depends_on :item }.to raise_error
|
30
|
-
expect { described_class.send :depends_on, :item }.not_to raise_error
|
31
|
-
end
|
32
|
-
|
33
|
-
it "accepts string argument" do
|
34
|
-
expect { described_class.send :depends_on, "item" }.not_to raise_error
|
35
|
-
end
|
36
|
-
|
37
|
-
it "requires non-empty argument" do
|
38
|
-
expect { described_class.send :depends_on, "" }
|
39
|
-
.to raise_error(ArgumentError)
|
40
|
-
end
|
41
|
-
|
42
|
-
it "requires string or symbol" do
|
43
|
-
expect { described_class.send :depends_on, 1 }
|
44
|
-
.to raise_error(TypeError)
|
45
|
-
end
|
46
|
-
|
47
|
-
it "accepts the :default option with class value" do
|
48
|
-
expect { described_class.send :depends_on, :item, default: test_class }
|
49
|
-
.not_to raise_error
|
50
|
-
end
|
51
|
-
|
52
|
-
it "accepts the :default option with module value" do
|
53
|
-
expect { described_class.send :depends_on, :item, default: test_module }
|
54
|
-
.not_to raise_error
|
55
|
-
end
|
56
|
-
|
57
|
-
it "accepts the :default option with nil" do
|
58
|
-
expect { described_class.send :depends_on, :item, default: nil }
|
59
|
-
.not_to raise_error
|
60
|
-
end
|
61
|
-
|
62
|
-
it "requires the :default option to be nil, class or module" do
|
63
|
-
expect { described_class.send :depends_on, :item, default: 1 }
|
64
|
-
.to raise_error { TypeError }
|
65
|
-
end
|
66
|
-
|
67
|
-
context "with a default implementation" do
|
68
|
-
|
69
|
-
before { described_class.send :depends_on, :item, default: test_class }
|
70
|
-
subject { described_class.new }
|
71
|
-
|
72
|
-
it "declares a getter" do
|
73
|
-
expect(subject).to respond_to :item
|
74
|
-
end
|
75
|
-
|
76
|
-
it "declares a setter" do
|
77
|
-
expect(subject).to respond_to :item=
|
78
|
-
expect { subject.item = described_class }
|
79
|
-
.to change { subject.item }.to described_class
|
80
|
-
end
|
81
|
-
|
82
|
-
it "makes a setter to require module or class" do
|
83
|
-
expect { subject.item = 1 }.to raise_error { TypeError }
|
84
|
-
end
|
85
|
-
|
86
|
-
it "sets implementation by default" do
|
87
|
-
expect(subject.item).to eq test_class
|
88
|
-
end
|
89
|
-
|
90
|
-
it "resets implementation to default" do
|
91
|
-
expect { subject.item = nil }.not_to change { subject.item }
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
context "without a default implementation" do
|
96
|
-
|
97
|
-
before { described_class.send :depends_on, :item }
|
98
|
-
subject { described_class.new }
|
99
|
-
|
100
|
-
it "declares a getter" do
|
101
|
-
expect(subject).to respond_to :item
|
102
|
-
end
|
103
|
-
|
104
|
-
it "declares a setter" do
|
105
|
-
expect(subject).to respond_to :item=
|
106
|
-
subject.item = test_class
|
107
|
-
expect(subject.item).to be test_class
|
108
|
-
end
|
109
|
-
|
110
|
-
it "makes a setter to require module or class" do
|
111
|
-
expect { subject.item = 1 }.to raise_error(TypeError)
|
112
|
-
end
|
113
|
-
|
114
|
-
it "fails before the dependency not implemented" do
|
115
|
-
expect { subject.item }.to raise_error(NotImplementedError)
|
116
|
-
end
|
117
|
-
|
118
|
-
it "fails when the dependency implementation resets" do
|
119
|
-
subject.item = test_class
|
120
|
-
expect { subject.item = nil }.to raise_error(NotImplementedError)
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
@@ -1,96 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
module Hexx
|
5
|
-
describe Helpers::Exceptions do
|
6
|
-
|
7
|
-
before { class Test; include Helpers::Exceptions; end }
|
8
|
-
after { Hexx.send :remove_const, :Test }
|
9
|
-
|
10
|
-
let(:service_invalid) { Hexx::ServiceInvalid }
|
11
|
-
let(:message) { Hexx::Message.new type: "error", text: "text" }
|
12
|
-
let(:described_class) { Test }
|
13
|
-
subject { described_class.new }
|
14
|
-
|
15
|
-
it "includes Messages" do
|
16
|
-
expect(described_class).to include Helpers::Messages
|
17
|
-
end
|
18
|
-
|
19
|
-
describe ".raises" do
|
20
|
-
|
21
|
-
it "declares the specific StandardError exception(s)" do
|
22
|
-
described_class.send :raises, :TestException
|
23
|
-
exception = described_class.const_get :TestException
|
24
|
-
expect(exception.new).to be_kind_of StandardError
|
25
|
-
end
|
26
|
-
|
27
|
-
it "accepts a list of values" do
|
28
|
-
expect { described_class.send :raises, :One, :Two }.not_to raise_error
|
29
|
-
expect(described_class.const_defined? :One).to be_truthy
|
30
|
-
expect(described_class.const_defined? :Two).to be_truthy
|
31
|
-
end
|
32
|
-
|
33
|
-
it "accepts an array of values" do
|
34
|
-
expect { described_class.send :raises, %w(One Two) }.not_to raise_error
|
35
|
-
expect(described_class.const_defined? :One).to be_truthy
|
36
|
-
expect(described_class.const_defined? :Two).to be_truthy
|
37
|
-
end
|
38
|
-
|
39
|
-
it "requires value" do
|
40
|
-
expect { described_class.send :raises }.to raise_error ArgumentError
|
41
|
-
end
|
42
|
-
|
43
|
-
it "fails if non-string or non-symbol value given" do
|
44
|
-
expect { described_class.send :raises, 1 }.to raise_error TypeError
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe "#on_error" do
|
49
|
-
|
50
|
-
it "fails with ServiceInvalid" do
|
51
|
-
expect { subject.on_error [message] }.to raise_error service_invalid
|
52
|
-
end
|
53
|
-
|
54
|
-
it "adds errors to the service" do
|
55
|
-
begin; subject.on_error [message]; rescue; end
|
56
|
-
expect(subject.errors.messages).to eq(base: ["text"])
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe "#escape" do
|
61
|
-
|
62
|
-
it "yields a block" do
|
63
|
-
value = "Hello!"
|
64
|
-
result = subject.escape { value }
|
65
|
-
expect(result).to eq value
|
66
|
-
end
|
67
|
-
|
68
|
-
context "when a block raises ServiceInvalid error" do
|
69
|
-
|
70
|
-
let!(:exception) { service_invalid.new(subject) }
|
71
|
-
|
72
|
-
it "re-raises the exception" do
|
73
|
-
expect { subject.escape { fail exception } }
|
74
|
-
.to raise_error { exception }
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
context "when a block raises StandardError" do
|
79
|
-
|
80
|
-
let(:run) { subject.escape { fail "text" } }
|
81
|
-
|
82
|
-
it "re-raises the ServiceInvalid" do
|
83
|
-
expect { run }.to raise_error service_invalid
|
84
|
-
end
|
85
|
-
|
86
|
-
it "adds error to the messages" do
|
87
|
-
begin
|
88
|
-
run
|
89
|
-
rescue => err
|
90
|
-
expect(err.messages).to contain_exactly message
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|