Class: HammerCLI::Options::Normalizers::ListNested

Inherits:
AbstractNormalizer show all
Defined in:
lib/hammer_cli/options/normalizers.rb

Defined Under Namespace

Classes: Schema

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractNormalizer

#complete, #description, inherited

Constructor Details

#initialize(schema) ⇒ ListNested

Returns a new instance of ListNested.



183
184
185
# File 'lib/hammer_cli/options/normalizers.rb', line 183

def initialize(schema)
  @schema = Schema.new(schema)
end

Instance Attribute Details

#schemaObject (readonly)

Returns the value of attribute schema.



181
182
183
# File 'lib/hammer_cli/options/normalizers.rb', line 181

def schema
  @schema
end

Class Method Details

.common_descriptionObject



155
156
157
158
159
# File 'lib/hammer_cli/options/normalizers.rb', line 155

def common_description
  _('Comma separated list of values defined by a schema.') +
    "\n" +
    _('JSON is acceptable and preferred way for such parameters')
end

.completion_typeObject



151
152
153
# File 'lib/hammer_cli/options/normalizers.rb', line 151

def completion_type
  :schema
end

Instance Method Details

#completion_typeObject



200
201
202
# File 'lib/hammer_cli/options/normalizers.rb', line 200

def completion_type
  super.merge({ schema: schema.description(richtext: false) })
end

#format(val) ⇒ Object



187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/hammer_cli/options/normalizers.rb', line 187

def format(val)
  return [] unless val.is_a?(String) && !val.empty?
  begin
    JSON.parse(val)
  rescue JSON::ParserError
    HammerCLI::CSVParser.new.parse(val).inject([]) do |results, item|
      next if item.empty?

      results << KeyValueList.new.format(item)
    end
  end
end