Class: Sharp::Generator

Inherits:
Object
  • Object
show all
Includes:
FileUtils
Defined in:
lib/sharp/generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Generator

Returns a new instance of Generator.



7
8
9
# File 'lib/sharp/generator.rb', line 7

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/sharp/generator.rb', line 5

def name
  @name
end

#output_dirObject

Returns the value of attribute output_dir.



5
6
7
# File 'lib/sharp/generator.rb', line 5

def output_dir
  @output_dir
end

#source_dirObject

Returns the value of attribute source_dir.



5
6
7
# File 'lib/sharp/generator.rb', line 5

def source_dir
  @source_dir
end

Instance Method Details

#configsObject



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/sharp/generator.rb', line 28

def configs
  {
    #:database => %w[development test production].inject({}) do |cfg, env|
      #cfg[env] = {
        #'adapter' => 'mysql2',
        #'database' => "#{@name}_#{env}",
        #'host' => 'localhost',
        #'user' => 'root'
      #}
      #cfg
    #end
  }
end

#generateObject



19
20
21
22
23
24
25
26
# File 'lib/sharp/generator.rb', line 19

def generate
  cp_r source_dir, output_dir
  configs.each do |config, data|
    open(File.join(output_dir, 'config', "#{config}.yml"), 'w') do |file|
      file << data.to_yaml.sub(/\A---\n/,'')
    end
  end
end