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)


831
832
833
834
835
836
837
838
839
# File 'lib/buildr/core/project.rb', line 831

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)


807
808
809
810
811
812
813
814
815
# File 'lib/buildr/core/project.rb', line 807

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:



774
775
776
777
778
779
780
781
782
783
784
785
# File 'lib/buildr/core/project.rb', line 774

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.



789
790
791
# File 'lib/buildr/core/project.rb', line 789

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

#included(base) ⇒ Object

:nodoc:



762
763
764
765
766
767
768
769
770
771
772
# File 'lib/buildr/core/project.rb', line 762

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