Class: Rails::Generators::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/generators/ballot/standalone/support.rb

Overview

Implement just enough of Generators to be useful.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



23
24
25
# File 'lib/generators/ballot/standalone/support.rb', line 23

def argv
  @argv
end

#destinationObject

Returns the value of attribute destination.



24
25
26
# File 'lib/generators/ballot/standalone/support.rb', line 24

def destination
  @destination
end

Class Method Details

.desc(value = nil) ⇒ Object

:nodoc:



14
15
16
17
# File 'lib/generators/ballot/standalone/support.rb', line 14

def self.desc(value = nil)
  @desc = value.gsub(/^Description:\n\s+/, '').chomp if value
  @desc
end

.generator_nameObject



19
20
21
# File 'lib/generators/ballot/standalone/support.rb', line 19

def self.generator_name
  name.split(/::/).last.sub(/Generator/, '').downcase
end

Instance Method Details

#migration_template(source, target) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/generators/ballot/standalone/support.rb', line 26

def migration_template(source, target)
  data = File.read(File.join(self.class.source_root, source))
  data = ERB.new(data, 0, '%<>>-').result(binding)

  path, file = File.split(target)

  file = "#{self.class.next_migration_number(nil)}_#{file}"

  File.write(File.join(destination || path, file), data)
end