module Cog::Controllers::GeneratorController

Manage a project's generators

Public Class Methods

create(name, opt={}) click to toggle source

Create a new generator @param name [String] the name to use for the new generator @option opt [String] :plugin_name (nil) plugin to use @return [Boolean] was the generator successfully created?

# File lib/cog/controllers/generator_controller.rb, line 11
def self.create(name, opt={})
  plugin = Cog.plugin(opt[:plugin_name])
  prefix = Cog.project_generator_path
  raise Errors::NoSuchPlugin.new(opt[:plugin_name]) if plugin.nil?
  raise Errors::PluginMissingDefinition.new('stamp_generator') if plugin.stamp_generator_block.nil?
  raise Errors::ActionRequiresProjectGeneratorPath.new('create generator') unless prefix
  dest = File.join prefix, "#{name}.rb"
  raise Errors::DuplicateGenerator.new(dest) if File.exists?(dest)
  plugin.stamp_generator_block.call name.to_s, dest
end
list() click to toggle source

List the available project generators @return [Array<String>] a list of generators

# File lib/cog/controllers/generator_controller.rb, line 24
def self.list
  Helpers::CascadingSet.process_paths Cog.generator_path, :ext => 'rb'
end
run(name) click to toggle source

Run the generator with the given name @param name [String] name of the generator to run @return [nil]

# File lib/cog/controllers/generator_controller.rb, line 31
def self.run(name)
  Cog.generator_path.reverse.each do |root|
    path = File.join root, "#{name}.rb"
    if File.exists?(path)
      GeneratorSandbox.new(path).interpret
      return
    end
  end
  raise Errors::NoSuchGenerator.new(name)
end
run_all() click to toggle source

Run all generators @return [nil]

# File lib/cog/controllers/generator_controller.rb, line 44
def self.run_all
  Cog.generator_path.each do |root|
    Dir.glob("#{root}/*.rb").each do |path|
      GeneratorSandbox.new(path).interpret
    end
  end
end