Sha256: 65fc3b595c1acc1cec27ef5132843492b0a8d56f013b5a78b5f8ecbf7c1504da

Contents?: true

Size: 763 Bytes

Versions: 1

Compression:

Stored size: 763 Bytes

Contents

require 'scaffolder'

module Scaffolder::ToolIndex
  require 'scaffolder/tool'

  def get_tool(name)
    tools[normalise(name)]
  end

  def tool_exists?(name)
    ! get_tool(name).nil?
  end

  def [](type)
    if tool_exists?(type)
      get_tool(type)
    else
      Scaffolder::Tool::Help
    end
  end

  private

  def tool_classes
    Scaffolder::Tool.constants.inject(Array.new) do |array,constant|
      clss = Scaffolder::Tool.const_get(constant)
      array << clss if clss.superclass == Scaffolder::Tool
      array
    end
  end

  def tools
    tool_classes.inject(Hash.new) do |hash,clss|
      hash[clss.to_s.split('::').last.downcase.to_sym] = clss
      hash
    end
  end

  def normalise(name)
    name.to_s.downcase.to_sym if name
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
scaffolder-tools-0.1.3 lib/scaffolder/tool_index.rb