light-services 0.5.4 → 2.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/config/rubocop_linter_action.yml +4 -0
- data/.github/workflows/ci.yml +63 -0
- data/.gitignore +3 -4
- data/.rspec +1 -0
- data/.rubocop.yml +22 -8
- data/CHANGELOG.md +1 -0
- data/CODE_OF_CONDUCT.md +55 -30
- data/Gemfile +16 -2
- data/Gemfile.lock +101 -0
- data/LICENSE.txt +1 -1
- data/README.md +3 -149
- data/Rakefile +2 -2
- data/bin/console +4 -4
- data/lib/light/services.rb +4 -7
- data/lib/light/services/base.rb +127 -27
- data/lib/light/services/base_with_context.rb +32 -0
- data/lib/light/services/class_based_collection/base.rb +88 -0
- data/lib/light/services/class_based_collection/mount.rb +33 -0
- data/lib/light/services/collection/arguments.rb +34 -0
- data/lib/light/services/collection/base.rb +47 -0
- data/lib/light/services/collection/outputs.rb +16 -0
- data/lib/light/services/config.rb +63 -0
- data/lib/light/services/exceptions.rb +3 -2
- data/lib/light/services/messages.rb +77 -34
- data/lib/light/services/settings/argument.rb +50 -0
- data/lib/light/services/settings/output.rb +34 -0
- data/lib/light/services/settings/step.rb +62 -0
- data/lib/light/services/version.rb +1 -1
- data/light-services.gemspec +21 -24
- metadata +34 -127
- data/.codeclimate.yml +0 -16
- data/.ruby-gemset +0 -1
- data/.travis.yml +0 -29
- data/Appraisals +0 -21
- data/gemfiles/rails_4_0.gemfile +0 -7
- data/gemfiles/rails_4_0.gemfile.lock +0 -115
- data/gemfiles/rails_4_1.gemfile +0 -7
- data/gemfiles/rails_4_1.gemfile.lock +0 -119
- data/gemfiles/rails_4_2.gemfile +0 -7
- data/gemfiles/rails_4_2.gemfile.lock +0 -146
- data/gemfiles/rails_5_0.gemfile +0 -7
- data/gemfiles/rails_5_0.gemfile.lock +0 -150
- data/gemfiles/rails_5_1.gemfile +0 -7
- data/gemfiles/rails_5_1.gemfile.lock +0 -150
- data/lib/light/services/callbacks.rb +0 -54
- data/lib/light/services/outputs.rb +0 -70
- data/lib/light/services/parameters.rb +0 -96
@@ -1,54 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Light
|
4
|
-
module Services
|
5
|
-
module Callbacks
|
6
|
-
def self.included(base)
|
7
|
-
base.extend ClassMethods
|
8
|
-
base.class_eval do
|
9
|
-
class << self
|
10
|
-
attr_accessor :callbacks
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def run_callbacks(type, options = {})
|
18
|
-
callbacks_by(type).each do |callback|
|
19
|
-
break if !success? && !options[:force_run]
|
20
|
-
send(callback[:method_name])
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def callbacks_by(type)
|
25
|
-
all_callbacks.select { |callback| callback[:type] == type }
|
26
|
-
end
|
27
|
-
|
28
|
-
def all_callbacks
|
29
|
-
return @_all_callbacks if defined?(@_all_callbacks)
|
30
|
-
@_all_callbacks = self.class.ancestors.select { |klass| klass.ancestors.include?(::Light::Services::Base) }
|
31
|
-
.map(&:callbacks).compact.reverse.flatten.uniq
|
32
|
-
end
|
33
|
-
|
34
|
-
module ClassMethods
|
35
|
-
def before(method_name)
|
36
|
-
set_callback(:before, method_name)
|
37
|
-
end
|
38
|
-
|
39
|
-
def after(method_name)
|
40
|
-
set_callback(:after, method_name)
|
41
|
-
end
|
42
|
-
|
43
|
-
def finally(method_name)
|
44
|
-
set_callback(:finally, method_name)
|
45
|
-
end
|
46
|
-
|
47
|
-
def set_callback(type, method_name)
|
48
|
-
self.callbacks ||= []
|
49
|
-
self.callbacks << { type: type, method_name: method_name }
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Light
|
4
|
-
module Services
|
5
|
-
module Outputs
|
6
|
-
def self.included(base)
|
7
|
-
base.extend ClassMethods
|
8
|
-
base.class_eval do
|
9
|
-
class << self
|
10
|
-
attr_accessor :outputs
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
# Getters
|
16
|
-
attr_reader :outputs
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
# Setters
|
21
|
-
attr_writer :outputs
|
22
|
-
|
23
|
-
def initialize_outputs
|
24
|
-
self.outputs = {}
|
25
|
-
|
26
|
-
all_outputs.each do |options|
|
27
|
-
store_output(options)
|
28
|
-
end
|
29
|
-
|
30
|
-
generate_outputs_methods
|
31
|
-
end
|
32
|
-
|
33
|
-
def all_outputs
|
34
|
-
return @_all_outputs if defined?(@_all_outputs)
|
35
|
-
@_all_outputs = self.class.ancestors.select { |klass| klass.ancestors.include?(::Light::Services::Base) }
|
36
|
-
.map(&:outputs).compact.flatten.uniq
|
37
|
-
end
|
38
|
-
|
39
|
-
def store_output(options)
|
40
|
-
output_name = options[:name]
|
41
|
-
output_value = options[:value]
|
42
|
-
|
43
|
-
outputs[output_name] = output_value
|
44
|
-
end
|
45
|
-
|
46
|
-
def generate_outputs_methods
|
47
|
-
outputs.keys.each do |output_name|
|
48
|
-
define_singleton_method output_name do
|
49
|
-
outputs[output_name]
|
50
|
-
end
|
51
|
-
|
52
|
-
define_singleton_method "#{output_name}=" do |value|
|
53
|
-
outputs[output_name] = value
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
module ClassMethods
|
59
|
-
def output(name, value = nil, options = {})
|
60
|
-
self.outputs ||= []
|
61
|
-
self.outputs << {
|
62
|
-
name: name,
|
63
|
-
value: value,
|
64
|
-
public: options.fetch(:private, false)
|
65
|
-
}
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
@@ -1,96 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Light
|
4
|
-
module Services
|
5
|
-
module Parameters
|
6
|
-
def self.included(base)
|
7
|
-
base.extend ClassMethods
|
8
|
-
base.class_eval do
|
9
|
-
class << self
|
10
|
-
attr_accessor :parameters
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
# Getters
|
16
|
-
attr_reader :parameters
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
# Setters
|
21
|
-
attr_writer :parameters
|
22
|
-
|
23
|
-
def initialize_params
|
24
|
-
self.parameters = {}
|
25
|
-
|
26
|
-
all_parameters.each do |options|
|
27
|
-
validate_parameter(options)
|
28
|
-
store_parameter(options)
|
29
|
-
end
|
30
|
-
|
31
|
-
generate_parameters_methods
|
32
|
-
end
|
33
|
-
|
34
|
-
def all_parameters
|
35
|
-
return @_all_parameters if defined?(@_all_parameters)
|
36
|
-
@_all_parameters = self.class.ancestors.select { |klass| klass.ancestors.include?(::Light::Services::Base) }
|
37
|
-
.map(&:parameters).compact.flatten.uniq
|
38
|
-
end
|
39
|
-
|
40
|
-
def validate_parameter(options)
|
41
|
-
if parameter_required?(options)
|
42
|
-
raise Light::Services::ParamRequired, "Parameter \"#{options[:name]}\" is required"
|
43
|
-
end
|
44
|
-
|
45
|
-
return unless parameter_wrong_type?(options)
|
46
|
-
|
47
|
-
raise Light::Services::ParamType, "Type of \"#{options[:name]}\" must be \"#{options[:type]}\""
|
48
|
-
end
|
49
|
-
|
50
|
-
def parameter_required?(options)
|
51
|
-
!args.key?(options[:name]) && options[:required] && !options[:allow_nil]
|
52
|
-
end
|
53
|
-
|
54
|
-
def parameter_wrong_type?(options)
|
55
|
-
value = args[options[:name]]
|
56
|
-
|
57
|
-
wrong_type = options[:type] && !options[:type].include?(value.class)
|
58
|
-
not_allow_nil = !options[:allow_nil] || (options[:allow_nil] && !value.nil?)
|
59
|
-
|
60
|
-
wrong_type && not_allow_nil
|
61
|
-
end
|
62
|
-
|
63
|
-
def store_parameter(options)
|
64
|
-
parameter_name = options[:name]
|
65
|
-
parameter_value = args[parameter_name]
|
66
|
-
|
67
|
-
parameters[parameter_name] = parameter_value
|
68
|
-
end
|
69
|
-
|
70
|
-
def generate_parameters_methods
|
71
|
-
parameters.keys.each do |parameter_name|
|
72
|
-
define_singleton_method parameter_name do
|
73
|
-
parameters[parameter_name]
|
74
|
-
end
|
75
|
-
|
76
|
-
define_singleton_method "#{parameter_name}=" do |value|
|
77
|
-
parameters[parameter_name] = value
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
module ClassMethods
|
83
|
-
def param(name, options = {})
|
84
|
-
self.parameters ||= []
|
85
|
-
self.parameters << {
|
86
|
-
name: name,
|
87
|
-
required: options.fetch(:required, true),
|
88
|
-
public: options.fetch(:private, false),
|
89
|
-
type: [*options[:type]].compact,
|
90
|
-
allow_nil: options.fetch(:allow_nil, false)
|
91
|
-
}
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|