Skip to content

Commit

Permalink
Add platforms schema command.
Browse files Browse the repository at this point in the history
Signed-off-by: Jared Quick <jquick@chef.io>
  • Loading branch information
jquick committed Aug 31, 2018
1 parent d69791e commit 2dc0f2e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Expand Up @@ -2,6 +2,8 @@
source 'https://rubygems.org'
gemspec name: 'inspec'

gem 'train', :git => 'https://github.com/inspec/train.git', :branch => 'jq/add_platforms_export'

if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2.2')
gem 'json', '~> 1.8'
gem 'rack', '< 2.0'
Expand Down
2 changes: 1 addition & 1 deletion inspec.gemspec
Expand Up @@ -26,7 +26,7 @@ Gem::Specification.new do |spec|

spec.required_ruby_version = '>= 2.3'

spec.add_dependency 'train', '~> 1.4', '>= 1.4.35'
# spec.add_dependency 'train', '~> 1.4', '>= 1.4.35'
spec.add_dependency 'thor', '~> 0.20'
spec.add_dependency 'json', '>= 1.8', '< 3.0'
spec.add_dependency 'method_source', '~> 0.8'
Expand Down
17 changes: 15 additions & 2 deletions lib/inspec/schema.rb
Expand Up @@ -200,18 +200,31 @@ class Schema
},
}.freeze

# using a proc here so we can lazy load it when we need
PLATFORMS = lambda do
require 'train'
Train.create('mock').connection
Train::Platforms.export
end

LIST = {
'exec-json' => EXEC_JSON,
'exec-jsonmin' => EXEC_JSONMIN,
'platforms' => PLATFORMS,
}.freeze

def self.names
LIST.keys
end

def self.json(name)
v = LIST[name] ||
raise("Cannot find schema #{name.inspect}.")
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
end
Expand Down

0 comments on commit 2dc0f2e

Please sign in to comment.