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
-
#after_define(*args, &block) ⇒ Object
This block is called once for the project with the project instance, right after running the project definition.
-
#before_define(*args, &block) ⇒ Object
This block is called once for the project with the project instance, right before running the project definition.
-
#extended(base) ⇒ Object
:nodoc:.
-
#first_time(&block) ⇒ Object
This block will be called once for any particular extension included in Project.
-
#included(base) ⇒ Object
:nodoc:.
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)
854 855 856 857 858 859 860 861 862 |
# File 'lib/buildr/core/project.rb', line 854 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)
830 831 832 833 834 835 836 837 838 |
# File 'lib/buildr/core/project.rb', line 830 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:
797 798 799 800 801 802 803 804 805 806 807 808 |
# File 'lib/buildr/core/project.rb', line 797 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.
812 813 814 |
# File 'lib/buildr/core/project.rb', line 812 def first_time(&block) module_callbacks << Callback.new(:first_time, self.name, [], block) end |
#included(base) ⇒ Object
:nodoc:
785 786 787 788 789 790 791 792 793 794 795 |
# File 'lib/buildr/core/project.rb', line 785 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 |