hexx 7.1.0 → 8.0.0
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 +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/coercible.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Hexx
|
4
|
-
|
5
|
-
# Declares the +attr_coerced+ private class method.
|
6
|
-
#
|
7
|
-
# @example
|
8
|
-
#
|
9
|
-
# require "hexx"
|
10
|
-
# require_relative "attributes/string"
|
11
|
-
#
|
12
|
-
# class User
|
13
|
-
# extend Hexx::Coercible
|
14
|
-
# attr_coerced :name, type: ActiveSupport::Multibyte::Chars
|
15
|
-
# end
|
16
|
-
#
|
17
|
-
# # This will coerce user name with mb chars:
|
18
|
-
# user = User.new name: "Иоанн"
|
19
|
-
# user.name
|
20
|
-
# # => #<ActiveSupport::Multibyte::Chars @wrapped_string = "Иоанн">
|
21
|
-
module Coercible
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
# @!method attr_coerced(*names, options)
|
26
|
-
# Coerced the attribute(s) with given type.
|
27
|
-
# @example (see Hexx::Coercible)
|
28
|
-
# @param [Array<Symbol, String>] names The list of attributes to be coerced.
|
29
|
-
# @param [Hash] options The coercion options.
|
30
|
-
# @option options [Class] :type The class for coercion.
|
31
|
-
def attr_coerced(*names, type:)
|
32
|
-
names.flatten.each { |name| coercion.add self, name, type }
|
33
|
-
end
|
34
|
-
|
35
|
-
# @api hide
|
36
|
-
# The method returns a coercion creator for PORO object only.
|
37
|
-
# To be reloaded for ActiveRecord models
|
38
|
-
# @return [Class] attribute coercion (Hexx::Creators::Coercion by default)
|
39
|
-
def coercion
|
40
|
-
Hexx::Creators::Coercion
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
data/lib/hexx/configurable.rb
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Hexx
|
4
|
-
|
5
|
-
# Contains methods to declare and inject module dependencies.
|
6
|
-
#
|
7
|
-
# Allows to provide DJ framework for the gem.
|
8
|
-
#
|
9
|
-
# @example
|
10
|
-
# # Declare the dependencies for the gem root module
|
11
|
-
#
|
12
|
-
# # lib/my_gem.rb
|
13
|
-
# module MyGem
|
14
|
-
# extend Hexx::Configurable
|
15
|
-
# self.depends_on :get_item, :add_item
|
16
|
-
# self.depends_on :delete_item, default: DeleteItem
|
17
|
-
# end
|
18
|
-
#
|
19
|
-
# # Inject dependencies (as a constant or its name)
|
20
|
-
#
|
21
|
-
# # config/my_gem.rb
|
22
|
-
# MyGem.configure do |config|
|
23
|
-
# config.get_item = AnotherGem::Services::Get
|
24
|
-
# config.add_item
|
25
|
-
# end
|
26
|
-
#
|
27
|
-
# # Use dependency in the module code (models, services, etc.)
|
28
|
-
# # When the dependency hasn't been set, fails with +NotImplementedError+
|
29
|
-
#
|
30
|
-
# MyGem.get_item # => AnotherGem::Services::Get
|
31
|
-
# MyGem.get_item # => DeleteItem
|
32
|
-
# MyGem.add_item # fails with a NotImplementedError
|
33
|
-
module Configurable
|
34
|
-
|
35
|
-
# Yields a block and gives it self
|
36
|
-
#
|
37
|
-
# @example
|
38
|
-
# module MyGem
|
39
|
-
# extend Hexx::Configurable
|
40
|
-
# end
|
41
|
-
#
|
42
|
-
# MyGem.configure do |config|
|
43
|
-
# c # => MyGem
|
44
|
-
# end
|
45
|
-
#
|
46
|
-
# @yield The block.
|
47
|
-
# @yieldparam [Hexx::Configurable] +self+.
|
48
|
-
def configure
|
49
|
-
yield(self)
|
50
|
-
end
|
51
|
-
|
52
|
-
# @!method depends_on(*names, options)
|
53
|
-
# Declares a dependency getter and setter.
|
54
|
-
#
|
55
|
-
# @example
|
56
|
-
# module MyGem
|
57
|
-
# extend Hexx::Configurable
|
58
|
-
# self.depends_on :some_class
|
59
|
-
# end
|
60
|
-
#
|
61
|
-
# MyGem.some_class = String
|
62
|
-
# # => "String"
|
63
|
-
# MyGem.some_class # => String
|
64
|
-
#
|
65
|
-
# MyGem.some_class = "String"
|
66
|
-
# # => "String"
|
67
|
-
# MyGem.some_class # => String
|
68
|
-
#
|
69
|
-
# MyGem.some_class = :String
|
70
|
-
# # => "String"
|
71
|
-
# MyGem.some_class # => String
|
72
|
-
#
|
73
|
-
# @example Dependencies can be declared by a plain list of names
|
74
|
-
# module MyGem
|
75
|
-
# extend Hexx::Configurable
|
76
|
-
# self.depends_on :some_class, "another_class"
|
77
|
-
# end
|
78
|
-
#
|
79
|
-
# @example Dependencies can be declared by an array of names
|
80
|
-
# module MyGem
|
81
|
-
# extend Hexx::Configurable
|
82
|
-
# self.depends_on %w(some_class another_class)
|
83
|
-
# end
|
84
|
-
#
|
85
|
-
# @example A dependency can have default implementation
|
86
|
-
# module MyGem
|
87
|
-
# extend Hexx::Configurable
|
88
|
-
# self.depends_on :item, default: Item
|
89
|
-
# end
|
90
|
-
#
|
91
|
-
# @param [Array<String, Symbol>] names The list of names for dependencies.
|
92
|
-
# @param [Hash] options The list of options for dependency declaration.
|
93
|
-
# @option options [Module, nil] :default (nil) The default implementation
|
94
|
-
# for the dependency.
|
95
|
-
def depends_on(*names, default: nil)
|
96
|
-
names.flatten.each do |name|
|
97
|
-
Creators::ModuleDependency.add self, name, default
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
data/lib/hexx/creators/base.rb
DELETED
@@ -1,103 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Hexx
|
4
|
-
|
5
|
-
# @api hide
|
6
|
-
# The module contains classes that adds specific attributes
|
7
|
-
# to given classes or modules.
|
8
|
-
module Creators
|
9
|
-
|
10
|
-
# @api hide
|
11
|
-
# @abstract
|
12
|
-
# The base class for attribute injection.
|
13
|
-
#
|
14
|
-
# The objects of the class validates its parameters and adds
|
15
|
-
# attribute's getter and setter into the target class or module.
|
16
|
-
class Base < Struct.new(:target, :name)
|
17
|
-
|
18
|
-
# @api hide
|
19
|
-
# @!method add(target, name)
|
20
|
-
# Injects an attribute to the target class.
|
21
|
-
#
|
22
|
-
# @param [Module] target The class or module to inject the attribute to.
|
23
|
-
# @param [String, Symbol] name The name of the attribute.
|
24
|
-
# @raise (see Hexx::Creators::Base#validate)
|
25
|
-
# @return [Hexx::Creators::Base] the base class object.
|
26
|
-
def self.add(*args)
|
27
|
-
new(*args).validate.add_getter.add_setter
|
28
|
-
end
|
29
|
-
|
30
|
-
# @api hide
|
31
|
-
# @!attribute target
|
32
|
-
# The class to inject the attribute to
|
33
|
-
# @return [Class] the target for the injection
|
34
|
-
|
35
|
-
# @api hide
|
36
|
-
# @!attribute name
|
37
|
-
# The name of the attribute to be created in a target class
|
38
|
-
# @return [Class] the name of the attribute
|
39
|
-
|
40
|
-
# @api hide
|
41
|
-
# Validates parameters of the dependency declaration.
|
42
|
-
#
|
43
|
-
# @raise (see Hexx::Creators::Base#check_target)
|
44
|
-
# @raise (see Hexx::Creators::Base#check_name_type)
|
45
|
-
# @raise (see Hexx::Creators::Base#check_name_value)
|
46
|
-
# @return [Hexx::Creators::Base] +self+
|
47
|
-
def validate
|
48
|
-
check_target
|
49
|
-
check_name_type
|
50
|
-
check_name_value
|
51
|
-
self
|
52
|
-
end
|
53
|
-
|
54
|
-
# @api hide
|
55
|
-
# Adds the parameter getter to the +target+ instance
|
56
|
-
# @return [Hexx::Creators::Base] +self+
|
57
|
-
def add_getter
|
58
|
-
target.class_eval getter
|
59
|
-
self
|
60
|
-
end
|
61
|
-
|
62
|
-
# @api hide
|
63
|
-
# Adds the parameter setter to the +target+ instance
|
64
|
-
# @return [Hexx::Creators::Base] +self+
|
65
|
-
def add_setter
|
66
|
-
target.class_eval setter
|
67
|
-
self
|
68
|
-
end
|
69
|
-
|
70
|
-
private
|
71
|
-
|
72
|
-
# @abstract
|
73
|
-
def getter
|
74
|
-
end
|
75
|
-
|
76
|
-
# @abstract
|
77
|
-
def setter
|
78
|
-
end
|
79
|
-
|
80
|
-
# @api hide
|
81
|
-
# @raise [TypeError] if a target to add the instance parameter to
|
82
|
-
# is not a class.
|
83
|
-
def check_target
|
84
|
-
return if target.is_a? Class
|
85
|
-
fail TypeError.new "#{ target.inspect } is not a class"
|
86
|
-
end
|
87
|
-
|
88
|
-
# @api hide
|
89
|
-
# @raise [TypeError] if the attribute name is neither a string nor symbol.
|
90
|
-
def check_name_type
|
91
|
-
return if name.is_a?(String) || name.is_a?(Symbol)
|
92
|
-
fail TypeError.new "#{ name.inspect } is neither string nor symbol"
|
93
|
-
end
|
94
|
-
|
95
|
-
# @api hide
|
96
|
-
# @raise [AttributeError] it the name is blank.
|
97
|
-
def check_name_value
|
98
|
-
return unless name.to_s == ""
|
99
|
-
fail ArgumentError.new "Dependency should have a name"
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
@@ -1,82 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require_relative "base"
|
3
|
-
|
4
|
-
module Hexx
|
5
|
-
module Creators
|
6
|
-
|
7
|
-
# @api hide
|
8
|
-
# Coerces class attribute getter and setter with given type.
|
9
|
-
#
|
10
|
-
# @example
|
11
|
-
# Coercion.add MyClass, :name, Multibyte::Chars
|
12
|
-
# object = MyClass.new
|
13
|
-
#
|
14
|
-
# object.name = "Ivo"
|
15
|
-
# object.name
|
16
|
-
# # => #<Multibyte::Chars @wrapped_string="Ivo" >
|
17
|
-
class Coercion < Base
|
18
|
-
|
19
|
-
# @api hide
|
20
|
-
# @!scope class
|
21
|
-
# @!method add(target, name, type)
|
22
|
-
# Reloads the Base class initializer by adding the type of the attribute
|
23
|
-
# to coerce with.
|
24
|
-
#
|
25
|
-
# @example (see Hexx::Creators::Coercion)
|
26
|
-
# @param (see Hexx::Creators::Base.add)
|
27
|
-
# @param [Module] type The type of the attribute.
|
28
|
-
# @raise (see Hexx::Creators::Coercion#validate)
|
29
|
-
# @return [Hexx::Creators::Coercion] the coercion object.
|
30
|
-
def initialize(target, name, type)
|
31
|
-
super target, name
|
32
|
-
@type = type
|
33
|
-
end
|
34
|
-
|
35
|
-
# @!attribute type
|
36
|
-
# The type to coerce the attribute with
|
37
|
-
# @return [Class] the type of the attribute
|
38
|
-
attr_accessor :type
|
39
|
-
|
40
|
-
# @api hide
|
41
|
-
# Validates parameters of the coercion declaration.
|
42
|
-
#
|
43
|
-
# Adds validation of the coercion type to the
|
44
|
-
# {Hexx::Helper::Base#validate}.
|
45
|
-
#
|
46
|
-
# @raise (see Hexx::Creators::Base.validate)
|
47
|
-
# @raise (see Hexx::Creators::Coercion#check_type)
|
48
|
-
# @return [Hexx::Creators::Coercion] +self+
|
49
|
-
def validate
|
50
|
-
check_type
|
51
|
-
super
|
52
|
-
end
|
53
|
-
|
54
|
-
private
|
55
|
-
|
56
|
-
# @api hide
|
57
|
-
# The definition of the coerced attribute getter.
|
58
|
-
# To be reloaded for ActiveRecord models.
|
59
|
-
def getter
|
60
|
-
"def #{ name }=(value);
|
61
|
-
@#{ name } = #{ type.name }.new(value);
|
62
|
-
end"
|
63
|
-
end
|
64
|
-
|
65
|
-
# @api hide
|
66
|
-
# The definition of the coerced attribute setter.
|
67
|
-
# To be reloaded for ActiveRecord models.
|
68
|
-
def setter
|
69
|
-
"def #{ name };
|
70
|
-
#{ type.name }.new(@#{ name });
|
71
|
-
end"
|
72
|
-
end
|
73
|
-
|
74
|
-
# @api hide
|
75
|
-
# @raise [TypeError] if type is not a class
|
76
|
-
def check_type
|
77
|
-
return if type.is_a? Class
|
78
|
-
fail TypeError.new "#{ type.inspect } is not a class"
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
@@ -1,87 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require_relative "base"
|
3
|
-
|
4
|
-
module Hexx
|
5
|
-
module Creators
|
6
|
-
|
7
|
-
# @api hide
|
8
|
-
# @abstract
|
9
|
-
# The base class for both instance and module dependencies.
|
10
|
-
class Dependency < Base
|
11
|
-
|
12
|
-
# @api hide
|
13
|
-
# @!scope class
|
14
|
-
# @!method add(target, name, default)
|
15
|
-
# Reloads the Base class initializer by adding the default implementation
|
16
|
-
# for the dependency.
|
17
|
-
#
|
18
|
-
# @param (see Hexx::Creators::Base)
|
19
|
-
# @param [Module] default The default implementation for the dependency.
|
20
|
-
# @raise (see Hexx::Creators::Dependency#validate)
|
21
|
-
# @return [Hexx::Creators::Dependency] the dependency object.
|
22
|
-
def initialize(target, name, default)
|
23
|
-
super target, name
|
24
|
-
@default = default
|
25
|
-
end
|
26
|
-
|
27
|
-
# @!attribute default
|
28
|
-
# The default implementation for the dependency
|
29
|
-
# @return [Module] the default implementation
|
30
|
-
attr_accessor :default
|
31
|
-
|
32
|
-
# @api hide
|
33
|
-
# Validates parameters for the dependency declaration.
|
34
|
-
#
|
35
|
-
# Adds validation of the dependency default implementation to the
|
36
|
-
# {Hexx::Helper::Base#validate}.
|
37
|
-
#
|
38
|
-
# @raise (see Hexx::Creators::Base#validate)
|
39
|
-
# @raise (see Hexx::Creators::Dependency#check_default)
|
40
|
-
# @return [Hexx::Creators::Dependency] +self+
|
41
|
-
def validate
|
42
|
-
check_default
|
43
|
-
super
|
44
|
-
end
|
45
|
-
|
46
|
-
private
|
47
|
-
|
48
|
-
# @api hide
|
49
|
-
# The dependency getter
|
50
|
-
def getter
|
51
|
-
"def #{ name };
|
52
|
-
@#{ name } ||= #{ default_name };
|
53
|
-
return @#{ name } if @#{ name };
|
54
|
-
fail NotImplementedError
|
55
|
-
.new \"DI: #{ target.name }##{ name } not implemented\";
|
56
|
-
end"
|
57
|
-
end
|
58
|
-
|
59
|
-
# @api hide
|
60
|
-
# The dependency setter
|
61
|
-
def setter
|
62
|
-
"def #{ name }=(value);
|
63
|
-
if value.nil? || value.is_a?(Module);
|
64
|
-
@#{ name } = value;
|
65
|
-
#{ name };
|
66
|
-
else;
|
67
|
-
fail TypeError.new \"DI: \#{ value.inspect } is not a module\";
|
68
|
-
end;
|
69
|
-
end"
|
70
|
-
end
|
71
|
-
|
72
|
-
# @api hide
|
73
|
-
# @raise [TypeError] if the default implementation is neither a class,
|
74
|
-
# nor module
|
75
|
-
def check_default
|
76
|
-
return if default.nil? || default.is_a?(Module)
|
77
|
-
fail TypeError.new "#{ default.inspect } is neither a class nor module"
|
78
|
-
end
|
79
|
-
|
80
|
-
# @api hide
|
81
|
-
# Returns the name of the default implementation of the dependency.
|
82
|
-
def default_name
|
83
|
-
@default_name ||= default ? default.name : "nil"
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require_relative "dependency"
|
3
|
-
|
4
|
-
module Hexx
|
5
|
-
module Creators
|
6
|
-
|
7
|
-
# @api hide
|
8
|
-
# Module dependency constructor.
|
9
|
-
#
|
10
|
-
# Adds the dependency to selected module.
|
11
|
-
#
|
12
|
-
# @example
|
13
|
-
# ModuleDependency.add(MyModule, :some_module, DefaultImplementation)
|
14
|
-
#
|
15
|
-
# MyModule.some_module
|
16
|
-
# # => DefaultImplementation
|
17
|
-
#
|
18
|
-
# MyModule.some_module = AnotherImplementation
|
19
|
-
# # => AnotherImplementation
|
20
|
-
#
|
21
|
-
# MyModule.some_module = 1
|
22
|
-
# # fails with #<TypeError @message="1 is not a module" >
|
23
|
-
class ModuleDependency < Dependency
|
24
|
-
|
25
|
-
# @api hide
|
26
|
-
# Adds the dependency to given module
|
27
|
-
# @example (see Hexx::Creators::ModuleDependency)
|
28
|
-
# @param [Module] target The module to declare the dependency of.
|
29
|
-
# @param [String, Symbol] name The name of the dependency.
|
30
|
-
# @param [Module] default The default implementation of the dependency.
|
31
|
-
|
32
|
-
# @api hide
|
33
|
-
# Adds the module dependency getter
|
34
|
-
# @return [ModuleDependency] +self+.
|
35
|
-
def add_getter
|
36
|
-
target.instance_eval getter
|
37
|
-
self
|
38
|
-
end
|
39
|
-
|
40
|
-
# @api hide
|
41
|
-
# Adds the module dependency setter
|
42
|
-
# @return [ModuleDependency] +self+.
|
43
|
-
def add_setter
|
44
|
-
target.instance_eval setter
|
45
|
-
self
|
46
|
-
end
|
47
|
-
|
48
|
-
private
|
49
|
-
|
50
|
-
# @raise [TypeError] if a target to add the dependency is not a module.
|
51
|
-
def check_target
|
52
|
-
return if target.is_a? Module
|
53
|
-
fail TypeError.new "#{ target.inspect } is not a module"
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|