class Grably::Core::Product

Product is core, minimal entity in build process. It describes real file with virtual destination. Product instances should be immutable.

Attributes

dst[R]
meta[R]
src[R]

Public Class Methods

expand(expr, task = nil) click to toggle source
# File lib/grably/core/product.rb, line 295
def expand(expr, task = nil)
  Grably::Core::ProductExpand.expand(expr, task)
end
new(src, dst = nil, meta = {}) click to toggle source
# File lib/grably/core/product.rb, line 233
def initialize(src, dst = nil, meta = {})
  raise 'src should be a string' unless src.is_a?(String)
  raise 'dst should be a string' unless dst.is_a?(String) || dst.nil?
  @src = File.expand_path(src)
  @dst = dst || File.basename(src)
  @meta = meta.freeze # Ensure meta is immutable
end

Public Instance Methods

==(other) click to toggle source
# File lib/grably/core/product.rb, line 272
def ==(other)
  # Everything which not a Product, can't be equal to Product
  return false unless other.is_a? Product

  # Should we include meta in comparison?
  @src.eql?(other.src) && @dst.eql?(other.dst)
end
[](*keys) click to toggle source
# File lib/grably/core/product.rb, line 241
def [](*keys)
  return @meta[keys.first] if keys.size == 1

  # Iterate over keys to preserve order so we can unpack result
  # like:
  # foo, bar = product[:foo, :bar]
  keys.map { |k| @meta[k] }
end
basename(*args) click to toggle source
# File lib/grably/core/product.rb, line 288
def basename(*args)
  File.basename(@dst, *args)
end
eql?(other) click to toggle source
# File lib/grably/core/product.rb, line 284
def eql?(other)
  self == other
end
exist?() click to toggle source
# File lib/grably/core/product.rb, line 255
def exist?
  File.exist?(@src)
end
hash() click to toggle source
# File lib/grably/core/product.rb, line 280
def hash
  @src.hash
end
inspect() click to toggle source
# File lib/grably/core/product.rb, line 259
def inspect
  'Product[src=\'%s\', dst=\'%s\', meta=%s]'.format(src, dst, meta)
end
map() { |src, dst, meta| ... } click to toggle source
# File lib/grably/core/product.rb, line 263
def map
  src, dst, meta = yield(@src, @dst, @meta)
  Product.new(src || @src, dst || @dst, meta || @meta)
end
to_s() click to toggle source
# File lib/grably/core/product.rb, line 268
def to_s
  inspect
end
update(values) click to toggle source
# File lib/grably/core/product.rb, line 250
def update(values)
  # Provide immutable update
  Product.new(@src, @dst, @meta.merge(values))
end