Class: Warbler::Application

Inherits:
Rake::Application
  • Object
show all
Includes:
RakeHelper
Defined in:
lib/warbler/application.rb

Overview

Extension of Rake::Application that allows the warble command to report its name properly and inject its own tasks without a Rakefile.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RakeHelper

extended, included

Constructor Details

#initializeApplication

Returns a new instance of Application.



16
17
18
19
20
# File 'lib/warbler/application.rb', line 16

def initialize
  super
  Warbler.application = self
  @project_loaded = false
end

Class Method Details

.runObject

Run the application: The equivalent code for the warble command is simply Warbler::Application.run.



74
# File 'lib/warbler/application.rb', line 74

def self.run; new.run end

Instance Method Details

#load_project_rakefileObject

Loads the project Rakefile in a separate application



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/warbler/application.rb', line 54

def load_project_rakefile
  return if @project_loaded
  # Load any application rakefiles to aid in autodetecting applications
  set_application Warbler.project_application = Rake::Application.new
  Rake::Application::DEFAULT_RAKEFILES.each do |rf|
    if File.exist?(rf)
      begin
        load rf
      rescue LoadError
        load File.join(Dir.getwd, rf)
      end
      break
    end
  end
  set_application
  @project_loaded = true
end

#load_rakefileObject

Sets the application name and loads Warbler’s own tasks



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/warbler/application.rb', line 23

def load_rakefile
  @name = 'warble'

  # Load the main warbler tasks
  wt = Warbler::Task.new

  task :default => wt.name

  desc "Generate a configuration file to customize your archive"
  task :config => "#{wt.name}:config"

  desc "Install Warbler tasks in your Rails application"
  task :pluginize => "#{wt.name}:pluginize"

  desc "Feature: package gem repository inside a jar"
  task :gemjar => "#{wt.name}:gemjar"

  desc "Feature: make an executable archive (runnable + an embedded web server)"
  task :executable => "#{wt.name}:executable"

  desc "Feature: make a runnable archive (e.g. java -jar rails.war -S rake db:migrate)"
  task :runnable => "#{wt.name}:runnable"

  desc "Feature: precompile all Ruby files"
  task :compiled => "#{wt.name}:compiled"

  desc "Display version of Warbler"
  task :version => "#{wt.name}:version"
end

#runObject

Run the application.



77
78
79
80
# File 'lib/warbler/application.rb', line 77

def run
  set_application
  super
end

#standard_rake_optionsObject

Remap the version option to display Warbler version.



83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/warbler/application.rb', line 83

def standard_rake_options
  super.map do |opt|
    if opt.first == '--version'
      ['--version', '-V', "Display the program version.",
       lambda { |value|
         puts "Warbler version #{Warbler::VERSION}"
         exit
       }
      ]
    else
      opt
    end
  end
end