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
@@ -1,48 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
module Hexx
|
5
|
-
describe Helpers::Messages do
|
6
|
-
|
7
|
-
before { class Test; include Helpers::Messages; end }
|
8
|
-
subject { Test.new }
|
9
|
-
after { Hexx.send :remove_const, :Test }
|
10
|
-
|
11
|
-
describe "#t" do
|
12
|
-
|
13
|
-
let(:scope) { %w(activemodel messages models hexx/test) }
|
14
|
-
let(:traslation) { I18n.t(:text, scope: scope, name: "name") }
|
15
|
-
|
16
|
-
it "translates symbols in the service scope" do
|
17
|
-
expect(subject.t(:text, name: "name")).to eq traslation
|
18
|
-
end
|
19
|
-
|
20
|
-
it "doesn't translate the string" do
|
21
|
-
expect(subject.t("text")).to eq "text"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "#messages" do
|
26
|
-
|
27
|
-
it "returns an array" do
|
28
|
-
expect(subject.messages).to be_kind_of Array
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe "#add_message" do
|
33
|
-
|
34
|
-
before { subject.add_message :info, :text }
|
35
|
-
let(:message) { subject.messages.first }
|
36
|
-
|
37
|
-
it "adds a new message" do
|
38
|
-
expect(message).to be_kind_of Hexx::Message
|
39
|
-
expect(message.type).to eq "info"
|
40
|
-
end
|
41
|
-
|
42
|
-
it "translates a symbol" do
|
43
|
-
translation = subject.t :text
|
44
|
-
expect(message.text).to eq translation
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,96 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
module Hexx
|
5
|
-
describe Helpers::Parameters do
|
6
|
-
|
7
|
-
before { class Test; include Helpers::Parameters; end }
|
8
|
-
let(:described_class) { Test }
|
9
|
-
after { Hexx.send :remove_const, :Test }
|
10
|
-
|
11
|
-
describe "#params" do
|
12
|
-
|
13
|
-
subject { described_class.new }
|
14
|
-
|
15
|
-
it "is defined" do
|
16
|
-
expect(subject).to respond_to :params
|
17
|
-
end
|
18
|
-
|
19
|
-
it "has no setter" do
|
20
|
-
expect(subject).not_to respond_to :params=
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe ".new" do
|
25
|
-
|
26
|
-
it "accepts parameters" do
|
27
|
-
expect { described_class.new name: "name" }.not_to raise_error
|
28
|
-
end
|
29
|
-
|
30
|
-
it "doesn't require parameters" do
|
31
|
-
expect { described_class.new }.not_to raise_error
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe ".allow_params" do
|
36
|
-
|
37
|
-
it "is defined" do
|
38
|
-
expect(described_class).to respond_to(:allow_params)
|
39
|
-
end
|
40
|
-
|
41
|
-
it "accepts one argument" do
|
42
|
-
expect { described_class.send :allow_params, :name }
|
43
|
-
.not_to raise_error
|
44
|
-
end
|
45
|
-
|
46
|
-
it "accepts a list of arguments" do
|
47
|
-
expect { described_class.send :allow_params, :name, :type }
|
48
|
-
.not_to raise_error
|
49
|
-
end
|
50
|
-
|
51
|
-
it "accepts an array of arguments" do
|
52
|
-
expect { described_class.send :allow_params, %w(name type) }
|
53
|
-
.not_to raise_error
|
54
|
-
end
|
55
|
-
|
56
|
-
it "requires strings or symbols" do
|
57
|
-
expect { described_class.send :allow_params, 1 }
|
58
|
-
.to raise_error SyntaxError
|
59
|
-
end
|
60
|
-
|
61
|
-
it "requires non-empty values" do
|
62
|
-
expect { described_class.send :allow_params, "" }
|
63
|
-
.to raise_error ArgumentError
|
64
|
-
end
|
65
|
-
|
66
|
-
it "requires values" do
|
67
|
-
expect { described_class.send :allow_params }
|
68
|
-
.to raise_error ArgumentError
|
69
|
-
end
|
70
|
-
|
71
|
-
context "with valid argument" do
|
72
|
-
|
73
|
-
before { described_class.send :allow_params, :name }
|
74
|
-
subject { described_class.new name: "name" }
|
75
|
-
|
76
|
-
it "allows initialization of the parameter" do
|
77
|
-
expect(subject.params).to eq("name" => "name")
|
78
|
-
end
|
79
|
-
|
80
|
-
it "defines private getter for the parameter" do
|
81
|
-
expect(described_class.private_instance_methods)
|
82
|
-
.to be_include :name
|
83
|
-
expect { subject.params["name"] = "new" }
|
84
|
-
.to change { subject.send :name }.to "new"
|
85
|
-
end
|
86
|
-
|
87
|
-
it "defines private setter for the parameter" do
|
88
|
-
expect(described_class.private_instance_methods)
|
89
|
-
.to be_include :name=
|
90
|
-
expect { subject.send :name=, "new" }
|
91
|
-
.to change { subject.params["name"] }.to "new"
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
module Hexx
|
5
|
-
describe Helpers::Validations do
|
6
|
-
|
7
|
-
before { class Test; include Helpers::Validations; 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 ActiveModel::Validations" do
|
16
|
-
expect(described_class).to include ActiveModel::Validations
|
17
|
-
end
|
18
|
-
|
19
|
-
describe "#validate!" do
|
20
|
-
|
21
|
-
it "passes when service is valid" do
|
22
|
-
allow(subject).to receive(:valud?).and_return true
|
23
|
-
expect { subject.validate! }.not_to raise_error
|
24
|
-
end
|
25
|
-
|
26
|
-
it "fails when service is invalid" do
|
27
|
-
allow(subject).to receive(:valid?).and_return false
|
28
|
-
expect { subject.validate! }.to raise_error service_invalid
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
data/spec/hexx/message_spec.rb
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
module Hexx
|
4
|
-
describe Message do
|
5
|
-
|
6
|
-
describe ".new" do
|
7
|
-
|
8
|
-
subject { Message }
|
9
|
-
|
10
|
-
it "requires type" do
|
11
|
-
expect { subject.new text: "" }.to raise_error
|
12
|
-
end
|
13
|
-
|
14
|
-
it "requires text" do
|
15
|
-
expect { subject.new type: "" }.to raise_error
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe "#type" do
|
20
|
-
|
21
|
-
subject { Message.new type: "info", text: "text" }
|
22
|
-
|
23
|
-
it "returns message type" do
|
24
|
-
expect(subject.type).to eq "info"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe "#text" do
|
29
|
-
|
30
|
-
subject { Message.new type: "info", text: "text" }
|
31
|
-
|
32
|
-
it "returns message text" do
|
33
|
-
expect(subject.text).to eq "text"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe "#==" do
|
38
|
-
|
39
|
-
let!(:params) { { type: "info", text: "text" } }
|
40
|
-
|
41
|
-
it "returns true if type and text of two messages are the same" do
|
42
|
-
expect(Message.new params).to eq(Message.new params)
|
43
|
-
end
|
44
|
-
|
45
|
-
it "returns false if types of two messages are different" do
|
46
|
-
expect(Message.new params)
|
47
|
-
.not_to eq(Message.new params.merge(type: "error"))
|
48
|
-
end
|
49
|
-
|
50
|
-
it "returns false if texts of two messages are different" do
|
51
|
-
expect(Message.new params)
|
52
|
-
.not_to eq(Message.new params.merge(text: "another"))
|
53
|
-
end
|
54
|
-
|
55
|
-
it "returns false when a message compares to non-message" do
|
56
|
-
expect(Message.new params).not_to eq("text")
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe "#<=>" do
|
61
|
-
|
62
|
-
let!(:aa) { Message.new type: "a", text: "a" }
|
63
|
-
let!(:ab) { Message.new type: "a", text: "b" }
|
64
|
-
let!(:ba) { Message.new type: "b", text: "a" }
|
65
|
-
|
66
|
-
it "orders messages by type" do
|
67
|
-
expect(aa < ba).to be_truthy
|
68
|
-
end
|
69
|
-
|
70
|
-
it "orders messages by text" do
|
71
|
-
expect(aa < ab).to be_truthy
|
72
|
-
end
|
73
|
-
|
74
|
-
it "orders messages first by type" do
|
75
|
-
expect(ab < ba).to be_truthy
|
76
|
-
end
|
77
|
-
|
78
|
-
it "fails when compared with non-message" do
|
79
|
-
expect { ab < "" }.to raise_error
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
data/spec/hexx/name_spec.rb
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
module Hexx
|
4
|
-
describe Name do
|
5
|
-
|
6
|
-
before { class Test < Name; end }
|
7
|
-
after { Hexx.send :remove_const, :Test }
|
8
|
-
|
9
|
-
let(:object) { double :object }
|
10
|
-
let(:described_class) { Test }
|
11
|
-
subject { described_class.send :new, object, :ua }
|
12
|
-
|
13
|
-
describe "#scope" do
|
14
|
-
|
15
|
-
it "is set by default" do
|
16
|
-
expect(subject.scope).to eq %w(activemodel models hexx/test)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe "#object" do
|
21
|
-
|
22
|
-
it "is set by the initializer" do
|
23
|
-
expect(subject.object).to eq object
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe "#locale" do
|
28
|
-
|
29
|
-
it "can be set by the initializer" do
|
30
|
-
subject = described_class.send :new, object, :ua
|
31
|
-
expect(subject.locale).to eq :ua
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe "#t" do
|
36
|
-
|
37
|
-
it "translates the symbol in current scope and locale" do
|
38
|
-
result = subject.t :text
|
39
|
-
expect(result)
|
40
|
-
.to eq "translation missing: ua.activemodel.models.hexx/test.text"
|
41
|
-
end
|
42
|
-
|
43
|
-
it "returns non-symbols as is" do
|
44
|
-
value = "something"
|
45
|
-
expect(subject.t value).to eq value
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe "#for" do
|
50
|
-
|
51
|
-
it "returns a blank string" do
|
52
|
-
expect(subject.for).to eq ""
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe ".new" do
|
57
|
-
|
58
|
-
it "is private" do
|
59
|
-
expect(described_class.private_methods).to include :new
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe ".for" do
|
64
|
-
|
65
|
-
let(:name) { double for: nil }
|
66
|
-
before { allow(described_class).to receive(:new).and_return name }
|
67
|
-
|
68
|
-
it "constructs the object and calls its #for method" do
|
69
|
-
expect(described_class).to receive(:new).with(object, :ua)
|
70
|
-
expect(name).to receive(:for)
|
71
|
-
described_class.for object, locale: :ua
|
72
|
-
end
|
73
|
-
|
74
|
-
it "sets locale by default" do
|
75
|
-
expect(described_class).to receive(:new).with(object, I18n.locale)
|
76
|
-
described_class.for object
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
data/spec/hexx/null_spec.rb
DELETED
@@ -1,152 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
module Hexx
|
5
|
-
describe Null do
|
6
|
-
|
7
|
-
subject { Null }
|
8
|
-
|
9
|
-
describe ".new" do
|
10
|
-
|
11
|
-
it "constructs itself" do
|
12
|
-
expect(Null.new).to eq Null
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe "arbitrary method" do
|
17
|
-
|
18
|
-
it "is defined" do
|
19
|
-
expect(Null).to respond_to :drag_and_drop
|
20
|
-
end
|
21
|
-
|
22
|
-
it "yields a block" do
|
23
|
-
test = double :test, check: nil
|
24
|
-
expect(test).to receive :check
|
25
|
-
Null.when_fishing { test.check }
|
26
|
-
end
|
27
|
-
|
28
|
-
it "returns itself" do
|
29
|
-
expect(Null.is_an_eagle_owl?).to eq Null
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
it "equals nil" do
|
34
|
-
expect(Null).to eq nil
|
35
|
-
expect(Null).to be_nil
|
36
|
-
end
|
37
|
-
|
38
|
-
it "equals Null" do
|
39
|
-
expect(Null.eq? Null).to be_truthy
|
40
|
-
end
|
41
|
-
|
42
|
-
it "is less than any other object" do
|
43
|
-
expect(Null).to be < -1
|
44
|
-
expect(Null).to be < false
|
45
|
-
expect(Null).to be < true
|
46
|
-
expect(Null).to be < ""
|
47
|
-
end
|
48
|
-
|
49
|
-
it "is falsey" do
|
50
|
-
expect(Null).to be_falsey
|
51
|
-
expect(Null.true?).to be_falsey
|
52
|
-
expect(Null.false?).to be_truthy
|
53
|
-
expect(!Null).to eq true
|
54
|
-
end
|
55
|
-
|
56
|
-
describe "#to_a" do
|
57
|
-
|
58
|
-
it "returns the empty array" do
|
59
|
-
expect(Null.to_a).to eq []
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe "#to_h" do
|
64
|
-
|
65
|
-
it "returns the empty hash" do
|
66
|
-
expect(Null.to_h).to eq({})
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe "#to_s" do
|
71
|
-
|
72
|
-
it "returns the empty string" do
|
73
|
-
expect(Null.to_s).to eq ""
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
describe "#to_i" do
|
78
|
-
|
79
|
-
it "returns zero as an integer" do
|
80
|
-
expect(Null.to_i).to eq 0
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
describe "#to_f" do
|
85
|
-
|
86
|
-
it "returns zero as a float" do
|
87
|
-
expect(Null.to_f).to eq 0.0
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
describe "#to_c" do
|
92
|
-
|
93
|
-
it "returns zero as a complex" do
|
94
|
-
expect(Null.to_c).to eq 0.to_c
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
describe "#to_r" do
|
99
|
-
|
100
|
-
it "returns zero as a rational" do
|
101
|
-
expect(Null.to_r).to eq 0.to_r
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
describe "#^" do
|
106
|
-
|
107
|
-
it "null returns false" do
|
108
|
-
expect(Null ^ Null).to be_falsey
|
109
|
-
end
|
110
|
-
|
111
|
-
it "nil returns false" do
|
112
|
-
expect(Null ^ nil).to be_falsey
|
113
|
-
end
|
114
|
-
|
115
|
-
it "false returns false" do
|
116
|
-
expect(Null ^ false).to be_falsey
|
117
|
-
end
|
118
|
-
|
119
|
-
it "true returns true" do
|
120
|
-
expect(Null ^ true).to be_truthy
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
describe "#&" do
|
125
|
-
|
126
|
-
it "returns false" do
|
127
|
-
[Null, nil, false, true, 1, ""].each do |other|
|
128
|
-
expect(Null & other).to be_falsey
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
describe "#|" do
|
134
|
-
|
135
|
-
it "null returns false" do
|
136
|
-
expect(Null | Null).to be_falsey
|
137
|
-
end
|
138
|
-
|
139
|
-
it "nil returns false" do
|
140
|
-
expect(Null | nil).to be_falsey
|
141
|
-
end
|
142
|
-
|
143
|
-
it "false returns false" do
|
144
|
-
expect(Null | false).to be_falsey
|
145
|
-
end
|
146
|
-
|
147
|
-
it "true returns true" do
|
148
|
-
expect(Null | true).to be_truthy
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|