light-services 0.4.0 → 0.5.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/.codeclimate.yml +2 -2
- data/.rubocop.yml +9 -1152
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -1
- data/.travis.yml +21 -9
- data/Appraisals +6 -1
- data/Gemfile +2 -0
- data/README.md +109 -6
- data/Rakefile +2 -0
- data/bin/console +1 -0
- data/gemfiles/rails_4_0.gemfile +1 -1
- data/gemfiles/rails_4_0.gemfile.lock +2 -2
- data/gemfiles/rails_4_1.gemfile +1 -1
- data/gemfiles/rails_4_1.gemfile.lock +2 -2
- data/gemfiles/rails_4_2.gemfile +1 -1
- data/gemfiles/rails_4_2.gemfile.lock +2 -2
- data/gemfiles/rails_5_0.gemfile +2 -2
- data/gemfiles/rails_5_0.gemfile.lock +80 -86
- data/gemfiles/rails_5_1.gemfile +7 -0
- data/gemfiles/rails_5_1.gemfile.lock +150 -0
- data/lib/light/services/base.rb +5 -4
- data/lib/light/services/callbacks.rb +18 -15
- data/lib/light/services/exceptions.rb +2 -0
- data/lib/light/services/messages.rb +9 -5
- data/lib/light/services/outputs.rb +64 -0
- data/lib/light/services/parameters.rb +40 -50
- data/lib/light/services/version.rb +3 -1
- data/lib/light/services.rb +3 -1
- data/light-services.gemspec +2 -0
- metadata +7 -4
- data/lib/light/services/variables.rb +0 -38
@@ -0,0 +1,150 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
light-services (0.5.0)
|
5
|
+
rails (> 4.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actioncable (5.1.3)
|
11
|
+
actionpack (= 5.1.3)
|
12
|
+
nio4r (~> 2.0)
|
13
|
+
websocket-driver (~> 0.6.1)
|
14
|
+
actionmailer (5.1.3)
|
15
|
+
actionpack (= 5.1.3)
|
16
|
+
actionview (= 5.1.3)
|
17
|
+
activejob (= 5.1.3)
|
18
|
+
mail (~> 2.5, >= 2.5.4)
|
19
|
+
rails-dom-testing (~> 2.0)
|
20
|
+
actionpack (5.1.3)
|
21
|
+
actionview (= 5.1.3)
|
22
|
+
activesupport (= 5.1.3)
|
23
|
+
rack (~> 2.0)
|
24
|
+
rack-test (~> 0.6.3)
|
25
|
+
rails-dom-testing (~> 2.0)
|
26
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
27
|
+
actionview (5.1.3)
|
28
|
+
activesupport (= 5.1.3)
|
29
|
+
builder (~> 3.1)
|
30
|
+
erubi (~> 1.4)
|
31
|
+
rails-dom-testing (~> 2.0)
|
32
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
33
|
+
activejob (5.1.3)
|
34
|
+
activesupport (= 5.1.3)
|
35
|
+
globalid (>= 0.3.6)
|
36
|
+
activemodel (5.1.3)
|
37
|
+
activesupport (= 5.1.3)
|
38
|
+
activerecord (5.1.3)
|
39
|
+
activemodel (= 5.1.3)
|
40
|
+
activesupport (= 5.1.3)
|
41
|
+
arel (~> 8.0)
|
42
|
+
activesupport (5.1.3)
|
43
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
44
|
+
i18n (~> 0.7)
|
45
|
+
minitest (~> 5.1)
|
46
|
+
tzinfo (~> 1.1)
|
47
|
+
appraisal (2.2.0)
|
48
|
+
bundler
|
49
|
+
rake
|
50
|
+
thor (>= 0.14.0)
|
51
|
+
arel (8.0.0)
|
52
|
+
builder (3.2.3)
|
53
|
+
codeclimate-test-reporter (1.0.8)
|
54
|
+
simplecov (<= 0.13)
|
55
|
+
concurrent-ruby (1.0.5)
|
56
|
+
diff-lcs (1.3)
|
57
|
+
docile (1.1.5)
|
58
|
+
erubi (1.6.1)
|
59
|
+
globalid (0.4.0)
|
60
|
+
activesupport (>= 4.2.0)
|
61
|
+
i18n (0.8.6)
|
62
|
+
json (1.8.6)
|
63
|
+
loofah (2.0.3)
|
64
|
+
nokogiri (>= 1.5.9)
|
65
|
+
mail (2.6.6)
|
66
|
+
mime-types (>= 1.16, < 4)
|
67
|
+
method_source (0.8.2)
|
68
|
+
mime-types (3.1)
|
69
|
+
mime-types-data (~> 3.2015)
|
70
|
+
mime-types-data (3.2016.0521)
|
71
|
+
mini_portile2 (2.2.0)
|
72
|
+
minitest (5.10.3)
|
73
|
+
nio4r (2.1.0)
|
74
|
+
nokogiri (1.8.0)
|
75
|
+
mini_portile2 (~> 2.2.0)
|
76
|
+
rack (2.0.3)
|
77
|
+
rack-test (0.6.3)
|
78
|
+
rack (>= 1.0)
|
79
|
+
rails (5.1.3)
|
80
|
+
actioncable (= 5.1.3)
|
81
|
+
actionmailer (= 5.1.3)
|
82
|
+
actionpack (= 5.1.3)
|
83
|
+
actionview (= 5.1.3)
|
84
|
+
activejob (= 5.1.3)
|
85
|
+
activemodel (= 5.1.3)
|
86
|
+
activerecord (= 5.1.3)
|
87
|
+
activesupport (= 5.1.3)
|
88
|
+
bundler (>= 1.3.0)
|
89
|
+
railties (= 5.1.3)
|
90
|
+
sprockets-rails (>= 2.0.0)
|
91
|
+
rails-dom-testing (2.0.3)
|
92
|
+
activesupport (>= 4.2.0)
|
93
|
+
nokogiri (>= 1.6)
|
94
|
+
rails-html-sanitizer (1.0.3)
|
95
|
+
loofah (~> 2.0)
|
96
|
+
railties (5.1.3)
|
97
|
+
actionpack (= 5.1.3)
|
98
|
+
activesupport (= 5.1.3)
|
99
|
+
method_source
|
100
|
+
rake (>= 0.8.7)
|
101
|
+
thor (>= 0.18.1, < 2.0)
|
102
|
+
rake (10.5.0)
|
103
|
+
rspec (3.6.0)
|
104
|
+
rspec-core (~> 3.6.0)
|
105
|
+
rspec-expectations (~> 3.6.0)
|
106
|
+
rspec-mocks (~> 3.6.0)
|
107
|
+
rspec-core (3.6.0)
|
108
|
+
rspec-support (~> 3.6.0)
|
109
|
+
rspec-expectations (3.6.0)
|
110
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
111
|
+
rspec-support (~> 3.6.0)
|
112
|
+
rspec-mocks (3.6.0)
|
113
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
114
|
+
rspec-support (~> 3.6.0)
|
115
|
+
rspec-support (3.6.0)
|
116
|
+
simplecov (0.11.2)
|
117
|
+
docile (~> 1.1.0)
|
118
|
+
json (~> 1.8)
|
119
|
+
simplecov-html (~> 0.10.0)
|
120
|
+
simplecov-html (0.10.2)
|
121
|
+
sprockets (3.7.1)
|
122
|
+
concurrent-ruby (~> 1.0)
|
123
|
+
rack (> 1, < 3)
|
124
|
+
sprockets-rails (3.2.0)
|
125
|
+
actionpack (>= 4.0)
|
126
|
+
activesupport (>= 4.0)
|
127
|
+
sprockets (>= 3.0.0)
|
128
|
+
thor (0.20.0)
|
129
|
+
thread_safe (0.3.6)
|
130
|
+
tzinfo (1.2.3)
|
131
|
+
thread_safe (~> 0.1)
|
132
|
+
websocket-driver (0.6.5)
|
133
|
+
websocket-extensions (>= 0.1.0)
|
134
|
+
websocket-extensions (0.1.2)
|
135
|
+
|
136
|
+
PLATFORMS
|
137
|
+
ruby
|
138
|
+
|
139
|
+
DEPENDENCIES
|
140
|
+
appraisal (~> 2.1)
|
141
|
+
bundler (~> 1.12)
|
142
|
+
codeclimate-test-reporter
|
143
|
+
light-services!
|
144
|
+
rails (= 5.1.3)
|
145
|
+
rake (~> 10.0)
|
146
|
+
rspec (~> 3.0)
|
147
|
+
simplecov (~> 0.11.2)
|
148
|
+
|
149
|
+
BUNDLED WITH
|
150
|
+
1.15.4
|
data/lib/light/services/base.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Light
|
2
4
|
module Services
|
3
5
|
class Base
|
4
6
|
# Includes
|
5
7
|
include Light::Services::Parameters
|
8
|
+
include Light::Services::Outputs
|
6
9
|
include Light::Services::Callbacks
|
7
10
|
|
8
11
|
# Getters
|
@@ -32,9 +35,7 @@ module Light
|
|
32
35
|
|
33
36
|
class << self
|
34
37
|
def call(args = {})
|
35
|
-
|
36
|
-
service.call
|
37
|
-
service
|
38
|
+
new(args).tap(&:call)
|
38
39
|
end
|
39
40
|
|
40
41
|
alias run call
|
@@ -49,7 +50,7 @@ module Light
|
|
49
50
|
run_callbacks(:before)
|
50
51
|
run if success?
|
51
52
|
run_callbacks(:after) if success?
|
52
|
-
run_callbacks(:finally,
|
53
|
+
run_callbacks(:finally, force_run: true)
|
53
54
|
success?
|
54
55
|
end
|
55
56
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Light
|
2
4
|
module Services
|
3
5
|
module Callbacks
|
@@ -12,32 +14,33 @@ module Light
|
|
12
14
|
|
13
15
|
private
|
14
16
|
|
15
|
-
def run_callbacks(type,
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
callbacks.each do |callback|
|
20
|
-
break if !success? && opts[:break]
|
21
|
-
send(callback[:method])
|
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])
|
22
21
|
end
|
23
22
|
end
|
24
23
|
|
24
|
+
def callbacks_by(type)
|
25
|
+
(self.class.callbacks || []).select { |callback| callback[:type] == type }
|
26
|
+
end
|
27
|
+
|
25
28
|
module ClassMethods
|
26
|
-
def before(
|
27
|
-
set_callback(:before,
|
29
|
+
def before(method_name)
|
30
|
+
set_callback(:before, method_name)
|
28
31
|
end
|
29
32
|
|
30
|
-
def after(
|
31
|
-
set_callback(:after,
|
33
|
+
def after(method_name)
|
34
|
+
set_callback(:after, method_name)
|
32
35
|
end
|
33
36
|
|
34
|
-
def finally(
|
35
|
-
set_callback(:finally,
|
37
|
+
def finally(method_name)
|
38
|
+
set_callback(:finally, method_name)
|
36
39
|
end
|
37
40
|
|
38
|
-
def set_callback(type,
|
41
|
+
def set_callback(type, method_name)
|
39
42
|
self.callbacks ||= []
|
40
|
-
self.callbacks << { type: type,
|
43
|
+
self.callbacks << { type: type, method_name: method_name }
|
41
44
|
end
|
42
45
|
end
|
43
46
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Light
|
2
4
|
module Services
|
3
5
|
class Messages
|
@@ -6,8 +8,8 @@ module Light
|
|
6
8
|
end
|
7
9
|
|
8
10
|
def add(key, message)
|
9
|
-
|
10
|
-
|
11
|
+
storage[key] ||= []
|
12
|
+
storage[key] << message
|
11
13
|
end
|
12
14
|
|
13
15
|
def from_record(record)
|
@@ -17,11 +19,11 @@ module Light
|
|
17
19
|
end
|
18
20
|
|
19
21
|
def delete(key)
|
20
|
-
|
22
|
+
storage.delete(key)
|
21
23
|
end
|
22
24
|
|
23
25
|
def blank?
|
24
|
-
|
26
|
+
storage.empty?
|
25
27
|
end
|
26
28
|
|
27
29
|
def any?
|
@@ -29,9 +31,11 @@ module Light
|
|
29
31
|
end
|
30
32
|
|
31
33
|
def to_hash
|
32
|
-
|
34
|
+
storage
|
33
35
|
end
|
34
36
|
|
37
|
+
alias to_h to_hash
|
38
|
+
|
35
39
|
private
|
36
40
|
|
37
41
|
# Getters/Setters
|
@@ -0,0 +1,64 @@
|
|
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
|
+
(self.class.outputs || []).each do |options|
|
27
|
+
store_output(options)
|
28
|
+
end
|
29
|
+
|
30
|
+
generate_outputs_methods
|
31
|
+
end
|
32
|
+
|
33
|
+
def store_output(options)
|
34
|
+
output_name = options[:name]
|
35
|
+
output_value = options[:value]
|
36
|
+
|
37
|
+
outputs[output_name] = output_value
|
38
|
+
end
|
39
|
+
|
40
|
+
def generate_outputs_methods
|
41
|
+
outputs.keys.each do |output_name|
|
42
|
+
define_singleton_method output_name do
|
43
|
+
outputs[output_name]
|
44
|
+
end
|
45
|
+
|
46
|
+
define_singleton_method "#{output_name}=" do |value|
|
47
|
+
outputs[output_name] = value
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
module ClassMethods
|
53
|
+
def output(name, value = nil, options = {})
|
54
|
+
self.outputs ||= []
|
55
|
+
self.outputs << {
|
56
|
+
name: name,
|
57
|
+
value: value,
|
58
|
+
public: options.fetch(:private, false)
|
59
|
+
}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Light
|
2
4
|
module Services
|
3
5
|
module Parameters
|
@@ -6,72 +8,69 @@ module Light
|
|
6
8
|
base.class_eval do
|
7
9
|
class << self
|
8
10
|
attr_accessor :parameters
|
9
|
-
attr_accessor :outputs
|
10
11
|
end
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
def outputs
|
19
|
-
@outputs_storage.to_hash
|
20
|
-
end
|
15
|
+
# Getters
|
16
|
+
attr_reader :parameters
|
21
17
|
|
22
18
|
private
|
23
19
|
|
20
|
+
# Setters
|
21
|
+
attr_writer :parameters
|
22
|
+
|
24
23
|
def initialize_params
|
25
|
-
|
24
|
+
self.parameters = {}
|
26
25
|
|
27
26
|
(self.class.parameters || []).each do |options|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
27
|
+
validate_parameter(options)
|
28
|
+
store_parameter(options)
|
29
|
+
end
|
32
30
|
|
33
|
-
|
34
|
-
|
31
|
+
generate_parameters_methods
|
32
|
+
end
|
35
33
|
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
def validate_parameter(options)
|
35
|
+
if parameter_required?(options)
|
36
|
+
raise Light::Services::ParamRequired, "Parameter \"#{options[:name]}\" is required"
|
37
|
+
end
|
39
38
|
|
40
|
-
|
41
|
-
raise Light::Services::ParamType, "Type of \"#{options[:name]}\" must be \"#{options[:type]}\""
|
42
|
-
end
|
39
|
+
return unless parameter_wrong_type?(options)
|
43
40
|
|
44
|
-
|
45
|
-
|
41
|
+
raise Light::Services::ParamType, "Type of \"#{options[:name]}\" must be \"#{options[:type]}\""
|
42
|
+
end
|
46
43
|
|
47
|
-
|
48
|
-
|
49
|
-
|
44
|
+
def parameter_required?(options)
|
45
|
+
!args.key?(options[:name]) && options[:required] && !options[:allow_nil]
|
46
|
+
end
|
50
47
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
48
|
+
def parameter_wrong_type?(options)
|
49
|
+
value = args[options[:name]]
|
50
|
+
|
51
|
+
wrong_type = options[:type] && !options[:type].include?(value.class)
|
52
|
+
not_allow_nil = !options[:allow_nil] || (options[:allow_nil] && !value.nil?)
|
55
53
|
|
56
|
-
|
54
|
+
wrong_type && not_allow_nil
|
57
55
|
end
|
58
56
|
|
59
|
-
def
|
60
|
-
|
57
|
+
def store_parameter(options)
|
58
|
+
parameter_name = options[:name]
|
59
|
+
parameter_value = args[parameter_name]
|
61
60
|
|
62
|
-
|
63
|
-
|
61
|
+
parameters[parameter_name] = parameter_value
|
62
|
+
end
|
64
63
|
|
65
|
-
|
66
|
-
|
64
|
+
def generate_parameters_methods
|
65
|
+
parameters.keys.each do |parameter_name|
|
66
|
+
define_singleton_method parameter_name do
|
67
|
+
parameters[parameter_name]
|
67
68
|
end
|
68
69
|
|
69
|
-
define_singleton_method "#{
|
70
|
-
|
70
|
+
define_singleton_method "#{parameter_name}=" do |value|
|
71
|
+
parameters[parameter_name] = value
|
71
72
|
end
|
72
73
|
end
|
73
|
-
|
74
|
-
@outputs_storage
|
75
74
|
end
|
76
75
|
|
77
76
|
module ClassMethods
|
@@ -85,15 +84,6 @@ module Light
|
|
85
84
|
allow_nil: options.fetch(:allow_nil, false)
|
86
85
|
}
|
87
86
|
end
|
88
|
-
|
89
|
-
def output(name, value = nil, options = {})
|
90
|
-
self.outputs ||= []
|
91
|
-
self.outputs << {
|
92
|
-
name: name,
|
93
|
-
value: value,
|
94
|
-
public: options.fetch(:private, false)
|
95
|
-
}
|
96
|
-
end
|
97
87
|
end
|
98
88
|
end
|
99
89
|
end
|