Class: Bowline::Generators::Generator

Inherits:
Templater::Generator
  • Object
show all
Defined in:
lib/bowline/generators.rb

Direct Known Subclasses

MigrationGenerator, NamedGenerator

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.chmod(destination, options = {}) ⇒ Object



99
100
101
102
103
# File 'lib/bowline/generators.rb', line 99

def self.chmod(destination, options = {})
  files << Templater::ActionDescription.new("chmod") do |generator|
    Templater::Actions::Chmod.new(generator, destination, options)
  end
end

.source_rootObject



105
106
107
# File 'lib/bowline/generators.rb', line 105

def self.source_root
  File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. templates]))
end

.touch(destination, options = {}) ⇒ Object



93
94
95
96
97
# File 'lib/bowline/generators.rb', line 93

def self.touch(destination, options = {})
  empty_directories << Templater::ActionDescription.new("touch") do |generator|
    Templater::Actions::Touch.new(generator, destination, options)
  end
end

Instance Method Details

#shebangObject



89
90
91
# File 'lib/bowline/generators.rb', line 89

def shebang
  "#!/usr/bin/env #{RbConfig::CONFIG["RUBY_INSTALL_NAME"]}"
end

#with_modules(modules, options = {}, &block) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/bowline/generators.rb', line 76

def with_modules(modules, options={}, &block)
  indent = options[:indent] || 0
  text = capture(&block)
  modules.each_with_index do |mod, i|
    concat(("  " * (indent + i)) + "module #{mod}\n", block.binding)
  end
  text = text.to_a.map{ |line| ("  " * modules.size) + line }.join
  concat(text, block.binding)
  modules.reverse.each_with_index do |mod, i|
    concat(("  " * (indent + modules.size - i - 1)) + "end # #{mod}\n", block.binding)
  end
end