Class: Bcome::Registry::Command::Base
- Inherits:
-
Object
- Object
- Bcome::Registry::Command::Base
show all
- Defined in:
- lib/objects/registry/command/base.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(data) ⇒ Base
Returns a new instance of Base.
23
24
25
26
27
|
# File 'lib/objects/registry/command/base.rb', line 23
def initialize(data)
@data = data
@data[:defaults] = {} unless @data[:defaults]
validate
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_sym, *arguments, &block) ⇒ Object
53
54
55
|
# File 'lib/objects/registry/command/base.rb', line 53
def method_missing(method_sym, *arguments, &block)
@data.key?(method_sym) ? @data[method_sym] : super
end
|
Class Method Details
.is_valid_type?(type) ⇒ Boolean
10
11
12
|
# File 'lib/objects/registry/command/base.rb', line 10
def is_valid_type?(type)
valid_types.keys.include?(type.to_sym)
end
|
.new_from_raw_command(data) ⇒ Object
4
5
6
7
8
|
# File 'lib/objects/registry/command/base.rb', line 4
def new_from_raw_command(data)
raise Bcome::Exception::InvalidContextCommand, "#{data.inspect} is missing key type" unless data[:type]
raise Bcome::Exception::InvalidContextCommand, "#{data.inspect} has invalid type '#{data[:type]}'" unless is_valid_type?(data[:type])
valid_types[data[:type].to_sym].new(data)
end
|
Instance Method Details
#defaults ⇒ Object
29
30
31
|
# File 'lib/objects/registry/command/base.rb', line 29
def defaults
@data[:defaults]
end
|
#execute(*_params) ⇒ Object
45
46
47
|
# File 'lib/objects/registry/command/base.rb', line 45
def execute(*_params)
raise 'Should be overriden'
end
|
#expected_keys ⇒ Object
49
50
51
|
# File 'lib/objects/registry/command/base.rb', line 49
def expected_keys
%i[console_command group description]
end
|
#process_arguments(arguments) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/objects/registry/command/base.rb', line 33
def process_arguments(arguments)
merged_arguments = {}
if [Array, Hash].include?(arguments.class)
processor_klass = arguments.is_a?(Array) ? ::Bcome::Registry::Arguments::CommandLine : ::Bcome::Registry::Arguments::Console
merged_arguments = processor_klass.process(arguments, defaults)
elsif defaults
merged_arguments = defaults
end
merged_arguments
end
|
#validate ⇒ Object
57
58
59
60
61
|
# File 'lib/objects/registry/command/base.rb', line 57
def validate
expected_keys.each do |key|
validation_error "#{@data.inspect} is missing key #{key}" unless @data.key?(key)
end
end
|
#validation_error(message) ⇒ Object