light-services 0.6.2 → 2.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.github/config/rubocop_linter_action.yml +4 -0
  3. data/.github/workflows/ci.yml +63 -0
  4. data/.gitignore +11 -4
  5. data/.rspec +1 -0
  6. data/.rubocop.yml +22 -8
  7. data/CHANGELOG.md +1 -0
  8. data/CODE_OF_CONDUCT.md +55 -30
  9. data/Gemfile +16 -2
  10. data/Gemfile.lock +101 -0
  11. data/LICENSE.txt +1 -1
  12. data/README.md +3 -149
  13. data/Rakefile +2 -2
  14. data/bin/console +4 -4
  15. data/lib/light/services.rb +4 -7
  16. data/lib/light/services/base.rb +142 -30
  17. data/lib/light/services/base_with_context.rb +33 -0
  18. data/lib/light/services/class_based_collection/base.rb +88 -0
  19. data/lib/light/services/class_based_collection/mount.rb +33 -0
  20. data/lib/light/services/collection/arguments.rb +34 -0
  21. data/lib/light/services/collection/base.rb +47 -0
  22. data/lib/light/services/collection/outputs.rb +16 -0
  23. data/lib/light/services/config.rb +63 -0
  24. data/lib/light/services/exceptions.rb +3 -2
  25. data/lib/light/services/messages.rb +68 -44
  26. data/lib/light/services/settings/argument.rb +50 -0
  27. data/lib/light/services/settings/output.rb +34 -0
  28. data/lib/light/services/settings/step.rb +71 -0
  29. data/lib/light/services/version.rb +1 -1
  30. data/light-services.gemspec +21 -24
  31. metadata +28 -129
  32. data/.codeclimate.yml +0 -18
  33. data/.ruby-gemset +0 -1
  34. data/.ruby-version +0 -1
  35. data/.travis.yml +0 -36
  36. data/Appraisals +0 -25
  37. data/gemfiles/rails_4_0.gemfile +0 -7
  38. data/gemfiles/rails_4_0.gemfile.lock +0 -115
  39. data/gemfiles/rails_4_1.gemfile +0 -7
  40. data/gemfiles/rails_4_1.gemfile.lock +0 -118
  41. data/gemfiles/rails_4_2.gemfile +0 -7
  42. data/gemfiles/rails_4_2.gemfile.lock +0 -144
  43. data/gemfiles/rails_5_0.gemfile +0 -7
  44. data/gemfiles/rails_5_0.gemfile.lock +0 -151
  45. data/gemfiles/rails_5_1.gemfile +0 -7
  46. data/gemfiles/rails_5_1.gemfile.lock +0 -151
  47. data/gemfiles/rails_5_2.gemfile +0 -7
  48. data/gemfiles/rails_5_2.gemfile.lock +0 -159
  49. data/lib/light/services/callbacks.rb +0 -54
  50. data/lib/light/services/outputs.rb +0 -70
  51. data/lib/light/services/parameters.rb +0 -96
