Class: Squared::Workspace::Project::Base
- Inherits:
-
Object
- Object
- Squared::Workspace::Project::Base
- Includes:
- Rake::DSL, Shell, Common::Format, System, Utils
- Defined in:
- lib/squared/workspace/project/base.rb
Direct Known Subclasses
Constant Summary collapse
- @@task_desc =
Rake::TaskManager.
- @@print_order =
0
Constants included from Common
Instance Attribute Summary collapse
-
#dependfile ⇒ Object
readonly
Returns the value of attribute dependfile.
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#pipe ⇒ Object
readonly
Returns the value of attribute pipe.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#theme ⇒ Object
readonly
Returns the value of attribute theme.
-
#verbose ⇒ Object
readonly
Returns the value of attribute verbose.
-
#workspace ⇒ Object
readonly
Returns the value of attribute workspace.
Class Method Summary collapse
- .aliasargs ⇒ Object
- .as_path(val) ⇒ Object
- .bannerargs ⇒ Object
- .batchargs ⇒ Object
- .config? ⇒ Boolean
- .populate ⇒ Object
- .ref ⇒ Object
- .tasks ⇒ Object
- .to_s ⇒ Object
Instance Method Summary collapse
- #add(path, name = nil, **kwargs, &blk) ⇒ Object
- #allref ⇒ Object
- #basepath(*args, ascend: nil) ⇒ Object
- #build(*args, from: :build, sync: invoked_sync?('build')) ⇒ Object
- #build? ⇒ Boolean
- #clean(sync: invoked_sync?('clean')) ⇒ Object
- #clean? ⇒ Boolean
- #copy(sync: invoked_sync?('copy')) ⇒ Object
- #copy? ⇒ Boolean
- #depend(sync: invoked_sync?('depend')) ⇒ Object
- #depend? ⇒ Boolean
- #dependtype ⇒ Object
- #dev? ⇒ Boolean
- #doc(sync: invoked_sync?('doc')) ⇒ Object
- #doc? ⇒ Boolean
- #enabled?(ref = nil) ⇒ Boolean
- #error(key, *args, **kwargs, &blk) ⇒ Object
- #event(name, key, *args, **kwargs, &blk) ⇒ Object
- #exclude?(*refs) ⇒ Boolean
- #first(key, *args, **kwargs, &blk) ⇒ Object
- #generate(keys) ⇒ Object
- #graph(start = [], tasks = nil, sync: invoked_sync?('graph'), pass: [], out: nil) ⇒ Object
- #graph? ⇒ Boolean
- #has?(meth, ref = nil) ⇒ Boolean
-
#initialize(workspace, path, name, group: nil, graph: nil, pass: nil, exclude: nil, first: {}, last: {}, error: {}, common: , **kwargs) ⇒ Base
constructor
A new instance of Base.
- #initialize_build(ref, **kwargs) ⇒ Object
- #initialize_env(dev: nil, prod: nil) ⇒ Object
- #initialize_events(ref) ⇒ Object
- #initialize_logger(log: nil) ⇒ Object
- #initialize_ref(ref) ⇒ Object
- #inject(obj, *args, **kwargs, &blk) ⇒ Object
- #inspect ⇒ Object
- #last(key, *args, **kwargs, &blk) ⇒ Object
- #localname ⇒ Object
- #log ⇒ Object
- #populate(keys) ⇒ Object
- #prod? ⇒ Boolean
- #ref ⇒ Object
- #ref?(val) ⇒ Boolean
- #script? ⇒ Boolean
- #task_include?(key, ref = nil) ⇒ Boolean
- #test(sync: invoked_sync?('test')) ⇒ Object
- #test? ⇒ Boolean
- #to_s ⇒ Object
- #to_sym ⇒ Object
- #variable_set(key, *val, **kwargs) ⇒ Object
- #version ⇒ Object
- #with(**kwargs, &blk) ⇒ Object
Methods included from Common::Format
Constructor Details
#initialize(workspace, path, name, group: nil, graph: nil, pass: nil, exclude: nil, first: {}, last: {}, error: {}, common: , **kwargs) ⇒ Base
Returns a new instance of Base.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/squared/workspace/project/base.rb', line 62 def initialize(workspace, path, name, *, group: nil, graph: nil, pass: nil, exclude: nil, first: {}, last: {}, error: {}, common: ARG[:COMMON], **kwargs) @path = path @workspace = workspace @name = name.to_s.freeze @project = @path.basename.to_s.freeze @group = group&.to_s.freeze @depend = kwargs[:depend] @doc = kwargs[:doc] @test = kwargs[:test] @copy = kwargs[:copy] @clean = kwargs[:clean] @version = kwargs[:version] @exception = kwargs.key?(:exception) ? env_bool(kwargs[:exception]) : workspace.exception @pipe = kwargs.key?(:pipe) ? env_pipe(kwargs[:pipe]) : workspace.pipe @verbose = kwargs.key?(:verbose) ? kwargs[:verbose] : workspace.verbose @theme = if !@verbose {} elsif common workspace.theme else __get__(:theme)[:project][to_sym] ||= {} end @output = [] @ref = [] @children = [] @graph = if graph as_a(graph, workspace.prefix ? ->(val) { workspace.task_name(val).to_sym } : :to_sym).freeze end @pass = (pass ? as_a(pass) : []).freeze @exclude = (exclude ? as_a(exclude, :to_sym) : []).freeze @events = { first: first, last: last, error: error } @envname = @name.gsub(/[^\w]+/, '_').upcase.freeze @desc = (@name.include?(':') ? @name.split(':').join(ARG[:SPACE]) : @name).freeze @parent = nil @global = false run_set(kwargs[:run], kwargs[:env], opts: kwargs.fetch(:opts, true)) initialize_ref(Base.ref) end |
Instance Attribute Details
#dependfile ⇒ Object (readonly)
Returns the value of attribute dependfile.
59 60 61 |
# File 'lib/squared/workspace/project/base.rb', line 59 def dependfile @dependfile end |
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
59 60 61 |
# File 'lib/squared/workspace/project/base.rb', line 59 def exception @exception end |
#group ⇒ Object (readonly)
Returns the value of attribute group.
59 60 61 |
# File 'lib/squared/workspace/project/base.rb', line 59 def group @group end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
59 60 61 |
# File 'lib/squared/workspace/project/base.rb', line 59 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
59 60 61 |
# File 'lib/squared/workspace/project/base.rb', line 59 def parent @parent end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
59 60 61 |
# File 'lib/squared/workspace/project/base.rb', line 59 def path @path end |
#pipe ⇒ Object (readonly)
Returns the value of attribute pipe.
59 60 61 |
# File 'lib/squared/workspace/project/base.rb', line 59 def pipe @pipe end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
59 60 61 |
# File 'lib/squared/workspace/project/base.rb', line 59 def project @project end |
#theme ⇒ Object (readonly)
Returns the value of attribute theme.
59 60 61 |
# File 'lib/squared/workspace/project/base.rb', line 59 def theme @theme end |
#verbose ⇒ Object (readonly)
Returns the value of attribute verbose.
59 60 61 |
# File 'lib/squared/workspace/project/base.rb', line 59 def verbose @verbose end |
#workspace ⇒ Object (readonly)
Returns the value of attribute workspace.
59 60 61 |
# File 'lib/squared/workspace/project/base.rb', line 59 def workspace @workspace end |
Class Method Details
.aliasargs ⇒ Object
24 |
# File 'lib/squared/workspace/project/base.rb', line 24 def aliasargs(*); end |
.as_path(val) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/squared/workspace/project/base.rb', line 31 def as_path(val) case val when Pathname val when String Pathname.new(val) end end |
.bannerargs ⇒ Object
25 |
# File 'lib/squared/workspace/project/base.rb', line 25 def (*); end |
.batchargs ⇒ Object
23 |
# File 'lib/squared/workspace/project/base.rb', line 23 def batchargs(*); end |
.config? ⇒ Boolean
44 45 46 |
# File 'lib/squared/workspace/project/base.rb', line 44 def config?(*) false end |
.populate ⇒ Object
22 |
# File 'lib/squared/workspace/project/base.rb', line 22 def populate(*); end |
.ref ⇒ Object
40 41 42 |
# File 'lib/squared/workspace/project/base.rb', line 40 def ref @ref ||= to_s.downcase.to_sym end |
.tasks ⇒ Object
27 28 29 |
# File 'lib/squared/workspace/project/base.rb', line 27 def tasks %i[build depend graph doc test copy clean].freeze end |
.to_s ⇒ Object
48 49 50 |
# File 'lib/squared/workspace/project/base.rb', line 48 def to_s super.match(/[^:]+\z/)[0] end |
Instance Method Details
#add(path, name = nil, **kwargs, &blk) ⇒ Object
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
# File 'lib/squared/workspace/project/base.rb', line 295 def add(path, name = nil, **kwargs, &blk) checkdir = lambda do |val| if val.directory? && !val.empty? true else log.warn "workspace \"#{val}\" (#{val.empty? ? 'empty' : 'not found'})" false end end if path.is_a?(String) && (data = %r{^(.+)[\\/]\*+$}.match(path)) return self unless checkdir.(path = basepath(data[1])) path = path.children.select { |val| checkdir.(val) } end if path.is_a?(Array) name = @name if name == true path.each { |val| add(val, name && task_join(name, File.basename(val)), **kwargs, &blk) } return self elsif !projectpath?(path = basepath(path)) || !checkdir.(path) return self elsif name.is_a?(Symbol) name = name.to_s elsif !name.is_a?(String) name = nil end if @withargs data = @withargs.dup data.merge!(kwargs) kwargs = data end kwargs[:group] = group unless kwargs.key?(:group) kwargs[:ref] = ref unless kwargs.key?(:ref) parent = self proj = nil workspace.add(path, name || path.basename, **kwargs) do variable_set :parent, parent proj = self end @children << proj proj.instance_eval(&blk) if block_given? self end |
#allref ⇒ Object
587 588 589 |
# File 'lib/squared/workspace/project/base.rb', line 587 def allref @ref.reverse_each end |
#basepath(*args, ascend: nil) ⇒ Object
591 592 593 594 595 596 597 598 599 600 601 |
# File 'lib/squared/workspace/project/base.rb', line 591 def basepath(*args, ascend: nil) ret = path.join(*args) return ret unless ascend && !ret.exist? path.parent.ascend.each do |dir| target = dir.join(*args) return target if target.exist? break if (ascend.is_a?(String) && dir.join(ascend).exist?) || workspace.root == dir || parent&.path == dir end ret end |
#build(*args, from: :build, sync: invoked_sync?('build')) ⇒ Object
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
# File 'lib/squared/workspace/project/base.rb', line 350 def build(*args, from: :build, sync: invoked_sync?('build'), **) = verbose if args.empty? return unless from == :build cmd, opts, var, flags = @output = verbose == 1 if task_invoked?('build', 'build:sync') else cmd = args.shift opts = args.map { |val| shell_quote(val, force: false) }.join(' ') end if cmd case opts when String cmd = "#{cmd} #{opts}" when Array cmd = as_a(cmd).concat(opts).join(' && ') else cmd = [cmd, compose(opts, script: false)].compact.join(' ') unless opts == false || !respond_to?(:compose) end else return unless respond_to?(:compose) cmd = compose(opts, flags, from: from, script: true) end run(cmd, var, from: from, banner: , sync: sync) end |
#build? ⇒ Boolean
523 524 525 |
# File 'lib/squared/workspace/project/base.rb', line 523 def build? !!@output[0] || script? end |
#clean(sync: invoked_sync?('clean')) ⇒ Object
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 |
# File 'lib/squared/workspace/project/base.rb', line 402 def clean(*, sync: invoked_sync?('clean'), **) return unless @clean on :first, :clean case @clean when String run(@clean, from: :clean, sync: sync) when Enumerable (@clean.is_a?(Hash) ? @clean.values : as_a(@clean)).each do |val| val = val.to_s path = basepath(val) if path.directory? && val =~ %r{[\\/]\z} log.warn "rm -rf #{path}" path.rmtree(verbose: true) else log.warn "rm #{path}" (val.include?('*') ? Dir[path] : [path]).each do |file| next unless File.file?(file) begin File.delete(file) rescue StandardError => e log.error e end end end end end on :last, :clean end |
#clean? ⇒ Boolean
551 552 553 |
# File 'lib/squared/workspace/project/base.rb', line 551 def clean? runnable?(@clean) || workspace.task_defined?(name, 'clean') end |
#copy(sync: invoked_sync?('copy')) ⇒ Object
384 385 386 387 388 |
# File 'lib/squared/workspace/project/base.rb', line 384 def copy(*, sync: invoked_sync?('copy'), **) return unless @copy run_s(@copy, from: :copy, sync: sync) end |
#copy? ⇒ Boolean
539 540 541 |
# File 'lib/squared/workspace/project/base.rb', line 539 def copy? runnable?(@copy) || workspace.task_defined?(name, 'copy') end |
#depend(sync: invoked_sync?('depend')) ⇒ Object
378 379 380 381 382 |
# File 'lib/squared/workspace/project/base.rb', line 378 def depend(*, sync: invoked_sync?('depend'), **) return unless @depend run(@depend, from: :depend, sync: sync) end |
#depend? ⇒ Boolean
531 532 533 |
# File 'lib/squared/workspace/project/base.rb', line 531 def depend? !!@depend end |
#dependtype ⇒ Object
577 578 579 |
# File 'lib/squared/workspace/project/base.rb', line 577 def dependtype(*) @dependindex ? @dependindex.succ : 0 end |
#dev? ⇒ Boolean
555 556 557 |
# File 'lib/squared/workspace/project/base.rb', line 555 def dev? @dev != false && workspace.dev?(pat: @dev, **scriptargs) end |
#doc(sync: invoked_sync?('doc')) ⇒ Object
390 391 392 393 394 |
# File 'lib/squared/workspace/project/base.rb', line 390 def doc(*, sync: invoked_sync?('doc'), **) return unless @doc build(*as_a(@doc), from: :doc, sync: sync) end |
#doc? ⇒ Boolean
543 544 545 |
# File 'lib/squared/workspace/project/base.rb', line 543 def doc? !!@doc end |
#enabled?(ref = nil) ⇒ Boolean
507 508 509 510 511 |
# File 'lib/squared/workspace/project/base.rb', line 507 def enabled?(ref = nil, **) return false if ref && !ref?(ref) path.directory? && !path.empty? end |
#error(key, *args, **kwargs, &blk) ⇒ Object
471 472 473 |
# File 'lib/squared/workspace/project/base.rb', line 471 def error(key, *args, **kwargs, &blk) event(:error, key, *args, **kwargs, &blk) end |
#event(name, key, *args, **kwargs, &blk) ⇒ Object
475 476 477 |
# File 'lib/squared/workspace/project/base.rb', line 475 def event(name, key, *args, **kwargs, &blk) (@events[name.to_sym] ||= {})[key.to_sym] = [block_given? ? [blk] + args : args, kwargs] end |
#exclude?(*refs) ⇒ Boolean
563 564 565 566 567 |
# File 'lib/squared/workspace/project/base.rb', line 563 def exclude?(*refs) return false if @exclude.empty? refs.flatten.any? { |ref| @exclude.include?(ref) } end |
#first(key, *args, **kwargs, &blk) ⇒ Object
463 464 465 |
# File 'lib/squared/workspace/project/base.rb', line 463 def first(key, *args, **kwargs, &blk) event(:first, key, *args, **kwargs, &blk) end |
#generate(keys) ⇒ Object
282 283 284 |
# File 'lib/squared/workspace/project/base.rb', line 282 def generate(keys, **) task_build keys end |
#graph(start = [], tasks = nil, sync: invoked_sync?('graph'), pass: [], out: nil) ⇒ Object
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 |
# File 'lib/squared/workspace/project/base.rb', line 433 def graph(start = [], tasks = nil, sync: invoked_sync?('graph'), pass: [], out: nil) if (val = env('GRAPH', strict: true)) tasks ||= [] split_escape(val).each do |task| if ref?(task.to_sym) && (script = workspace.script_get(:graph, ref: task.to_sym)) tasks += script[:graph] else tasks << task end end end pass.concat(split_escape(val)) if (val = env('GRAPH_PASS', strict: true)) data = graph_collect(self, start) unless out data[name] << self on :first, :graph end begin done = graph_branch(self, data, tasks, out, sync: sync, pass: pass) rescue StandardError => e ret = on(:error, :graph, e) raise unless ret == true end if out [out, done] else on :last, :graph end end |
#graph? ⇒ Boolean
535 536 537 |
# File 'lib/squared/workspace/project/base.rb', line 535 def graph? @graph.is_a?(Array) && !@graph.empty? end |
#has?(meth, ref = nil) ⇒ Boolean
513 514 515 516 517 |
# File 'lib/squared/workspace/project/base.rb', line 513 def has?(meth, ref = nil) return false if ref && !ref?(ref) respond_to?(meth = :"#{meth}?") && __send__(meth) end |
#initialize_build(ref, **kwargs) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/squared/workspace/project/base.rb', line 110 def initialize_build(ref, **kwargs) initialize_ref(ref) if (@script = @workspace.script_get(group: @group, ref: ref)) if @script[:log] && !kwargs.key?(:log) kwargs[:log] = @script[:log] @log = nil end @depend = @script[:depend] if @depend.nil? @doc = @script[:doc] if @doc.nil? @test = @script[:test] if @test.nil? @clean = @script[:clean] if @clean.nil? @exclude = @script[:exclude] if @exclude.empty? && @script.key?(:exclude) end initialize_events(ref, **kwargs) initialize_logger(**kwargs) return if @output[0] == false data = @workspace.script_find(*@ref, @group) if @output[0].nil? if (scr = data[:script]) @global = true script_set(scr, prod: kwargs[:prod]) elsif (run = data[:run]) @global = true run_set run end unless data[:env] if (scr = kwargs[:script]) @global = false script_set scr elsif @script && !data[:global] if (scr = @script[:script]) @global = false script_set scr elsif (run = @script[:run]) @global = false run_set run end end end elsif data[:env] && data[:run] @global = true run_set data[:run] end end |
#initialize_env(dev: nil, prod: nil) ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/squared/workspace/project/base.rb', line 196 def initialize_env(dev: nil, prod: nil, **) pre = "BUILD_#{@envname}" @dev = env_match("#{pre}_DEV", dev) @prod = env_match("#{pre}_PROD", prod) cmd = @output[0] unless cmd == false || cmd.is_a?(Array) || (val = env('BUILD', suffix: 'OPTS')).nil? @output[cmd ? 1 : 3] = shell_split(val, join: true) end unless @output[2] == false || (val = env('BUILD', suffix: 'ENV')).nil? begin data = JSON.parse(val) raise_error('invalid JSON object', val, hint: "#{prefix}_ENV") unless data.is_a?(Hash) rescue StandardError => e log.warn e else @output[2] = data end end @version = val if (val = env('BUILD', suffix: 'VERSION')) return unless (val = env('BUILD', strict: true)) @global = false if val == '0' @output = [false] elsif script? script_set val else run_set val end end |
#initialize_events(ref) ⇒ Object
156 157 158 159 160 |
# File 'lib/squared/workspace/project/base.rb', line 156 def initialize_events(ref, **) return unless (events = @workspace.events_get(group: @group, ref: ref)) events.each { |task, data| data.each { |ev, blk| (@events[ev] ||= {})[task] ||= blk } } end |
#initialize_logger(log: nil) ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/squared/workspace/project/base.rb', line 162 def initialize_logger(log: nil, **) return if @log log = log.is_a?(Hash) ? log.dup : { file: log } unless (file = env('LOG_FILE')) file = case env('LOG_AUTO') when 'y', 'year' "#{@name}-#{Date.today.year}.log" when 'm', 'month' "#{@name}-#{Date.today.strftime('%Y-%m')}.log" when 'd', 'day', '1' "#{@name}-#{Date.today}.log" end end if file ||= log[:file] file = Date.today.strftime(file) file = (dir = env('LOG_DIR')) ? @workspace.home.join(dir, file) : @workspace.home.join(file) begin file = file.realdirpath rescue StandardError => e raise if @exception file = nil warn (Logger::WARN, e) if warning? end end log[:progname] ||= @name if (val = env('LOG_LEVEL', ignore: false)) log[:level] = val end log.delete(:file) @log = [file, log] end |
#initialize_ref(ref) ⇒ Object
106 107 108 |
# File 'lib/squared/workspace/project/base.rb', line 106 def initialize_ref(ref) @ref << ref unless @exclude.include?(ref) end |
#inject(obj, *args, **kwargs, &blk) ⇒ Object
338 339 340 341 342 343 344 345 346 347 348 |
# File 'lib/squared/workspace/project/base.rb', line 338 def inject(obj, *args, **kwargs, &blk) return self unless enabled? out = obj.link(self, *args, **kwargs, &blk) if obj.respond_to?(:link) if !out warn (:warn, 'link not compatible', subject: obj.to_s, hint: name) elsif out.respond_to?(:build) out.build end self end |
#inspect ⇒ Object
607 608 609 |
# File 'lib/squared/workspace/project/base.rb', line 607 def inspect "#<#{self.class}: #{name} => #{self}>" end |
#last(key, *args, **kwargs, &blk) ⇒ Object
467 468 469 |
# File 'lib/squared/workspace/project/base.rb', line 467 def last(key, *args, **kwargs, &blk) event(:last, key, *args, **kwargs, &blk) end |
#localname ⇒ Object
603 604 605 |
# File 'lib/squared/workspace/project/base.rb', line 603 def localname workspace.task_localname(name) end |
#log ⇒ Object
581 582 583 584 585 |
# File 'lib/squared/workspace/project/base.rb', line 581 def log return @log unless @log.is_a?(Array) @log = Logger.new(enabled? ? @log[0] : nil, **@log[1]) end |
#populate(keys) ⇒ Object
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'lib/squared/workspace/project/base.rb', line 231 def populate(keys, **) task_build keys return unless ref?(Base.ref) namespace name do @@tasks[Base.ref].each do |action, flags| next if @pass.include?(action) namespace action do flags.each do |flag| case action when 'graph' next unless graph? check = lambda do |args| next args if (args = args.to_a).empty? param_guard(action, flag, args: args.reject { |val| name == val.to_s }) end format_desc action, flag, 'project*' if flag == :run task flag do |_, args| graph check.(args) end else task flag do |_, args| out, done = graph(check.(args), out: []) out.map! do |val| done.each_with_index do |proj, i| next unless Regexp.new(" #{Regexp.escape(proj.name)}(?:@\\d|\\z)") =~ val val += " (#{i.succ})" break end val end emphasize(out, title: path, right: true, border: borderstyle, sub: [ { pat: /\A(#{Regexp.escape(path.to_s)})(.*)\z/, styles: theme[:header] }, { pat: /\A(#{Regexp.escape(name)})(.*)\z/, styles: theme[:active] }, { pat: /\A(.+ )(\()(\d+)(\))(.*)\z/, styles: theme[:inline], index: 3 } ]) end end end end end end end end |
#prod? ⇒ Boolean
559 560 561 |
# File 'lib/squared/workspace/project/base.rb', line 559 def prod? @prod != false && workspace.prod?(pat: @prod, **scriptargs) end |
#ref ⇒ Object
227 228 229 |
# File 'lib/squared/workspace/project/base.rb', line 227 def ref Base.ref end |
#ref?(val) ⇒ Boolean
519 520 521 |
# File 'lib/squared/workspace/project/base.rb', line 519 def ref?(val) @ref.include?(val) end |
#script? ⇒ Boolean
527 528 529 |
# File 'lib/squared/workspace/project/base.rb', line 527 def script? @output[0].nil? && !!@output[1] && respond_to?(:compose) end |
#task_include?(key, ref = nil) ⇒ Boolean
569 570 571 |
# File 'lib/squared/workspace/project/base.rb', line 569 def task_include?(key, ref = nil) workspace.task_include?(self, key, ref) && !@pass.include?(key.to_s) end |
#test(sync: invoked_sync?('test')) ⇒ Object
396 397 398 399 400 |
# File 'lib/squared/workspace/project/base.rb', line 396 def test(*, sync: invoked_sync?('test'), **) return unless @test build(*as_a(@test), from: :test, sync: sync) end |
#test? ⇒ Boolean
547 548 549 |
# File 'lib/squared/workspace/project/base.rb', line 547 def test? !!@test end |
#to_s ⇒ Object
611 612 613 |
# File 'lib/squared/workspace/project/base.rb', line 611 def to_s path.to_s end |
#to_sym ⇒ Object
615 616 617 |
# File 'lib/squared/workspace/project/base.rb', line 615 def to_sym name.to_sym end |
#variable_set(key, *val, **kwargs) ⇒ Object
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 |
# File 'lib/squared/workspace/project/base.rb', line 479 def variable_set(key, *val, **kwargs) if variables.include?(key) case key when :build, :run run_set(*val, **kwargs) when :script script_set(*val, **kwargs) when :env run_set(output[0], *val, **kwargs) when :parent @parent = val if (val = val.first).is_a?(Project::Base) when :graph @graph = case val.first when nil, false nil else val.flatten.map!(&:to_s).freeze end when :dependfile @dependfile = basepath(*val) else instance_variable_set :"@#{key}", val.first end else log.warn "variable_set: @#{key} (private)" end end |
#version ⇒ Object
573 574 575 |
# File 'lib/squared/workspace/project/base.rb', line 573 def version(*) @version end |
#with(**kwargs, &blk) ⇒ Object
286 287 288 289 290 291 292 293 |
# File 'lib/squared/workspace/project/base.rb', line 286 def with(**kwargs, &blk) @withargs = kwargs.empty? ? nil : kwargs if block_given? instance_eval(&blk) @withargs = nil end self end |