Class: DjDashboard::Tasks::Install

Inherits:
Object
  • Object
show all
Defined in:
lib/dj_dashboard/tasks/install.rb

Class Method Summary collapse

Class Method Details

.copierObject



60
61
62
63
64
65
66
# File 'lib/dj_dashboard/tasks/install.rb', line 60

def self.copier
  unless @copier
    Rails::Generators::Base.source_root(gem_path)
    @copier = Rails::Generators::Base.new
  end
  @copier
end

.copy_assets_filesObject

TODO: This is wierd…



15
16
17
18
19
20
21
22
# File 'lib/dj_dashboard/tasks/install.rb', line 15

def self.copy_assets_files
  puts 'now copying assets'
  return nil if Rails.version =~ /3.0/ # not needed for rails 3.0
  origin = File.join(gem_path, 'public')
  destination = Rails.root.join('app/assets') if Rails.version =~ /3.1/
  destination = Rails.root.join('public') if Rails.version =~ /3.0/
  copy_files(%w( stylesheets images javascripts ), origin, destination, 'dj_dashboard')
end

.copy_config_filesObject



31
32
33
34
35
36
# File 'lib/dj_dashboard/tasks/install.rb', line 31

def self.copy_config_files
  puts 'now copying initializer file'
  origin = File.join(gem_path, 'config')
  destination = Rails.root.join('config')        
  copy_files(%w( initializers ), origin, destination)
end

.copy_db_filesObject



24
25
26
27
28
29
# File 'lib/dj_dashboard/tasks/install.rb', line 24

def self.copy_db_files
  puts 'now copying db files'
  origin = File.join(gem_path, 'db')
  destination = Rails.root.join('db')
  copy_files(%w( migrate ), origin, destination)
end

.copy_files(directories, origin, destination, prefix = nil) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/dj_dashboard/tasks/install.rb', line 42

def self.copy_files(directories, origin, destination, prefix = nil)
  directories.each do |directory|
    dirs = [origin, directory, prefix, '**/*'].compact
    Dir[File.join(*dirs)].each do |file|
      relative  = file.gsub(/^#{origin}\//, '')
      dirs = [destination, relative].compact
      dest_file = File.join(*dirs)
      dest_dir  = File.dirname(dest_file)

      if !File.exist?(dest_dir)
        FileUtils.mkdir_p(dest_dir)
      end

      copier.copy_file(file, dest_file) unless File.directory?(file)
    end
  end
end

.gem_pathObject



38
39
40
# File 'lib/dj_dashboard/tasks/install.rb', line 38

def self.gem_path
  File.expand_path('../../..', File.dirname(__FILE__))
end

.runObject



6
7
8
9
10
11
12
# File 'lib/dj_dashboard/tasks/install.rb', line 6

def self.run
  puts 'installing dj_dashboard'
  copy_assets_files
  copy_db_files
  copy_config_files
  run_migrations
end

.run_migrationsObject



68
69
70
71
# File 'lib/dj_dashboard/tasks/install.rb', line 68

def self.run_migrations
  puts 'now running migrations'
  Rake::Task['db:migrate'].invoke
end