Class: Aviary::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/aviary/generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#queryObject (readonly)

Returns the value of attribute query.



3
4
5
# File 'lib/aviary/generator.rb', line 3

def query
  @query
end

#sourceObject (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_templateObject

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_pathObject



36
37
38
# File 'lib/aviary/generator.rb', line 36

def generator_path
  File.join(File.dirname(__FILE__), '..', '..', 'generator')
end

#migrateObject

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

#processObject



10
11
12
13
# File 'lib/aviary/generator.rb', line 10

def process
  copy_template
  migrate
end