light-services 0.6.3 → 2.0.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) 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 +102 -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 +151 -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 +55 -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 +67 -45
  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 +77 -0
  29. data/lib/light/services/version.rb +1 -1
  30. data/light-services.gemspec +21 -25
  31. metadata +28 -122
  32. data/.codeclimate.yml +0 -18
  33. data/.ruby-gemset +0 -1
  34. data/.ruby-version +0 -1
  35. data/.travis.yml +0 -33
  36. data/Appraisals +0 -13
  37. data/gemfiles/rails_5_0.gemfile +0 -7
  38. data/gemfiles/rails_5_0.gemfile.lock +0 -151
  39. data/gemfiles/rails_5_1.gemfile +0 -7
  40. data/gemfiles/rails_5_1.gemfile.lock +0 -151
  41. data/gemfiles/rails_5_2.gemfile +0 -7
  42. data/gemfiles/rails_5_2.gemfile.lock +0 -159
  43. data/lib/light/services/callbacks.rb +0 -54
  44. data/lib/light/services/outputs.rb +0 -70
  45. data/lib/light/services/parameters.rb +0 -96
@@ -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