hexx-services 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.coveralls.yml +2 -0
- data/.gitignore +9 -0
- data/.metrics +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +2 -0
- data/.travis.yml +16 -0
- data/.yardopts +3 -0
- data/Gemfile +7 -0
- data/Guardfile +14 -0
- data/LICENSE +21 -0
- data/README.md +121 -0
- data/Rakefile +27 -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/reek.yml +1 -0
- data/config/metrics/roodi.yml +24 -0
- data/config/metrics/rubocop.yml +72 -0
- data/config/metrics/saikuro.yml +3 -0
- data/config/metrics/simplecov.yml +8 -0
- data/config/metrics/yardstick.yml +37 -0
- data/hexx-services.gemspec +27 -0
- data/lib/hexx-services.rb +23 -0
- data/lib/hexx-services/base.rb +26 -0
- data/lib/hexx-services/dependencies_dsl.rb +47 -0
- data/lib/hexx-services/execution_dsl.rb +43 -0
- data/lib/hexx-services/patches.rb +39 -0
- data/lib/hexx-services/translation_dsl.rb +45 -0
- data/lib/hexx-services/version.rb +13 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/unit/base_spec.rb +61 -0
- data/spec/unit/dependencies_dsl_spec.rb +64 -0
- data/spec/unit/execution_dsl_spec.rb +85 -0
- data/spec/unit/patches_spec.rb +53 -0
- data/spec/unit/translation_dsl_spec.rb +44 -0
- metadata +145 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
describe Hexx::Services::Base do
|
4
|
+
|
5
|
+
subject(:service) { described_class.new }
|
6
|
+
|
7
|
+
let(:private_class_methods) { described_class.private_methods }
|
8
|
+
let(:private_methods) { service.private_methods }
|
9
|
+
let(:public_class_methods) { described_class.methods }
|
10
|
+
let(:public_methods) { service.methods }
|
11
|
+
|
12
|
+
it "implements Dependencies DSL" do
|
13
|
+
expect(described_class).to be_kind_of Hexx::Services::DependenciesDSL
|
14
|
+
expect(private_class_methods).to include :depends_on
|
15
|
+
end
|
16
|
+
|
17
|
+
it "implements Translation DSL" do
|
18
|
+
expect(described_class).to include Hexx::Services::TranslationDSL
|
19
|
+
expect(private_methods).to include :translate
|
20
|
+
end
|
21
|
+
|
22
|
+
it "implements Eigindir DSL" do
|
23
|
+
expect(described_class).to include Eigindir
|
24
|
+
|
25
|
+
expect(private_class_methods).to include :attribute
|
26
|
+
expect(private_class_methods).to include :attribute_reader
|
27
|
+
expect(private_class_methods).to include :attribute_writer
|
28
|
+
|
29
|
+
expect(private_methods).to include :attributes
|
30
|
+
expect(private_methods).to include :attributes=
|
31
|
+
end
|
32
|
+
|
33
|
+
it "implements Attestor::Validations DSL" do
|
34
|
+
expect(described_class).to include Attestor::Validations
|
35
|
+
|
36
|
+
expect(private_class_methods).to include :validate
|
37
|
+
expect(private_class_methods).to include :validates
|
38
|
+
|
39
|
+
expect(private_methods).to include :invalid
|
40
|
+
expect(private_methods).to include :validate
|
41
|
+
expect(private_methods).to include :validate!
|
42
|
+
end
|
43
|
+
|
44
|
+
it "implements Informator DSL" do
|
45
|
+
expect(described_class).to include Informator
|
46
|
+
|
47
|
+
expect(public_methods).to include :subscribe
|
48
|
+
|
49
|
+
expect(private_methods).to include :remember
|
50
|
+
expect(private_methods).to include :publish
|
51
|
+
expect(private_methods).to include :publish!
|
52
|
+
end
|
53
|
+
|
54
|
+
it "implements Execution DSL" do
|
55
|
+
expect(described_class).to include Hexx::Services::ExecutionDSL
|
56
|
+
|
57
|
+
expect(public_methods).to include :call
|
58
|
+
expect(private_methods).to include :execute
|
59
|
+
end
|
60
|
+
|
61
|
+
end # describe Hexx::Services::Base
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
describe Hexx::Services::DependenciesDSL do
|
4
|
+
|
5
|
+
let(:klass) { Class.new { extend Hexx::Services::DependenciesDSL } }
|
6
|
+
subject(:dependant) { klass.new }
|
7
|
+
|
8
|
+
describe "#depends_on" do
|
9
|
+
|
10
|
+
subject { klass.depends_on :foo, default }
|
11
|
+
|
12
|
+
shared_examples "declaring a dependency" do
|
13
|
+
let(:injection) { double }
|
14
|
+
|
15
|
+
it "doesn't fail" do
|
16
|
+
expect { subject }.not_to raise_error
|
17
|
+
end
|
18
|
+
|
19
|
+
it "defines the attribute" do
|
20
|
+
subject
|
21
|
+
expect { dependant.foo = injection }
|
22
|
+
.to change { dependant.foo }
|
23
|
+
.from(default)
|
24
|
+
.to(injection)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "resets the attribute to default" do
|
28
|
+
subject
|
29
|
+
dependant.foo = nil
|
30
|
+
expect(dependant.foo).to eq default
|
31
|
+
end
|
32
|
+
|
33
|
+
it "returns itself" do
|
34
|
+
expect(subject).to eq klass
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "when no default is set" do
|
39
|
+
|
40
|
+
let(:default) { nil }
|
41
|
+
it_behaves_like "declaring a dependency"
|
42
|
+
|
43
|
+
end # context
|
44
|
+
|
45
|
+
context "when default is a service" do
|
46
|
+
|
47
|
+
let(:default) { Class.new(Hexx::Services::Base) }
|
48
|
+
it_behaves_like "declaring a dependency"
|
49
|
+
|
50
|
+
end # context
|
51
|
+
|
52
|
+
context "when default is not a service" do
|
53
|
+
|
54
|
+
let(:default) { double }
|
55
|
+
|
56
|
+
it "raises TypeError" do
|
57
|
+
expect { subject }.to raise_error TypeError
|
58
|
+
end
|
59
|
+
|
60
|
+
end # context
|
61
|
+
|
62
|
+
end # describe #depends_on
|
63
|
+
|
64
|
+
end # describe Hexx::Services::DependenciesDSL
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
describe Hexx::Services::ExecutionDSL do
|
4
|
+
|
5
|
+
subject(:executor) { Class.new { include Hexx::Services::ExecutionDSL }.new }
|
6
|
+
|
7
|
+
it { is_expected.to be_kind_of Informator }
|
8
|
+
|
9
|
+
describe "#execute" do
|
10
|
+
|
11
|
+
subject { executor.execute }
|
12
|
+
it "doesn't fail" do
|
13
|
+
expect { subject }.not_to raise_error
|
14
|
+
end
|
15
|
+
|
16
|
+
end # describe #execute
|
17
|
+
|
18
|
+
describe "#call" do
|
19
|
+
|
20
|
+
subject { executor.call }
|
21
|
+
|
22
|
+
let(:event) { Informator::Event.new :error }
|
23
|
+
|
24
|
+
shared_examples "publishing result of #execute" do
|
25
|
+
before { allow(executor).to receive(:execute) { execute } }
|
26
|
+
|
27
|
+
it "calls #execute" do
|
28
|
+
expect(executor).to receive :execute
|
29
|
+
subject
|
30
|
+
end
|
31
|
+
|
32
|
+
it "catches exception" do
|
33
|
+
expect { subject }.not_to raise_error
|
34
|
+
end
|
35
|
+
|
36
|
+
it { is_expected.to contain_exactly event }
|
37
|
+
end
|
38
|
+
|
39
|
+
context "when #execute returns an event" do
|
40
|
+
|
41
|
+
let(:execute) { event }
|
42
|
+
it_behaves_like "publishing result of #execute"
|
43
|
+
|
44
|
+
end # context
|
45
|
+
|
46
|
+
context "when #execute returns an array of events" do
|
47
|
+
|
48
|
+
let(:execute) { [event] }
|
49
|
+
it_behaves_like "publishing result of #execute"
|
50
|
+
|
51
|
+
end # context
|
52
|
+
|
53
|
+
context "when #execute throws :published with an event" do
|
54
|
+
|
55
|
+
let(:execute) { throw :published, event }
|
56
|
+
it_behaves_like "publishing result of #execute"
|
57
|
+
|
58
|
+
end # context
|
59
|
+
|
60
|
+
context "when #execute throws :published with array of events" do
|
61
|
+
|
62
|
+
let(:execute) { throw :published, [event] }
|
63
|
+
it_behaves_like "publishing result of #execute"
|
64
|
+
|
65
|
+
end # context
|
66
|
+
|
67
|
+
context "when #execute throws :published with no events" do
|
68
|
+
|
69
|
+
let(:event) { Informator::Event.new :success }
|
70
|
+
let(:execute) { throw :published, [:event] }
|
71
|
+
it_behaves_like "publishing result of #execute"
|
72
|
+
|
73
|
+
end # context
|
74
|
+
|
75
|
+
context "when #execute returns no events" do
|
76
|
+
|
77
|
+
let(:event) { Informator::Event.new :success }
|
78
|
+
let(:execute) { [:event] }
|
79
|
+
it_behaves_like "publishing result of #execute"
|
80
|
+
|
81
|
+
end # context
|
82
|
+
|
83
|
+
end # describe #call
|
84
|
+
|
85
|
+
end # describe Hexx::Services::ExecutionDSL
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
describe Hexx::Services::Patches do
|
4
|
+
using described_class
|
5
|
+
|
6
|
+
describe "to Class" do
|
7
|
+
|
8
|
+
subject(:klass) { Class.new }
|
9
|
+
|
10
|
+
before { described_class::MyTestClass = klass }
|
11
|
+
after { described_class.send :remove_const, :MyTestClass }
|
12
|
+
|
13
|
+
describe "#pathname" do
|
14
|
+
|
15
|
+
subject { klass.pathname }
|
16
|
+
it { is_expected.to eq "hexx/services/patches/my_test_class" }
|
17
|
+
|
18
|
+
end # describe #pathname
|
19
|
+
|
20
|
+
end # describe Class
|
21
|
+
|
22
|
+
describe "to Object" do
|
23
|
+
|
24
|
+
describe "#kind_of_service_class?" do
|
25
|
+
|
26
|
+
subject { object.kind_of_service_class? }
|
27
|
+
|
28
|
+
context "for ancestor of Hexx::Services::Base" do
|
29
|
+
|
30
|
+
let(:object) { Class.new(Hexx::Services::Base) }
|
31
|
+
it { is_expected.to eql true }
|
32
|
+
|
33
|
+
end # context
|
34
|
+
|
35
|
+
context "for arbitrary class" do
|
36
|
+
|
37
|
+
let(:object) { Class.new }
|
38
|
+
it { is_expected.to eql false }
|
39
|
+
|
40
|
+
end # context
|
41
|
+
|
42
|
+
context "for not a class" do
|
43
|
+
|
44
|
+
let(:object) { double }
|
45
|
+
it { is_expected.to eql false }
|
46
|
+
|
47
|
+
end # context
|
48
|
+
|
49
|
+
end # describe #kind_of_service_class?
|
50
|
+
|
51
|
+
end # describe Object
|
52
|
+
|
53
|
+
end # describe Hexx::Services::Patches
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
describe Hexx::Services::TranslationDSL do
|
4
|
+
|
5
|
+
before do
|
6
|
+
Hexx::MyTestService = Class.new { include Hexx::Services::TranslationDSL }
|
7
|
+
end
|
8
|
+
after { Hexx.send :remove_const, :MyTestService }
|
9
|
+
|
10
|
+
subject(:translator) { Hexx::MyTestService.new }
|
11
|
+
|
12
|
+
describe "#translate" do
|
13
|
+
|
14
|
+
subject { translator.translate name, options }
|
15
|
+
|
16
|
+
let(:options) { { bar: :baz } }
|
17
|
+
|
18
|
+
context "a symbol" do
|
19
|
+
|
20
|
+
let(:name) { :foo }
|
21
|
+
let(:scope) { [:services, :"hexx/my_test_service"] }
|
22
|
+
|
23
|
+
it "translates it" do
|
24
|
+
expect(subject)
|
25
|
+
.to eql "translation missing: en.#{ scope.join(".") }.foo"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "uses options" do
|
29
|
+
expect(I18n).to receive(:t).with name, options.merge(scope: scope)
|
30
|
+
subject
|
31
|
+
end
|
32
|
+
|
33
|
+
end # context
|
34
|
+
|
35
|
+
context "non-symbol" do
|
36
|
+
|
37
|
+
let(:name) { 1 }
|
38
|
+
it { is_expected.to eql "1" }
|
39
|
+
|
40
|
+
end # context
|
41
|
+
|
42
|
+
end # describe #translate
|
43
|
+
|
44
|
+
end # describe Hexx::Services::TranslationDSL
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hexx-services
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Kozin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: attestor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: eigindir
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: informator
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: hexx-rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.4'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.4'
|
69
|
+
description:
|
70
|
+
email: andrew.kozin@gmail.com
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files:
|
74
|
+
- README.md
|
75
|
+
- LICENSE
|
76
|
+
files:
|
77
|
+
- ".coveralls.yml"
|
78
|
+
- ".gitignore"
|
79
|
+
- ".metrics"
|
80
|
+
- ".rspec"
|
81
|
+
- ".rubocop.yml"
|
82
|
+
- ".travis.yml"
|
83
|
+
- ".yardopts"
|
84
|
+
- Gemfile
|
85
|
+
- Guardfile
|
86
|
+
- LICENSE
|
87
|
+
- README.md
|
88
|
+
- Rakefile
|
89
|
+
- config/metrics/STYLEGUIDE
|
90
|
+
- config/metrics/cane.yml
|
91
|
+
- config/metrics/churn.yml
|
92
|
+
- config/metrics/flay.yml
|
93
|
+
- config/metrics/metric_fu.yml
|
94
|
+
- config/metrics/reek.yml
|
95
|
+
- config/metrics/roodi.yml
|
96
|
+
- config/metrics/rubocop.yml
|
97
|
+
- config/metrics/saikuro.yml
|
98
|
+
- config/metrics/simplecov.yml
|
99
|
+
- config/metrics/yardstick.yml
|
100
|
+
- hexx-services.gemspec
|
101
|
+
- lib/hexx-services.rb
|
102
|
+
- lib/hexx-services/base.rb
|
103
|
+
- lib/hexx-services/dependencies_dsl.rb
|
104
|
+
- lib/hexx-services/execution_dsl.rb
|
105
|
+
- lib/hexx-services/patches.rb
|
106
|
+
- lib/hexx-services/translation_dsl.rb
|
107
|
+
- lib/hexx-services/version.rb
|
108
|
+
- spec/spec_helper.rb
|
109
|
+
- spec/unit/base_spec.rb
|
110
|
+
- spec/unit/dependencies_dsl_spec.rb
|
111
|
+
- spec/unit/execution_dsl_spec.rb
|
112
|
+
- spec/unit/patches_spec.rb
|
113
|
+
- spec/unit/translation_dsl_spec.rb
|
114
|
+
homepage: https://github.com/nepalez/hexx-services
|
115
|
+
licenses:
|
116
|
+
- MIT
|
117
|
+
metadata: {}
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - "~>"
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '2.1'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 2.4.6
|
135
|
+
signing_key:
|
136
|
+
specification_version: 4
|
137
|
+
summary: Service Objects for application domain layer
|
138
|
+
test_files:
|
139
|
+
- spec/spec_helper.rb
|
140
|
+
- spec/unit/translation_dsl_spec.rb
|
141
|
+
- spec/unit/execution_dsl_spec.rb
|
142
|
+
- spec/unit/patches_spec.rb
|
143
|
+
- spec/unit/dependencies_dsl_spec.rb
|
144
|
+
- spec/unit/base_spec.rb
|
145
|
+
has_rdoc:
|