Class: Baltix::Rake

Inherits:
Object
  • Object
show all
Extended by:
Loader
Defined in:
lib/baltix/rake.rb

Defined Under Namespace

Classes: InvalidRakefileError

Constant Summary collapse

TYPE =
'Rake::Application'
PRELOAD_MATCHER =
{ /\/rakefile(.rb)?$/i => :preload }

Constants included from Log

Log::DEFAULT_IO_NAMES

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Loader

app_file, extended, extended_list, load_file, mods, pre_loaders, type_hash

Methods included from Log

default_prefix, io_name_parse, ios, level, #level_match, #log, prefix, prefix_for, setup, setup_kind

Constructor Details

#initialize(rakefile, options = {}) ⇒ Rake

Returns a new instance of Rake.



39
40
41
42
43
44
45
# File 'lib/baltix/rake.rb', line 39

def initialize rakefile, options = {}
   raise InvalidRakefileError unless File.file?(rakefile)

   @rakefile = rakefile
   @options = options
   @app = self.class.load(rakefile).objects.first
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



13
14
15
# File 'lib/baltix/rake.rb', line 13

def app
  @app
end

#optionsObject (readonly)

Returns the value of attribute options.



13
14
15
# File 'lib/baltix/rake.rb', line 13

def options
  @options
end

#rakefileObject (readonly)

Returns the value of attribute rakefile.



13
14
15
# File 'lib/baltix/rake.rb', line 13

def rakefile
  @rakefile
end

Class Method Details

.load(rakefile) ⇒ Object



53
54
55
# File 'lib/baltix/rake.rb', line 53

def load rakefile
   app_file(rakefile)
end

.preloadObject

preload callback



49
50
51
# File 'lib/baltix/rake.rb', line 49

def preload
   Rake.instance_variable_set(:@application, nil)
end

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/baltix/rake.rb', line 15

def blank?
   !@app
end

#present?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/baltix/rake.rb', line 19

def present?
   !!@app
end

#run_task(task_name) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/baltix/rake.rb', line 27

def run_task task_name
   if @app
      Rake.instance_variable_set(:@application, @app)

      Dir.chdir(@app.original_dir) do
         @app.invoke_task(task_name)
      end
   end
rescue Exception => e
   warn "#{e.class}: #{e.message}\n\t#{e.backtrace.join("\n\t")}"
end

#tasksObject



23
24
25
# File 'lib/baltix/rake.rb', line 23

def tasks
   @tasks ||= @app&.tasks || []
end