Class: GLCommand::ContextInspect

Inherits:
Object
  • Object
show all
Defined in:
lib/gl_command/context_inspect.rb

Constant Summary collapse

PERMITTED_OUTPUTS =
i[string hash].freeze

Class Method Summary collapse

Class Method Details

.error(error_obj) ⇒ Object



8
9
10
11
12
# File 'lib/gl_command/context_inspect.rb', line 8

def error(error_obj)
  return '' if error_obj.blank?

  error_obj.is_a?(Array) ? error_obj.uniq.join(', ') : error_obj.to_s
end

.hash_params(hash, output: :string) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/gl_command/context_inspect.rb', line 14

def hash_params(hash, output: :string)
  unless PERMITTED_OUTPUTS.include?(output)
    raise "Unknown output type: #{output}, must be one of #{PERMITTED_OUTPUTS}"
  end

  result = hash.map { |key, value| output_for(key:, value:, output:) }
  output == :string ? result.join(', ') : result.to_h
end