@@ -1,151 +0,0 @@
1
- PATH
2
- remote: ..
3
- specs:
4
- light-services (0.6.2)
5
- rails (> 4.0)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- actioncable (5.1.6)
11
- actionpack (= 5.1.6)
12
- nio4r (~> 2.0)
13
- websocket-driver (~> 0.6.1)
14
- actionmailer (5.1.6)
15
- actionpack (= 5.1.6)
16
- actionview (= 5.1.6)
17
- activejob (= 5.1.6)
18
- mail (~> 2.5, >= 2.5.4)
19
- rails-dom-testing (~> 2.0)
20
- actionpack (5.1.6)
21
- actionview (= 5.1.6)
22
- activesupport (= 5.1.6)
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.6)
28
- activesupport (= 5.1.6)
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.6)
34
- activesupport (= 5.1.6)
35
- globalid (>= 0.3.6)
36
- activemodel (5.1.6)
37
- activesupport (= 5.1.6)
38
- activerecord (5.1.6)
39
- activemodel (= 5.1.6)
40
- activesupport (= 5.1.6)
41
- arel (~> 8.0)
42
- activesupport (5.1.6)
43
- concurrent-ruby (~> 1.0, >= 1.0.2)
44
- i18n (>= 0.7, < 2)
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
- crass (1.0.4)
57
- diff-lcs (1.3)
58
- docile (1.1.5)
59
- erubi (1.7.1)
60
- globalid (0.4.1)
61
- activesupport (>= 4.2.0)
62
- i18n (1.1.0)
63
- concurrent-ruby (~> 1.0)
64
- json (1.8.6)
65
- loofah (2.2.2)
66
- crass (~> 1.0.2)
67
- nokogiri (>= 1.5.9)
68
- mail (2.7.0)
69
- mini_mime (>= 0.1.1)
70
- method_source (0.9.0)
71
- mini_mime (1.0.1)
72
- mini_portile2 (2.3.0)
73
- minitest (5.11.3)
74
- nio4r (2.3.1)
75
- nokogiri (1.8.4)
76
- mini_portile2 (~> 2.3.0)
77
- rack (2.0.5)
78
- rack-test (1.1.0)
79
- rack (>= 1.0, < 3)
80
- rails (5.1.6)
81
- actioncable (= 5.1.6)
82
- actionmailer (= 5.1.6)
83
- actionpack (= 5.1.6)
84
- actionview (= 5.1.6)
85
- activejob (= 5.1.6)
86
- activemodel (= 5.1.6)
87
- activerecord (= 5.1.6)
88
- activesupport (= 5.1.6)
89
- bundler (>= 1.3.0)
90
- railties (= 5.1.6)
91
- sprockets-rails (>= 2.0.0)
92
- rails-dom-testing (2.0.3)
93
- activesupport (>= 4.2.0)
94
- nokogiri (>= 1.6)
95
- rails-html-sanitizer (1.0.4)
96
- loofah (~> 2.2, >= 2.2.2)
97
- railties (5.1.6)
98
- actionpack (= 5.1.6)
99
- activesupport (= 5.1.6)
100
- method_source
101
- rake (>= 0.8.7)
102
- thor (>= 0.18.1, < 2.0)
103
- rake (10.5.0)
104
- rspec (3.6.0)
105
- rspec-core (~> 3.6.0)
106
- rspec-expectations (~> 3.6.0)
107
- rspec-mocks (~> 3.6.0)
108
- rspec-core (3.6.0)
109
- rspec-support (~> 3.6.0)
110
- rspec-expectations (3.6.0)
111
- diff-lcs (>= 1.2.0, < 2.0)
112
- rspec-support (~> 3.6.0)
113
- rspec-mocks (3.6.0)
114
- diff-lcs (>= 1.2.0, < 2.0)
115
- rspec-support (~> 3.6.0)
116
- rspec-support (3.6.0)
117
- simplecov (0.11.2)
118
- docile (~> 1.1.0)
119
- json (~> 1.8)
120
- simplecov-html (~> 0.10.0)
121
- simplecov-html (0.10.2)
122
- sprockets (3.7.2)
123
- concurrent-ruby (~> 1.0)
124
- rack (> 1, < 3)
125
- sprockets-rails (3.2.1)
126
- actionpack (>= 4.0)
127
- activesupport (>= 4.0)
128
- sprockets (>= 3.0.0)
129
- thor (0.20.0)
130
- thread_safe (0.3.6)
131
- tzinfo (1.2.5)
132
- thread_safe (~> 0.1)
133
- websocket-driver (0.6.5)
134
- websocket-extensions (>= 0.1.0)
135
- websocket-extensions (0.1.3)
136
-
137
- PLATFORMS
138
- ruby
139
-
140
- DEPENDENCIES
141
- appraisal (~> 2.1)
142
- bundler (~> 1.12)
143
- codeclimate-test-reporter
144
- light-services!
145
- rails (= 5.1.6)
146
- rake (~> 10.0)
147
- rspec (~> 3.0)
148
- simplecov (~> 0.11.2)
149
-
150
- BUNDLED WITH
151
- 1.16.2
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "5.2.1"
6
-
7
- gemspec path: "../"
@@ -1,159 +0,0 @@
1
- PATH
2
- remote: ..
3
- specs:
4
- light-services (0.6.2)
5
- rails (> 4.0)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- actioncable (5.2.1)
11
- actionpack (= 5.2.1)
12
- nio4r (~> 2.0)
13
- websocket-driver (>= 0.6.1)
14
- actionmailer (5.2.1)
15
- actionpack (= 5.2.1)
16
- actionview (= 5.2.1)
17
- activejob (= 5.2.1)
18
- mail (~> 2.5, >= 2.5.4)
19
- rails-dom-testing (~> 2.0)
20
- actionpack (5.2.1)
21
- actionview (= 5.2.1)
22
- activesupport (= 5.2.1)
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.2.1)
28
- activesupport (= 5.2.1)
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.2.1)
34
- activesupport (= 5.2.1)
35
- globalid (>= 0.3.6)
36
- activemodel (5.2.1)
37
- activesupport (= 5.2.1)
38
- activerecord (5.2.1)
39
- activemodel (= 5.2.1)
40
- activesupport (= 5.2.1)
41
- arel (>= 9.0)
42
- activestorage (5.2.1)
43
- actionpack (= 5.2.1)
44
- activerecord (= 5.2.1)
45
- marcel (~> 0.3.1)
46
- activesupport (5.2.1)
47
- concurrent-ruby (~> 1.0, >= 1.0.2)
48
- i18n (>= 0.7, < 2)
49
- minitest (~> 5.1)
50
- tzinfo (~> 1.1)
51
- appraisal (2.2.0)
52
- bundler
53
- rake
54
- thor (>= 0.14.0)
55
- arel (9.0.0)
56
- builder (3.2.3)
57
- codeclimate-test-reporter (1.0.8)
58
- simplecov (<= 0.13)
59
- concurrent-ruby (1.0.5)
60
- crass (1.0.4)
61
- diff-lcs (1.3)
62
- docile (1.1.5)
63
- erubi (1.7.1)
64
- globalid (0.4.1)
65
- activesupport (>= 4.2.0)
66
- i18n (1.1.0)
67
- concurrent-ruby (~> 1.0)
68
- json (1.8.6)
69
- loofah (2.2.2)
70
- crass (~> 1.0.2)
71
- nokogiri (>= 1.5.9)
72
- mail (2.7.0)
73
- mini_mime (>= 0.1.1)
74
- marcel (0.3.2)
75
- mimemagic (~> 0.3.2)
76
- method_source (0.9.0)
77
- mimemagic (0.3.2)
78
- mini_mime (1.0.1)
79
- mini_portile2 (2.3.0)
80
- minitest (5.11.3)
81
- nio4r (2.3.1)
82
- nokogiri (1.8.4)
83
- mini_portile2 (~> 2.3.0)
84
- rack (2.0.5)
85
- rack-test (1.1.0)
86
- rack (>= 1.0, < 3)
87
- rails (5.2.1)
88
- actioncable (= 5.2.1)
89
- actionmailer (= 5.2.1)
90
- actionpack (= 5.2.1)
91
- actionview (= 5.2.1)
92
- activejob (= 5.2.1)
93
- activemodel (= 5.2.1)
94
- activerecord (= 5.2.1)
95
- activestorage (= 5.2.1)
96
- activesupport (= 5.2.1)
97
- bundler (>= 1.3.0)
98
- railties (= 5.2.1)
99
- sprockets-rails (>= 2.0.0)
100
- rails-dom-testing (2.0.3)
101
- activesupport (>= 4.2.0)
102
- nokogiri (>= 1.6)
103
- rails-html-sanitizer (1.0.4)
104
- loofah (~> 2.2, >= 2.2.2)
105
- railties (5.2.1)
106
- actionpack (= 5.2.1)
107
- activesupport (= 5.2.1)
108
- method_source
109
- rake (>= 0.8.7)
110
- thor (>= 0.19.0, < 2.0)
111
- rake (10.5.0)
112
- rspec (3.8.0)
113
- rspec-core (~> 3.8.0)
114
- rspec-expectations (~> 3.8.0)
115
- rspec-mocks (~> 3.8.0)
116
- rspec-core (3.8.0)
117
- rspec-support (~> 3.8.0)
118
- rspec-expectations (3.8.1)
119
- diff-lcs (>= 1.2.0, < 2.0)
120
- rspec-support (~> 3.8.0)
121
- rspec-mocks (3.8.0)
122
- diff-lcs (>= 1.2.0, < 2.0)
123
- rspec-support (~> 3.8.0)
124
- rspec-support (3.8.0)
125
- simplecov (0.11.2)
126
- docile (~> 1.1.0)
127
- json (~> 1.8)
128
- simplecov-html (~> 0.10.0)
129
- simplecov-html (0.10.2)
130
- sprockets (3.7.2)
131
- concurrent-ruby (~> 1.0)
132
- rack (> 1, < 3)
133
- sprockets-rails (3.2.1)
134
- actionpack (>= 4.0)
135
- activesupport (>= 4.0)
136
- sprockets (>= 3.0.0)
137
- thor (0.20.0)
138
- thread_safe (0.3.6)
139
- tzinfo (1.2.5)
140
- thread_safe (~> 0.1)
141
- websocket-driver (0.7.0)
142
- websocket-extensions (>= 0.1.0)
143
- websocket-extensions (0.1.3)
144
-
145
- PLATFORMS
146
- ruby
147
-
148
- DEPENDENCIES
149
- appraisal (~> 2.1)
150
- bundler (~> 1.12)
151
- codeclimate-test-reporter
152
- light-services!
153
- rails (= 5.2.1)
154
- rake (~> 10.0)
155
- rspec (~> 3.0)
156
- simplecov (~> 0.11.2)
157
-
158
- BUNDLED WITH
159
- 1.16.2
@@ -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]&.none? { |type| value.is_a?(type) }
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