Sha256: ac86f0d81f2ef89d7776a53c16823d8d20efd1e70ffba856b09fd8c2a532ad26

Contents?: true

Size: 1.04 KB

Versions: 10

Compression:

Stored size: 1.04 KB

Contents

require 'rake/tasklib'
require 'mattock/cascading-definition'

module Mattock
  class TaskLib < Rake::TaskLib
    include CascadingDefinition

    attr_writer :namespace_name
    def self.default_namespace(name)
      setting(:namespace_name, name)
    end

    attr_reader :tasks

    def initialize(*toolkits)
      @tasks = []
      super
    end

    def task(*args)
      a_task = super
      @tasks << a_task
      return a_task
    end

    def in_namespace(*tasknames)
      if tasknames.empty?
        if block_given?
          if @namespace_name.nil?
            yield
          else
            namespace @namespace_name do
              yield
            end
          end
        end
      else
        tasknames.map do |taskname|
          [@namespace_name, taskname].compact.join(":")
        end
      end
    end

    def root_task
      @namespace_name || :default
    end

    def default_namespace
      nil
    end

    def [](taskname)
      in_namespace(taskname).first
    end
  end
  Tasklib = TaskLib #Because I can never remember
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
mattock-0.2.5 lib/mattock/tasklib.rb
mattock-0.2.4 lib/mattock/tasklib.rb
mattock-0.2.3 lib/mattock/tasklib.rb
mattock-0.2.2 lib/mattock/tasklib.rb
mattock-0.2.1 lib/mattock/tasklib.rb
mattock-0.2.0 lib/mattock/tasklib.rb
mattock-0.1.3 lib/mattock/tasklib.rb
mattock-0.1.2 lib/mattock/tasklib.rb
mattock-0.1.1 lib/mattock/tasklib.rb
mattock-0.1.0 lib/mattock/tasklib.rb