Module: Inspec::Schema::OutputSchema

Defined in:
lib/inspec/schema/output_schema.rb

Constant Summary collapse

PLATFORMS =

using a proc here so we can lazy load it when we need

lambda do
  require "train"
  Train.create("mock").connection
  Train::Platforms.export
end
LIST =
{
  "profile-json" => OutputSchema.finalize(Schema::ProfileJson::PROFILE),
  "exec-json" => OutputSchema.finalize(Schema::ExecJson::OUTPUT),
  "exec-jsonmin" => OutputSchema.finalize(Schema::ExecJsonMin::OUTPUT),
  "profile-json-enhanced-outcomes" => OutputSchema.finalize(Schema::ProfileJson::ENHANCED_OUTCOME_PROFILE),
  "exec-json-enhanced-outcomes" => OutputSchema.finalize(Schema::ExecJson::ENHANCED_OUTCOME_OUTPUT),
  "platforms" => PLATFORMS,
}.freeze

Class Method Summary collapse

Class Method Details

.build_definitions(schema_type) ⇒ Object

Build our definitions



11
12
13
14
15
# File 'lib/inspec/schema/output_schema.rb', line 11

def self.build_definitions(schema_type)
  {
    "definitions" => schema_type.all_depends.map { |t| [t.ref_name, t.body] }.to_h,
  }
end

.finalize(schema_type) ⇒ Object

Helper function to automatically bundle a type with its dependencies



18
19
20
# File 'lib/inspec/schema/output_schema.rb', line 18

def self.finalize(schema_type)
  schema_type.body.merge(OutputSchema.build_definitions(schema_type))
end

.json(name, opts) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/inspec/schema/output_schema.rb', line 42

def self.json(name, opts)
  name += "-enhanced-outcomes" if opts["enhanced_outcomes"]
  if !LIST.key?(name)
    raise("Cannot find schema #{name.inspect}.")
  elsif LIST[name].is_a?(Proc)
    v = LIST[name].call
  else
    v = LIST[name]
  end

  JSON.dump(v)
end

.namesObject



38
39
40
# File 'lib/inspec/schema/output_schema.rb', line 38

def self.names
  LIST.keys
end