Class: Grably::Core::Product
- Inherits:
-
Object
- Object
- Grably::Core::Product
- Defined in:
- lib/grably/core/product.rb,
lib/grably/core/product.rb
Overview
Product is core, minimal entity in build process. It describes real file with virtual destination. Product instances should be immutable.
Instance Attribute Summary collapse
-
#dst ⇒ Object
readonly
Returns the value of attribute dst.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#src ⇒ Object
readonly
Returns the value of attribute src.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](*keys) ⇒ Object
- #basename(*args) ⇒ Object
- #eql?(other) ⇒ Boolean
- #exist? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(src, dst = nil, meta = {}) ⇒ Product
constructor
A new instance of Product.
- #inspect ⇒ Object
- #map ⇒ Object
- #to_s ⇒ Object
- #update(values) ⇒ Object
Constructor Details
#initialize(src, dst = nil, meta = {}) ⇒ Product
Returns a new instance of Product.
233 234 235 236 237 238 239 |
# File 'lib/grably/core/product.rb', line 233 def initialize(src, dst = nil, = {}) 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.(src) @dst = dst || File.basename(src) @meta = .freeze # Ensure meta is immutable end |
Instance Attribute Details
#dst ⇒ Object (readonly)
Returns the value of attribute dst.
231 232 233 |
# File 'lib/grably/core/product.rb', line 231 def dst @dst end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
231 232 233 |
# File 'lib/grably/core/product.rb', line 231 def @meta end |
#src ⇒ Object (readonly)
Returns the value of attribute src.
231 232 233 |
# File 'lib/grably/core/product.rb', line 231 def src @src end |
Class Method Details
.expand(expr, task = nil) ⇒ Object
295 296 297 |
# File 'lib/grably/core/product.rb', line 295 def (expr, task = nil) Grably::Core::ProductExpand.(expr, task) end |
Instance Method Details
#==(other) ⇒ Object
272 273 274 275 276 277 278 |
# 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) ⇒ Object
241 242 243 244 245 246 247 248 |
# 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) ⇒ Object
288 289 290 |
# File 'lib/grably/core/product.rb', line 288 def basename(*args) File.basename(@dst, *args) end |
#eql?(other) ⇒ Boolean
284 285 286 |
# File 'lib/grably/core/product.rb', line 284 def eql?(other) self == other end |
#exist? ⇒ Boolean
255 256 257 |
# File 'lib/grably/core/product.rb', line 255 def exist? File.exist?(@src) end |
#hash ⇒ Object
280 281 282 |
# File 'lib/grably/core/product.rb', line 280 def hash @src.hash end |
#inspect ⇒ Object
259 260 261 |
# File 'lib/grably/core/product.rb', line 259 def inspect 'Product[src=\'%s\', dst=\'%s\', meta=%s]'.format(src, dst, ) end |
#map ⇒ Object
263 264 265 266 |
# File 'lib/grably/core/product.rb', line 263 def map src, dst, = yield(@src, @dst, @meta) Product.new(src || @src, dst || @dst, || @meta) end |
#to_s ⇒ Object
268 269 270 |
# File 'lib/grably/core/product.rb', line 268 def to_s inspect end |