Module: Buildr::Extension::ClassMethods

Defined in:
lib/buildr/core/project.rb

Overview

Methods added to the extension module when including Extension.

Instance Method Summary collapse

Instance Method Details

#after_define(*args, &block) ⇒ Object

This block is called once for the project with the project instance, right after running the project definition. You can use this to do any post-processing that depends on the project definition.

The block may be named and dependencies may be declared similar to Rake task dependencies:

after_define(:my_setup) do |project|
  # do stuff on project
end

# my_setup code must run before :compile (but only after project is defined)
after_define(:compile => :my_setup)


835
836
837
838
839
840
841
842
843
# File 'lib/buildr/core/project.rb', line 835

def after_define(*args, &block)
  if args.empty?
    name = self.name
    deps = []
  else
    name, args, deps = Buildr.application.resolve_args(args)
  end
  module_callbacks << Callback.new(:after_define, name, deps, block)
end

#before_define(*args, &block) ⇒ Object

This block is called once for the project with the project instance, right before running the project definition. You can use this to add tasks and set properties that will be used in the project definition.

The block may be named and dependencies may be declared similar to Rake task dependencies:

before_define(:my_setup) do |project|
  # do stuff on project
end

# my_setup code must run before :compile
before_define(:compile => :my_setup)


811
812
813
814
815
816
817
818
819
# File 'lib/buildr/core/project.rb', line 811

def before_define(*args, &block)
  if args.empty?
    name = self.name
    deps = []
  else
    name, args, deps = Buildr.application.resolve_args(args)
  end
  module_callbacks << Callback.new(:before_define, name, deps, block)
end

#extended(base) ⇒ Object

:nodoc:



778
779
780
781
782
783
784
785
786
787
788
789
# File 'lib/buildr/core/project.rb', line 778

def extended(base) #:nodoc:
  # When extending project, merge after_define callbacks and call before_define callback(s)
  # immediately
  if Project === base
    merge_callbacks(base.callbacks, module_callbacks.select { |cb| cb.phase == :after_define })
    calls = module_callbacks.select { |cb| cb.phase == :before_define }
    calls.each do |cb|
      cb.blocks.each { |b| b.call(base) } unless base.calledback[cb]
      base.calledback[cb] = cb
    end
  end
end

#first_time(&block) ⇒ Object

This block will be called once for any particular extension included in Project. You can use this to setup top-level and local tasks.



793
794
795
# File 'lib/buildr/core/project.rb', line 793

def first_time(&block)
  module_callbacks << Callback.new(:first_time, self.name, [], block)
end

#included(base) ⇒ Object

:nodoc:



766
767
768
769
770
771
772
773
774
775
776
# File 'lib/buildr/core/project.rb', line 766

def included(base) #:nodoc:
  # When included in Project, add module instance, merge callbacks and call first_time.
  if Project == base && !base.extension_modules.include?(module_callbacks)
    base.extension_modules << module_callbacks
    merge_callbacks(base.global_callbacks, module_callbacks)
    first_time = module_callbacks.select { |c| c.phase == :first_time }
    first_time.each do |c|
      c.blocks.each { |b| b.call }
    end
  end
end