Sha256: 30760e1b7e13a9dbcd758c6f1af54350a85639355f6d88e438753b6e440729e2

Contents?: true

Size: 1.23 KB

Versions: 12

Compression:

Stored size: 1.23 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,
      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

12 entries across 12 versions & 1 rubygems

Version Path
cmdlet-0.7.0 .builders/director/cmdlet_builder.rb
cmdlet-0.6.2 .builders/director/cmdlet_builder.rb
cmdlet-0.6.1 .builders/director/cmdlet_builder.rb
cmdlet-0.6.0 .builders/director/cmdlet_builder.rb
cmdlet-0.5.0 .builders/director/cmdlet_builder.rb
cmdlet-0.4.2 .builders/director/cmdlet_builder.rb
cmdlet-0.4.1 .builders/director/cmdlet_builder.rb
cmdlet-0.4.0 .builders/director/cmdlet_builder.rb
cmdlet-0.3.0 .builders/director/cmdlet_builder.rb
cmdlet-0.2.1 .builders/director/cmdlet_builder.rb
cmdlet-0.2.0 .builders/director/cmdlet_builder.rb
cmdlet-0.1.2 .builders/director/cmdlet_builder.rb