Class: Klenod::Build::Asset
- Inherits:
-
Object
- Object
- Klenod::Build::Asset
- Defined in:
- lib/klenod/build/asset.rb
Instance Attribute Summary collapse
-
#content_hash ⇒ Object
readonly
Returns the value of attribute content_hash.
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#logical_name ⇒ Object
readonly
Returns the value of attribute logical_name.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#output_path ⇒ Object
readonly
Returns the value of attribute output_path.
-
#queue_kind ⇒ Object
readonly
Returns the value of attribute queue_kind.
-
#source_path ⇒ Object
readonly
Returns the value of attribute source_path.
Class Method Summary collapse
Instance Method Summary collapse
- #bytes ⇒ Object
- #failed? ⇒ Boolean
- #generated? ⇒ Boolean
-
#initialize(logical_name, content_hash, output_path, source_path, bytes, content_type, metadata, generator: nil, writer: nil, queue: nil, queue_kind: :cpu) ⇒ Asset
constructor
A new instance of Asset.
- #pending? ⇒ Boolean
- #ready? ⇒ Boolean
- #running? ⇒ Boolean
- #static? ⇒ Boolean
- #wait ⇒ Object
- #write_to(path, &block) ⇒ Object
Constructor Details
#initialize(logical_name, content_hash, output_path, source_path, bytes, content_type, metadata, generator: nil, writer: nil, queue: nil, queue_kind: :cpu) ⇒ Asset
Returns a new instance of Asset.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/klenod/build/asset.rb', line 12 def initialize(logical_name, content_hash, output_path, source_path, bytes, content_type, , generator: nil, writer: nil, queue: nil, queue_kind: :cpu) @logical_name = logical_name @content_hash = content_hash @output_path = output_path @source_path = source_path @bytes = bytes @content_type = content_type @metadata = @generator = generator @writer = writer @queue = queue @queue_kind = queue_kind @disk_path = nil @task = nil @mutex = Mutex.new @state = (bytes || (source_path && !generator && !writer)) ? :ready : :pending @error = nil end |
Instance Attribute Details
#content_hash ⇒ Object (readonly)
Returns the value of attribute content_hash.
10 11 12 |
# File 'lib/klenod/build/asset.rb', line 10 def content_hash @content_hash end |
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
10 11 12 |
# File 'lib/klenod/build/asset.rb', line 10 def content_type @content_type end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
10 11 12 |
# File 'lib/klenod/build/asset.rb', line 10 def error @error end |
#logical_name ⇒ Object (readonly)
Returns the value of attribute logical_name.
10 11 12 |
# File 'lib/klenod/build/asset.rb', line 10 def logical_name @logical_name end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
10 11 12 |
# File 'lib/klenod/build/asset.rb', line 10 def @metadata end |
#output_path ⇒ Object (readonly)
Returns the value of attribute output_path.
10 11 12 |
# File 'lib/klenod/build/asset.rb', line 10 def output_path @output_path end |
#queue_kind ⇒ Object (readonly)
Returns the value of attribute queue_kind.
10 11 12 |
# File 'lib/klenod/build/asset.rb', line 10 def queue_kind @queue_kind end |
#source_path ⇒ Object (readonly)
Returns the value of attribute source_path.
10 11 12 |
# File 'lib/klenod/build/asset.rb', line 10 def source_path @source_path end |
Class Method Details
.generated(logical_name, content_hash, output_path, source_path, content_type, metadata, writer: nil, queue: nil, queue_kind: :cpu, &generator) ⇒ Object
31 32 33 |
# File 'lib/klenod/build/asset.rb', line 31 def self.generated(logical_name, content_hash, output_path, source_path, content_type, , writer: nil, queue: nil, queue_kind: :cpu, &generator) new(logical_name, content_hash, output_path, source_path, nil, content_type, , generator: generator, writer: writer, queue: queue, queue_kind: queue_kind) end |
Instance Method Details
#bytes ⇒ Object
35 36 37 38 |
# File 'lib/klenod/build/asset.rb', line 35 def bytes wait @bytes || File.binread(@disk_path || @source_path) end |
#failed? ⇒ Boolean
63 64 65 |
# File 'lib/klenod/build/asset.rb', line 63 def failed? @state == :failed end |
#generated? ⇒ Boolean
71 72 73 |
# File 'lib/klenod/build/asset.rb', line 71 def generated? !static? end |
#pending? ⇒ Boolean
55 56 57 |
# File 'lib/klenod/build/asset.rb', line 55 def pending? @state == :pending end |
#ready? ⇒ Boolean
51 52 53 |
# File 'lib/klenod/build/asset.rb', line 51 def ready? @state == :ready end |
#running? ⇒ Boolean
59 60 61 |
# File 'lib/klenod/build/asset.rb', line 59 def running? @state == :running end |
#static? ⇒ Boolean
67 68 69 |
# File 'lib/klenod/build/asset.rb', line 67 def static? @generator.nil? && @writer.nil? end |
#wait ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/klenod/build/asset.rb', line 40 def wait return self if ready? raise error if failed? task = start_generation task ? wait_for_task(task) : generate_now_or_queued raise error if failed? self end |
#write_to(path, &block) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/klenod/build/asset.rb', line 75 def write_to(path, &block) path = path.to_s return skip_existing(path) if File.file?(path) task = start_write(path, &block) task ? wait_for_task(task) : write_now_or_queued(path, &block) raise error if failed? :written end |