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
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
folders: # The list of folders to be used by any metric.
|
3
|
+
- lib
|
4
|
+
- app
|
5
|
+
metrics: # The list of allowed metrics. The other metrics are disabled.
|
6
|
+
- cane
|
7
|
+
- churn
|
8
|
+
- flay
|
9
|
+
- flog
|
10
|
+
- reek
|
11
|
+
- roodi
|
12
|
+
- saikuro
|
13
|
+
format: html
|
14
|
+
output: tmp/metric_fu
|
15
|
+
verbose: false
|
@@ -0,0 +1 @@
|
|
1
|
+
---
|
@@ -0,0 +1,24 @@
|
|
1
|
+
---
|
2
|
+
AssignmentInConditionalCheck:
|
3
|
+
CaseMissingElseCheck:
|
4
|
+
ClassLineCountCheck:
|
5
|
+
line_count: 300
|
6
|
+
ClassNameCheck:
|
7
|
+
pattern: !ruby/regexp /^[A-Z][a-zA-Z0-9]*$/
|
8
|
+
ClassVariableCheck:
|
9
|
+
CyclomaticComplexityBlockCheck:
|
10
|
+
complexity: 4
|
11
|
+
CyclomaticComplexityMethodCheck:
|
12
|
+
complexity: 8
|
13
|
+
EmptyRescueBodyCheck:
|
14
|
+
ForLoopCheck:
|
15
|
+
MethodLineCountCheck:
|
16
|
+
line_count: 20
|
17
|
+
MethodNameCheck:
|
18
|
+
pattern: !ruby/regexp /^[\||\^|\&|\!]$|^[_a-z<>=\[|+-\/\*`]+[_a-z0-9_<>=~@\[\]]*[=!\?]?$/
|
19
|
+
ModuleLineCountCheck:
|
20
|
+
line_count: 300
|
21
|
+
ModuleNameCheck:
|
22
|
+
pattern: !ruby/regexp /^[A-Z][a-zA-Z0-9]*$/
|
23
|
+
ParameterNumberCheck:
|
24
|
+
parameter_count: 5
|
@@ -0,0 +1,72 @@
|
|
1
|
+
---
|
2
|
+
# settings added by the 'hexx-suit' module
|
3
|
+
# output: "tmp/rubocop"
|
4
|
+
# format: "html"
|
5
|
+
|
6
|
+
AllCops:
|
7
|
+
Exclude:
|
8
|
+
- '**/db/schema.rb'
|
9
|
+
|
10
|
+
Lint/HandleExceptions:
|
11
|
+
Exclude:
|
12
|
+
- '**/*_spec.rb'
|
13
|
+
|
14
|
+
Lint/RescueException:
|
15
|
+
Exclude:
|
16
|
+
- '**/*_spec.rb'
|
17
|
+
|
18
|
+
Style/AccessorMethodName:
|
19
|
+
Exclude:
|
20
|
+
- '**/*_spec.rb'
|
21
|
+
|
22
|
+
Style/AsciiComments:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Style/ClassAndModuleChildren:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
Style/Documentation:
|
29
|
+
Enabled: false
|
30
|
+
|
31
|
+
Style/EmptyLinesAroundBlockBody:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
Style/EmptyLinesAroundClassBody:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
Style/EmptyLinesAroundMethodBody:
|
38
|
+
Enabled: false
|
39
|
+
|
40
|
+
Style/EmptyLinesAroundModuleBody:
|
41
|
+
Enabled: false
|
42
|
+
|
43
|
+
Style/EmptyLineBetweenDefs:
|
44
|
+
Enabled: false
|
45
|
+
|
46
|
+
Style/FileName:
|
47
|
+
Enabled: false
|
48
|
+
|
49
|
+
Style/RaiseArgs:
|
50
|
+
EnforcedStyle: compact
|
51
|
+
|
52
|
+
Style/SingleLineMethods:
|
53
|
+
Exclude:
|
54
|
+
- '**/*_spec.rb'
|
55
|
+
|
56
|
+
Style/SingleSpaceBeforeFirstArg:
|
57
|
+
Enabled: false
|
58
|
+
|
59
|
+
Style/SpecialGlobalVars:
|
60
|
+
Exclude:
|
61
|
+
- '**/Gemfile'
|
62
|
+
- '**/*.gemspec'
|
63
|
+
|
64
|
+
Style/StringLiterals:
|
65
|
+
EnforcedStyle: double_quotes
|
66
|
+
|
67
|
+
Style/StringLiteralsInInterpolation:
|
68
|
+
EnforcedStyle: double_quotes
|
69
|
+
|
70
|
+
Style/TrivialAccessors:
|
71
|
+
Exclude:
|
72
|
+
- '**/*_spec.rb'
|
@@ -0,0 +1,37 @@
|
|
1
|
+
---
|
2
|
+
# Settings added by the 'hexx-suit' gem
|
3
|
+
output: "tmp/yardstick/output.log"
|
4
|
+
path: "lib/**/*.rb"
|
5
|
+
rules:
|
6
|
+
ApiTag::Presence:
|
7
|
+
enabled: true
|
8
|
+
exclude: []
|
9
|
+
ApiTag::Inclusion:
|
10
|
+
enabled: true
|
11
|
+
exclude: []
|
12
|
+
ApiTag::ProtectedMethod:
|
13
|
+
enabled: true
|
14
|
+
exclude: []
|
15
|
+
ApiTag::PrivateMethod:
|
16
|
+
enabled: false
|
17
|
+
exclude: []
|
18
|
+
ExampleTag:
|
19
|
+
enabled: true
|
20
|
+
exclude: []
|
21
|
+
ReturnTag:
|
22
|
+
enabled: true
|
23
|
+
exclude: []
|
24
|
+
Summary::Presence:
|
25
|
+
enabled: true
|
26
|
+
exclude: []
|
27
|
+
Summary::Length:
|
28
|
+
enabled: true
|
29
|
+
exclude: []
|
30
|
+
Summary::Delimiter:
|
31
|
+
enabled: true
|
32
|
+
exclude: []
|
33
|
+
Summary::SingleLine:
|
34
|
+
enabled: true
|
35
|
+
exclude: []
|
36
|
+
threshold: 100
|
37
|
+
verbose: false
|
@@ -0,0 +1,27 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
require "hexx-services/version"
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
|
6
|
+
gem.name = "hexx-services"
|
7
|
+
gem.version = Hexx::Services::VERSION.dup
|
8
|
+
gem.author = "Andrew Kozin"
|
9
|
+
gem.email = "andrew.kozin@gmail.com"
|
10
|
+
gem.homepage = "https://github.com/nepalez/hexx-services"
|
11
|
+
gem.summary = "Service Objects for application domain layer"
|
12
|
+
gem.license = "MIT"
|
13
|
+
|
14
|
+
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
15
|
+
gem.test_files = Dir["spec/**/*.rb"]
|
16
|
+
gem.extra_rdoc_files = Dir["README.md", "LICENSE"]
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
|
19
|
+
gem.required_ruby_version = "~> 2.1"
|
20
|
+
|
21
|
+
gem.add_runtime_dependency "attestor", "~> 2.2"
|
22
|
+
gem.add_runtime_dependency "eigindir", "~> 0.0"
|
23
|
+
gem.add_runtime_dependency "informator", "~> 0.0"
|
24
|
+
|
25
|
+
gem.add_development_dependency "hexx-rspec", "~> 0.4"
|
26
|
+
|
27
|
+
end # Gem::Specification
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "attestor"
|
4
|
+
require "eigindir"
|
5
|
+
require "informator"
|
6
|
+
|
7
|
+
# Shared namespace for hexx gems collections
|
8
|
+
#
|
9
|
+
module Hexx
|
10
|
+
|
11
|
+
# Defines the base class for domain service objects
|
12
|
+
#
|
13
|
+
module Services
|
14
|
+
|
15
|
+
require_relative "hexx-services/patches.rb"
|
16
|
+
require_relative "hexx-services/translation_dsl"
|
17
|
+
require_relative "hexx-services/execution_dsl"
|
18
|
+
require_relative "hexx-services/dependencies_dsl"
|
19
|
+
require_relative "hexx-services/base"
|
20
|
+
|
21
|
+
end # module Services
|
22
|
+
|
23
|
+
end # module Hexx
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Hexx::Services
|
4
|
+
|
5
|
+
# The base class for domain service object
|
6
|
+
#
|
7
|
+
class Base
|
8
|
+
|
9
|
+
extend DependenciesDSL
|
10
|
+
include Eigindir, Attestor::Validations, TranslationDSL, ExecutionDSL
|
11
|
+
|
12
|
+
private_class_method :depends_on
|
13
|
+
private_class_method :attribute, :attribute_reader, :attribute_writer
|
14
|
+
private_class_method :validate, :validates
|
15
|
+
|
16
|
+
public :subscribe, :call
|
17
|
+
|
18
|
+
private :execute
|
19
|
+
private :remember, :publish, :publish!
|
20
|
+
private :attributes, :attributes=
|
21
|
+
private :validate, :validate!, :invalid
|
22
|
+
private :translate
|
23
|
+
|
24
|
+
end # class Base
|
25
|
+
|
26
|
+
end # class Hexx::Services
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Hexx::Services
|
4
|
+
|
5
|
+
# The module provides features to declare dependencies of
|
6
|
+
# service objects from other service objects.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# class MyService
|
10
|
+
# extend DSL::DependenciesDSL
|
11
|
+
# depends_on :get_item, GetItem
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# service = MyService.new
|
15
|
+
# service.get_item # => GetItem
|
16
|
+
# service.get_item = FindItem # => FindItem
|
17
|
+
# service.get_item = nil # => GetItem
|
18
|
+
#
|
19
|
+
module DependenciesDSL
|
20
|
+
|
21
|
+
using Patches
|
22
|
+
|
23
|
+
# Declare the dependency with a default value
|
24
|
+
#
|
25
|
+
# @param [Symbol, String] name The name of the dependency
|
26
|
+
# @param [Class] default The default implementation for the dependency
|
27
|
+
#
|
28
|
+
# @raise [TypeError] if default is set to class that is not a service
|
29
|
+
#
|
30
|
+
# @return [Symbol] the name of the dependency
|
31
|
+
#
|
32
|
+
def depends_on(name, default = nil)
|
33
|
+
if default.nil?
|
34
|
+
attr_accessor(name)
|
35
|
+
elsif default.kind_of_service_class?
|
36
|
+
define_method(name) { instance_variable_get(:"@#{ name }") || default }
|
37
|
+
attr_writer name
|
38
|
+
else
|
39
|
+
fail TypeError.new "The #{ default.inspect } is not a service"
|
40
|
+
end
|
41
|
+
|
42
|
+
self
|
43
|
+
end
|
44
|
+
|
45
|
+
end # module DependenciesDSL
|
46
|
+
|
47
|
+
end # module Hexx::Services
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Hexx::Services
|
4
|
+
|
5
|
+
# Module ExecutionDSL includes Informator and provides [#execute] and [#call]
|
6
|
+
# methods on top of it.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# class MyService
|
10
|
+
# include ExecutionDSL
|
11
|
+
#
|
12
|
+
# def execute
|
13
|
+
# publish! :something
|
14
|
+
# end
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
module ExecutionDSL
|
18
|
+
include Informator
|
19
|
+
|
20
|
+
# The method executes the service object catches `:published` and returns
|
21
|
+
# its results. When nothing was published it publishes `:success` event
|
22
|
+
# by itself.
|
23
|
+
#
|
24
|
+
# @return [<type>] <description>
|
25
|
+
#
|
26
|
+
def call
|
27
|
+
events = Array(catch(:published) { execute })
|
28
|
+
return events if events.first.instance_of? Event
|
29
|
+
publish :success
|
30
|
+
end
|
31
|
+
|
32
|
+
# @abstract
|
33
|
+
#
|
34
|
+
# Defines the sequence of commands provided by the service object
|
35
|
+
#
|
36
|
+
# @return [undefined]
|
37
|
+
#
|
38
|
+
def execute
|
39
|
+
end
|
40
|
+
|
41
|
+
end # module DependenciesDSL
|
42
|
+
|
43
|
+
end # module Hexx::Services
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Hexx::Services
|
4
|
+
|
5
|
+
# Module contains local monkey-patches (refinements) to Ruby core classes
|
6
|
+
#
|
7
|
+
module Patches
|
8
|
+
|
9
|
+
refine Class do
|
10
|
+
|
11
|
+
# Converts the name of the class to the conventional pathname
|
12
|
+
#
|
13
|
+
# @example
|
14
|
+
# Test::MyClassName.pathname # => "test/my_class_name"
|
15
|
+
#
|
16
|
+
# @return [String]
|
17
|
+
#
|
18
|
+
def pathname
|
19
|
+
convert = -> item { item.gsub(/([a-z])([A-Z])/, '\1_\2').downcase }
|
20
|
+
name.split("::").map(&convert).join("/")
|
21
|
+
end
|
22
|
+
|
23
|
+
end # refine Class
|
24
|
+
|
25
|
+
refine Object do
|
26
|
+
|
27
|
+
# Checks if an object is kind of service class
|
28
|
+
#
|
29
|
+
# @return [Boolean]
|
30
|
+
#
|
31
|
+
def kind_of_service_class?
|
32
|
+
is_a?(Class) && ancestors.include?(Hexx::Services::Base)
|
33
|
+
end
|
34
|
+
|
35
|
+
end # refine Object
|
36
|
+
|
37
|
+
end # module Patches
|
38
|
+
|
39
|
+
end # module Hexx::Services
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Hexx::Services
|
4
|
+
|
5
|
+
# The module provides features to do translations in the current service's
|
6
|
+
# scope
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# class MyService
|
10
|
+
# include TranslationDSL
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# service = MyService.new
|
14
|
+
# service.translate :foo
|
15
|
+
# # => "translation missing: en.services.my_service.foo"
|
16
|
+
#
|
17
|
+
module TranslationDSL
|
18
|
+
|
19
|
+
using Patches
|
20
|
+
|
21
|
+
# Translates a name in the scope of the current service
|
22
|
+
#
|
23
|
+
# @overload translate(name, options)
|
24
|
+
# Translates a symbolic argument with given options
|
25
|
+
#
|
26
|
+
# @param [Symbol] name
|
27
|
+
# @param [Hash] options
|
28
|
+
#
|
29
|
+
# @return [String]
|
30
|
+
#
|
31
|
+
# @overload translate(name, *)
|
32
|
+
# Stringifies non-symbolic argument
|
33
|
+
#
|
34
|
+
# @param [#to_s] name
|
35
|
+
#
|
36
|
+
# @return [String]
|
37
|
+
#
|
38
|
+
def translate(name, **options)
|
39
|
+
return name.to_s unless name.instance_of? Symbol
|
40
|
+
I18n.t name, options.merge(scope: [:services, self.class.pathname.to_sym])
|
41
|
+
end
|
42
|
+
|
43
|
+
end # module TranslationDSL
|
44
|
+
|
45
|
+
end # module Hexx::Services
|