Class: Sharp::Generator
- Inherits:
-
Object
- Object
- Sharp::Generator
- Includes:
- FileUtils
- Defined in:
- lib/sharp/generator.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#output_dir ⇒ Object
Returns the value of attribute output_dir.
-
#source_dir ⇒ Object
Returns the value of attribute source_dir.
Instance Method Summary collapse
- #configs ⇒ Object
- #generate ⇒ Object
-
#initialize(name) ⇒ Generator
constructor
A new instance of Generator.
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
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/sharp/generator.rb', line 5 def name @name end |
#output_dir ⇒ Object
Returns the value of attribute output_dir.
5 6 7 |
# File 'lib/sharp/generator.rb', line 5 def output_dir @output_dir end |
#source_dir ⇒ Object
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
#configs ⇒ Object
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 |
#generate ⇒ Object
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 |