Sha256: 12420f0d27e24160bd841c8fae5e09769af8fd195163778406d06357b4659370

Contents?: true

Size: 1.25 KB

Versions: 18

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

class CmdletBuilder < KDirector::Builders::ActionsBuilder
  attr_reader :current_cmdlet

  def initialize
    super

    dom[:category_key] = nil
    dom[:cmdlets] = []
  end

  def category_key
    dom[:category_key]
  end

  def category_key=(value)
    set(:category_key, value: value)
  end

  def cmdlets
    dom[:cmdlets]
  end

  def add_cmdlet
    @current_cmdlet = new_cmdlet
    dom[:cmdlets] << current_cmdlet
  end

  def cmdlet_setting(name, value)
    @current_cmdlet[name] = value
  end

  def add_cmdlet_parameter(name, description, **opts)
    parameter = {
      name: name,
      description: description
    }.merge(opts)

    @current_cmdlet[:parameters] << parameter
  end

  def add_cmdlet_example(value)
    lines = value.split("\n")
    value = lines.map { |line| "        # #{line.strip}" }.join("\n")

    @current_cmdlet[:examples] << value
  end

  private

  def new_cmdlet
    category = data_access.category.find_category(category_key)

    {
      name: nil,
      aliases: [],
      description: nil,
      result: nil,
      category: category[:name],
      category_description: category[:description],
      base_class_require: nil,
      base_class: nil,
      parameters: [],
      examples: []
    }
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
cmdlet-0.14.0 .builders/director/cmdlet_builder.rb
cmdlet-0.13.2 .builders/director/cmdlet_builder.rb
cmdlet-0.13.1 .builders/director/cmdlet_builder.rb
cmdlet-0.13.0 .builders/director/cmdlet_builder.rb
cmdlet-0.12.5 .builders/director/cmdlet_builder.rb
cmdlet-0.12.4 .builders/director/cmdlet_builder.rb
cmdlet-0.12.3 .builders/director/cmdlet_builder.rb
cmdlet-0.12.2 .builders/director/cmdlet_builder.rb
cmdlet-0.12.1 .builders/director/cmdlet_builder.rb
cmdlet-0.12.0 .builders/director/cmdlet_builder.rb
cmdlet-0.11.0 .builders/director/cmdlet_builder.rb
cmdlet-0.10.1 .builders/director/cmdlet_builder.rb
cmdlet-0.10.0 .builders/director/cmdlet_builder.rb
cmdlet-0.9.2 .builders/director/cmdlet_builder.rb
cmdlet-0.9.1 .builders/director/cmdlet_builder.rb
cmdlet-0.9.0 .builders/director/cmdlet_builder.rb
cmdlet-0.8.0 .builders/director/cmdlet_builder.rb
cmdlet-0.7.1 .builders/director/cmdlet_builder.rb