Class: HammerCLI::Options::Normalizers::JSONInput
- Inherits:
-
File
- Object
- AbstractNormalizer
- File
- HammerCLI::Options::Normalizers::JSONInput
- Defined in:
- lib/hammer_cli/options/normalizers.rb
Instance Method Summary collapse
Methods inherited from File
common_description, #complete, completion_type
Methods inherited from AbstractNormalizer
common_description, #complete, completion_type, #completion_type, #description, inherited
Instance Method Details
#format(val) ⇒ Object
289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/hammer_cli/options/normalizers.rb', line 289 def format(val) # The JSON input can be either the path to a file whose contents are # JSON or a JSON string. For example: # /my/path/to/file.json # or # '{ "units":[ { "name":"zip", "version":"9.0", "inclusion":"false" } ] }') json_string = ::File.exist?(::File.(val)) ? super(val) : val ::JSON.parse(json_string) rescue ::JSON::ParserError raise ArgumentError, _("Unable to parse JSON input.") end |