Class: JSON::SchemaGeneratorCLI

Inherits:
Object
  • Object
show all
Defined in:
lib/json/schema_generator_cli.rb

Instance Method Summary collapse

Constructor Details

#initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) ⇒ SchemaGeneratorCLI

Returns a new instance of SchemaGeneratorCLI.



2
3
4
# File 'lib/json/schema_generator_cli.rb', line 2

def initialize(argv, stdin=STDIN, stdout=STDOUT, stderr=STDERR, kernel=Kernel)
  @argv, @stdin, @stdout, @stderr, @kernel = argv, stdin, stdout, stderr, kernel
end

Instance Method Details

#execute!Object



6
7
8
9
10
11
12
# File 'lib/json/schema_generator_cli.rb', line 6

def execute!
  file = ARGV.shift
  version = ARGV.shift || 'draft3'
  schema = JSON.parse(JSON::SchemaGenerator.generate file, File.read(file), version)
  @stdout.puts JSON.pretty_generate schema
  @kernel.exit(0)
end