Sha256: 4cfe51a4601ac66c6e9c99d309753009ab273d2b9ef58116f48be7e3bdf4a802

Contents?: true

Size: 1.32 KB

Versions: 2

Compression:

Stored size: 1.32 KB

Contents

# returning(obj) and with(obj)
require "facet/kernel/with"
# &:symbol goodness.
require "facet/symbol/to_proc"
# blank? on string and nil
require "facet/string/blank"
require "facet/nilclass/blank"
# What it says.
require "facet/module/alias_method_chain"
require "highline"


module Kernel
  def warn_with_color(message)
    warn_without_color HighLine.new.color(message.to_s, :red)
  end
  alias_method_chain :warn, :color
end


module Buildr
  module Attributes

    def self.included(mod)
      mod.extend(self)
    end

    # An inherited attribute gets it value from an instance variable
    # with the same name. If the value is not set it will defer to the
    # parent object. If there is no parent object, it will use the
    # default value; with a block, it evaluates the block by calling
    # instance_eval on the object.
    #
    # For example:
    #   inherited_attr :version
    #   inherited_attr :src_dir, "src"
    #   inherited_attr :java_src_dir do src_dir + "/main/java"
    def inherited_attr(symbol, default = nil, &block)
      block ||= proc { default }
      define_method symbol do
        instance_variable_get("@#{symbol}") || (parent ? parent.send(symbol) : self.instance_eval(&block))
      end
      define_method "#{symbol}=" do |value|
        instance_variable_set("@#{symbol}", value)
      end
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
buildr-0.14.0 lib/core/core.rb
buildr-0.15.0 lib/core/core.rb