Class: Filament::Target
- Inherits:
-
Object
- Object
- Filament::Target
- Defined in:
- lib/filament/target.rb
Instance Attribute Summary collapse
-
#deployables ⇒ Object
readonly
Returns the value of attribute deployables.
-
#deps ⇒ Object
readonly
Returns the value of attribute deps.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#package ⇒ Object
readonly
Returns the value of attribute package.
-
#weak_deps ⇒ Object
readonly
Returns the value of attribute weak_deps.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
for easy sorting.
-
#[](tag) ⇒ Object
returns the value in the output hash for the given tag.
-
#build(&block) ⇒ Object
builds this specific target (and all dependencies) after building, it executes the provided block in the build context.
- #define ⇒ Object
-
#done? ⇒ Boolean
returns true if the target has completed.
-
#flattened_deps(include_weak = false) ⇒ Object
walks tree of dependencies, returns a complete list.
- #init ⇒ Object
-
#initialize(args, &block) ⇒ Target
constructor
A new instance of Target.
- #invoke ⇒ Object
-
#output(h, &block) ⇒ Object
adds some :output to the given :tag if a block is given, assume that’s the output if :deployable is true, also adds :output to deployables.
- #output_dir ⇒ Object
- #uri ⇒ Object
- #working_dir(subdir = nil) ⇒ Object
Constructor Details
#initialize(args, &block) ⇒ Target
Returns a new instance of Target.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/filament/target.rb', line 14 def initialize(args, &block) if args.is_a? Hash h = args @name = h[:name] else @name = args h = {} end weak_deps = h[:weak_deps] || [] deps = h[:deps] || [] @weak_deps = TargetList.new(*weak_deps) @deps = TargetList.new(*deps) @package = h[:package] || $context[:this_package] @invoked = false @proc = Proc.new {} @outputs = {} @deployables = [] raise 'targets must have a name' if @name.nil? raise 'targets must have a package' if @package.nil? @package << self init @proc = Proc.new do instance_eval(&block) define end end |
Instance Attribute Details
#deployables ⇒ Object (readonly)
Returns the value of attribute deployables.
12 13 14 |
# File 'lib/filament/target.rb', line 12 def deployables @deployables end |
#deps ⇒ Object (readonly)
Returns the value of attribute deps.
12 13 14 |
# File 'lib/filament/target.rb', line 12 def deps @deps end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/filament/target.rb', line 12 def name @name end |
#package ⇒ Object (readonly)
Returns the value of attribute package.
12 13 14 |
# File 'lib/filament/target.rb', line 12 def package @package end |
#weak_deps ⇒ Object (readonly)
Returns the value of attribute weak_deps.
12 13 14 |
# File 'lib/filament/target.rb', line 12 def weak_deps @weak_deps end |
Instance Method Details
#<=>(other) ⇒ Object
for easy sorting
67 68 69 |
# File 'lib/filament/target.rb', line 67 def <=>(other) return (uri <=> other) end |
#[](tag) ⇒ Object
returns the value in the output hash for the given tag
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/filament/target.rb', line 108 def [](tag) invoke o = @outputs[tag] return nil if o.nil? tasks = o[:tasks] tasks.each {|t| t.invoke} unless tasks.nil? return o[:output] end |
#build(&block) ⇒ Object
builds this specific target (and all dependencies) after building, it executes the provided block in the build context
122 123 124 125 126 127 |
# File 'lib/filament/target.rb', line 122 def build(&block) @package.build_context.execute do invoke block.call unless block.nil? end end |
#define ⇒ Object
50 |
# File 'lib/filament/target.rb', line 50 def define; end |
#done? ⇒ Boolean
returns true if the target has completed
130 131 132 |
# File 'lib/filament/target.rb', line 130 def done? return @invoked end |
#flattened_deps(include_weak = false) ⇒ Object
walks tree of dependencies, returns a complete list
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/filament/target.rb', line 72 def flattened_deps(include_weak=false) all = @deps.to_a.clone all += @weak_deps.to_a.clone if include_weak fd = [] until all.empty? d = all.pop unless fd.include?(d) fd << d all += d.deps all += d.weak_deps if include_weak end end return fd end |
#init ⇒ Object
48 |
# File 'lib/filament/target.rb', line 48 def init; end |
#invoke ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/filament/target.rb', line 134 def invoke return if done? @invoked = true @package.execute do @weak_deps.each {|t| t.invoke} @deps.each {|t| t.invoke} puts ">>> BUILDING #{uri} (#{@package.pathname}, #{self})" instance_eval(&@proc) @outputs.values.select{|h| h.key?(:tasks)}.collect{|h| h[:tasks]}.each do |tasks| tasks.each do |t| t.invoke end end end end |
#output(h, &block) ⇒ Object
adds some :output to the given :tag if a block is given, assume that’s the output if :deployable is true, also adds :output to deployables
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/filament/target.rb', line 91 def output(h, &block) tag = h[:tag] h[:output] ||= block if tag.respond_to?(:to_ary) tag.to_ary.each do |t| h2 = h.clone h2[:tag] = t output(h2) end else @outputs[tag] = h end @deployables << h[:output] if h[:deployable] end |
#output_dir ⇒ Object
58 59 60 |
# File 'lib/filament/target.rb', line 58 def output_dir return "#{$context[:output_dir]}/#{package.path}" end |
#uri ⇒ Object
62 63 64 |
# File 'lib/filament/target.rb', line 62 def uri return "#{@package.uri}:#{@name}" end |
#working_dir(subdir = nil) ⇒ Object
52 53 54 55 56 |
# File 'lib/filament/target.rb', line 52 def working_dir(subdir=nil) base = "#{$context[:working_dir]}/#{package.path}/#{name}" return subdir.nil? ? base : "#{base}/#{subdir.to_s}" end |