Module: Cardio::Generators::ClassMethods

Included in:
Base, Deck::DeckGenerator, ModBase
Defined in:
lib/cardio/generators.rb

Overview

methods shared across Generator bases (which inherit from Rails generator classes)

Instance Method Summary collapse

Instance Method Details

Override Rails default banner (using card/decko for the command name).



23
24
25
26
27
# File 'lib/cardio/generators.rb', line 23

def banner
  usage_args = arguments.map(&:usage).join " "
  text = "\n#{banner_command} generate #{namespace} #{usage_args} [options]".green
  text.gsub(/\s+/, " ")
end


29
30
31
# File 'lib/cardio/generators.rb', line 29

def banner_command
  Command.bin_name
end

#namespace(name = nil) ⇒ Object

Override Rails namespace handling so we can put generators in ‘module Cardio`



34
35
36
37
# File 'lib/cardio/generators.rb', line 34

def namespace name=nil
  return super if name
  @namespace ||= super.sub(/cardio:/, "")
end

#source_root(path = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/cardio/generators.rb', line 12

def source_root path=nil
  if path
    @_card_source_root = path
  else
    @_card_source_root ||= File.expand_path(
      "../../generators/#{generator_name}/templates", __FILE__
    )
  end
end