Sha256: d55303c66a7a8d5ad089a9650d3756e886e833e48b531944a47c5fa0b89ee5a3

Contents?: true

Size: 1.41 KB

Versions: 12

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

require 'json'

# The module for JSON related functionality.
module PuppetStrings::Json
  # Renders the current YARD registry as JSON to the given file (or STDOUT if nil).
  # @param [String] file The path to the output file to render the registry to. If nil, output will be to STDOUT.
  # @return [void]
  def self.render(file = nil)
    document = {
      puppet_classes: YARD::Registry.all(:puppet_class).sort_by!(&:name).map!(&:to_hash),
      data_types: YARD::Registry.all(:puppet_data_type).sort_by!(&:name).map!(&:to_hash),
      data_type_aliases: YARD::Registry.all(:puppet_data_type_alias).sort_by!(&:name).map!(&:to_hash),
      defined_types: YARD::Registry.all(:puppet_defined_type).sort_by!(&:name).map!(&:to_hash),
      resource_types: YARD::Registry.all(:puppet_type).sort_by!(&:name).map!(&:to_hash),
      providers: YARD::Registry.all(:puppet_provider).sort_by!(&:name).map!(&:to_hash),
      puppet_functions: YARD::Registry.all(:puppet_function).sort_by!(&:name).map!(&:to_hash),
      puppet_tasks: YARD::Registry.all(:puppet_task).sort_by!(&:name).map!(&:to_hash),
      puppet_plans: YARD::Registry.all(:puppet_plan).sort_by!(&:name).map!(&:to_hash)
      # TODO: Need Ruby documentation?
    }

    if file
      File.open(file, 'w') do |f|
        f.write(JSON.pretty_generate(document))
        f.write("\n")
      end
    else
      puts JSON.pretty_generate(document)
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
puppet-strings-4.1.3 lib/puppet-strings/json.rb
puppet-strings-4.1.2 lib/puppet-strings/json.rb
puppet-strings-4.1.1 lib/puppet-strings/json.rb
puppet-strings-4.1.0 lib/puppet-strings/json.rb
puppet-strings-4.0.0 lib/puppet-strings/json.rb
puppet-strings-4.0.0.rc.1 lib/puppet-strings/json.rb
puppet-strings-3.0.1 lib/puppet-strings/json.rb
puppet-strings-3.0.0 lib/puppet-strings/json.rb
puppet-strings-2.9.0 lib/puppet-strings/json.rb
puppet-strings-2.8.0 lib/puppet-strings/json.rb
puppet-strings-2.7.0 lib/puppet-strings/json.rb
puppet-strings-2.6.0 lib/puppet-strings/json.rb