Class: Migu::Generator
- Inherits:
-
Object
- Object
- Migu::Generator
- Defined in:
- lib/migu/generator.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #generate(name) ⇒ Object
- #generate_config ⇒ Object
-
#initialize ⇒ Generator
constructor
A new instance of Generator.
Constructor Details
#initialize ⇒ Generator
Returns a new instance of Generator.
7 8 9 |
# File 'lib/migu/generator.rb', line 7 def initialize @path = "migu/migrate" end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/migu/generator.rb', line 5 def path @path end |
Instance Method Details
#generate(name) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/migu/generator.rb', line 11 def generate(name) time = Time.now filename = "#{time.strftime("%Y%m%d%H%M%S")}_#{name}.rb" filepath = File.join(path, filename) Dir.mkdir(path) unless Dir.exist?(path) File.open(filepath, "w") do |file| file.write(<<-EOS) class #{name.camelize} < Migu::Migration def self.time "#{time.to_s}" end def up end def down end end EOS return filepath end end |
#generate_config ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/migu/generator.rb', line 35 def generate_config Dir.mkdir("migu") unless Dir.exist?("migu") filepath = "migu/config.rb" File.open(filepath, "w") do |file| file.write(<<-EOS) Migu.configuration do |config| config.before do # before hook end config.after do # after hook end end EOS end end |