Class: KwalifyToJsonSchema::Cli

Inherits:
Thor
  • Object
show all
Defined in:
lib/kwalify_to_json_schema/cli.rb

Constant Summary collapse

CUSTOM_PROCESSING_CODE_DOC =
<<~CODE
  class CustomProcessing
      # The method will be called before conversion allowing to customize the input Kwalify schema.
      # The implementation have to return the modified schema.
      # The default implemention don't modify the schema.
      # @param kwalify_schema {Hash}
      # @return modified schema
      def preprocess(kwalify_schema)
        # TODO return modified schema
      end
      
      # The method will be called after the conversion allowing to customize the output JSON schema.
      # The implementation have to return the modified schema.
      # The default implemention don't modify the schema.
      # @param json_schema {Hash}
      # @return modified schema
      def postprocess(json_schema)
        # TODO return modified schema
      end
  end
CODE

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/kwalify_to_json_schema/cli.rb', line 85

def self.exit_on_failure?
  false
end

Instance Method Details

#convert(kwalify_schema_file, result_file) ⇒ Object



43
44
45
46
47
# File 'lib/kwalify_to_json_schema/cli.rb', line 43

def convert(kwalify_schema_file, result_file)
  opts = options.dup
  opts[Options::CUSTOM_PROCESSING] = custom_processing(options)
  KwalifyToJsonSchema.convert_file(kwalify_schema_file, result_file, opts)
end

#convert_dir(kwalify_schema_dir, result_dir) ⇒ Object



74
75
76
77
78
79
80
81
82
83
# File 'lib/kwalify_to_json_schema/cli.rb', line 74

def convert_dir(kwalify_schema_dir, result_dir)
  opts = options.dup
  opts[Options::CUSTOM_PROCESSING] = custom_processing(options)
  
  path = [kwalify_schema_dir, options["recursive"] ? "**" : nil, "*.{yaml,yml}"].compact
  Dir.glob(File.join(*path)).each { |kwalify_schema_file|
    result_file = File.join(result_dir, File.basename(kwalify_schema_file, File.extname(kwalify_schema_file))) + ".#{options["format"]}"
    KwalifyToJsonSchema.convert_file(kwalify_schema_file, result_file, opts)
  }
end