Sha256: 4a3fd9000f2245996edfd50fe4ef3b09419b53a28d564e1c7323ff06f88fdf3a

Contents?: true

Size: 1.56 KB

Versions: 13

Compression:

Stored size: 1.56 KB

Contents

module Albacore
  def self.create_task(taskname, taskclass)
    # this style of creating tasks is not really what i
    # want to do. but it's necessary for ruby 1.8.6
    # because that version doesn't support the foo do |*args, &block|
    # block signature. it supports *args, but not &block.
    # so that limitation is worked around with string eval
    Object.class_eval(<<-EOF, __FILE__, __LINE__)
      def #{taskname}(name=:#{taskname}, *args, &configblock)
        task name, *args do |t, task_args|
          obj = #{taskclass}.new
          obj.load_config_by_task_name(name) if obj.respond_to?(:load_config_by_task_name)

          if !configblock.nil?
            case configblock.arity
              when 0
                configblock.call
              when 1
                configblock.call(obj)
              when 2
                configblock.call(obj, task_args)
            end
          end

          obj.execute if obj.respond_to?(:execute)
        end
      end

      def #{taskname}!(name=:#{taskname}, *args, &configblock)
        task name, *args do |t, task_args|
          obj = #{taskclass}.new
          obj.load_config_by_task_name(name) if obj.respond_to?(:load_config_by_task_name)

          if !configblock.nil?
            case configblock.arity
              when 0
                configblock.call
              when 1
                configblock.call(obj)
              when 2
                configblock.call(obj, task_args)
            end
          end

          obj.execute if obj.respond_to?(:execute)
        end.invoke
      end
    EOF
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
albacore-1.0.0 lib/albacore/support/createtask.rb
albacore-1.0.0.rc.3 lib/albacore/support/createtask.rb
albacore-0.3.6 lib/albacore/support/createtask.rb
albacore-1.0.0.rc.2 lib/albacore/support/createtask.rb
albacore-1.0.0.rc.1 lib/albacore/support/createtask.rb
albacore-0.3.5 lib/albacore/support/createtask.rb
albacore-0.3.4 lib/albacore/support/createtask.rb
albacore-0.3.3 lib/albacore/support/createtask.rb
albacore-0.3.2 lib/albacore/support/createtask.rb
albacore-0.3.1 lib/albacore/support/createtask.rb
albacore-0.3.0 lib/albacore/support/createtask.rb
albacore-0.2.7 lib/albacore/support/createtask.rb
albacore-0.2.6 lib/albacore/support/createtask.rb