Class: Slickr::Actions::Generate

Inherits:
Object
  • Object
show all
Defined in:
lib/slickr/actions/generate.rb

Overview

Adapter for calling the different types of Generators.

This class takes the name of the generator, in any form, and the name the user wants to give to the new piece of code. It will normalize both to follow Slickr conventions.

Naming Conventions

Slickr follows the same sort of conventions as Rails. Classes are appended with their type. Eg. a “spatiality” behavior will become SpatialityBehavior, a “hero” renderer will become HeroRenderer, etc.

Examples:

Generating a new behavior

Slickr::Actions::Generate.new("behavior", "spatiality").start
# => lib/behaviors/spatiality_behavior.rb

Generating a new behavior by specifying the full name

Slickr::Actions::Generate.new("behavior", "spatiality_behavior").start
# => lib/behaviors/spatiality_behavior.rb

Generating a new behavior by specifying the name in class form

Slickr::Actions::Generate.new("behavior", "SpatialityBehavior").start
# => lib/behaviors/spatiality_behavior.rb

Instance Method Summary collapse

Constructor Details

#initialize(type, name) ⇒ Generate

Returns a new instance of Generate.



29
30
31
32
# File 'lib/slickr/actions/generate.rb', line 29

def initialize(type, name)
  @type = type
  @name = name
end

Instance Method Details

#basenameObject



46
47
48
# File 'lib/slickr/actions/generate.rb', line 46

def basename
  @name.gsub(/#{@type}/i, "").downcase
end

#generator_classObject



38
39
40
# File 'lib/slickr/actions/generate.rb', line 38

def generator_class
  Slickr::Generators.const_get(:"#{@type.capitalize}")
end

#nameObject



42
43
44
# File 'lib/slickr/actions/generate.rb', line 42

def name
  "#{basename}_#{@type}".squeeze("_")
end

#startObject



34
35
36
# File 'lib/slickr/actions/generate.rb', line 34

def start
  generator_class.new(name).start
end