lite-command 2.1.2 → 3.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.
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lite
4
- module Command
5
- class AttributeValidator
6
-
7
- attr_reader :command
8
-
9
- def initialize(command)
10
- @command = command
11
- end
12
-
13
- def attributes
14
- @attributes ||=
15
- command.class.attributes.map do |_method_name, attribute|
16
- attribute.tap { |a| a.command = command }
17
- end
18
- end
19
-
20
- def errors
21
- @errors ||= attributes.each_with_object({}) do |attribute, h|
22
- next if attribute.tap(&:validate!).valid?
23
-
24
- h[attribute.from] ||= []
25
- h[attribute.from] = h[attribute.from] | attribute.errors
26
- end
27
- end
28
-
29
- def valid?
30
- attributes.empty? || errors.empty?
31
- end
32
-
33
- end
34
- end
35
- end
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lite
4
- module Command
5
- module Internals
6
- module Context
7
-
8
- def self.included(base)
9
- base.extend ClassMethods
10
- end
11
-
12
- module ClassMethods
13
-
14
- def attribute(*args, **options)
15
- args.each do |method_name|
16
- attribute = Lite::Command::Attribute.new(method_name, options)
17
- attributes[method_name] = attribute
18
-
19
- define_method(method_name) do
20
- ivar = :"@#{method_name}"
21
- return instance_variable_get(ivar) if instance_variable_defined?(ivar)
22
-
23
- instance_variable_set(ivar, attribute.value)
24
- end
25
- end
26
- end
27
-
28
- def attributes
29
- @attributes ||= {}
30
- end
31
-
32
- end
33
-
34
- private
35
-
36
- def validate_context_attributes
37
- validator = Lite::Command::AttributeValidator.new(self)
38
- return if validator.valid?
39
-
40
- invalid!("Invalid context attributes", validator.errors)
41
- end
42
-
43
- end
44
- end
45
- end
46
- end