Class: Aviary::Generator
- Inherits:
-
Object
- Object
- Aviary::Generator
- Defined in:
- lib/aviary/generator.rb
Instance Attribute Summary collapse
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
-
#copy_template ⇒ Object
Copies the contents of the
generator
directory into thesource
directory for setting up a new aviary. - #generator_path ⇒ Object
-
#initialize(config) ⇒ Generator
constructor
A new instance of Generator.
-
#migrate ⇒ Object
Migrates the database for the first time.
- #process ⇒ Object
Constructor Details
#initialize(config) ⇒ Generator
Returns a new instance of Generator.
5 6 7 8 |
# File 'lib/aviary/generator.rb', line 5 def initialize(config) @source = config[:source] @query = config[:query] end |
Instance Attribute Details
#query ⇒ Object (readonly)
Returns the value of attribute query.
3 4 5 |
# File 'lib/aviary/generator.rb', line 3 def query @query end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
3 4 5 |
# File 'lib/aviary/generator.rb', line 3 def source @source end |
Instance Method Details
#copy_template ⇒ Object
Copies the contents of the generator
directory into the source
directory for setting up a new aviary.
Returns nothing.
26 27 28 29 30 31 32 33 34 |
# File 'lib/aviary/generator.rb', line 26 def copy_template FileUtils.mkdir_p(self.source) unless File.exists?(self.source) File.open(File.join(self.source, 'template.erb'), 'w') do |file| erb = File.read(File.join(generator_path, 'template.erb')) erb.gsub!('{{query}}', self.query) if self.query file.write(erb) end FileUtils.cp_r File.join(generator_path, '_assets'), self.source end |
#generator_path ⇒ Object
36 37 38 |
# File 'lib/aviary/generator.rb', line 36 def generator_path File.join(File.dirname(__FILE__), '..', '..', 'generator') end |
#migrate ⇒ Object
Migrates the database for the first time.
Returns nothing.
18 19 20 |
# File 'lib/aviary/generator.rb', line 18 def migrate DataMapper.auto_migrate! end |
#process ⇒ Object
10 11 12 13 |
# File 'lib/aviary/generator.rb', line 10 def process copy_template migrate end |