Class: Squared::Workspace::Application
- Inherits:
-
Object
- Object
- Squared::Workspace::Application
- Includes:
- Rake::DSL, Common::Format, Git, Repo, Utils
- Defined in:
- lib/squared/workspace/application.rb
Constant Summary
Constants included from Common
Class Attribute Summary collapse
-
.attr_banner ⇒ Object
Returns the value of attribute attr_banner.
-
.impl_project ⇒ Object
Returns the value of attribute impl_project.
-
.impl_series ⇒ Object
Returns the value of attribute impl_series.
-
.kind_project ⇒ Object
readonly
Returns the value of attribute kind_project.
Instance Attribute Summary collapse
-
#closed ⇒ Object
readonly
Returns the value of attribute closed.
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
-
#home ⇒ Object
readonly
Returns the value of attribute home.
-
#main ⇒ Object
readonly
Returns the value of attribute main.
-
#pipe ⇒ Object
readonly
Returns the value of attribute pipe.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#series ⇒ Object
readonly
Returns the value of attribute series.
-
#theme ⇒ Object
readonly
Returns the value of attribute theme.
-
#verbose ⇒ Object
readonly
Returns the value of attribute verbose.
-
#warning ⇒ Object
readonly
Returns the value of attribute warning.
Attributes included from Repo
Attributes included from Git
Class Method Summary collapse
- .baseref ⇒ Object
- .exclude(*args) ⇒ Object
- .find(ref = nil, path: nil) ⇒ Object
- .implement(*objs, base: false) ⇒ Object
- .series_wrap(app) ⇒ Object
- .to_s ⇒ Object
Instance Method Summary collapse
- #add(path, project = nil, **kwargs, &blk) ⇒ Object
- #apply(&blk) ⇒ Object
- #banner(*args, command: true, styles: nil, border: nil, group: @group, ref: @ref) ⇒ Object
- #banner_get(*ref, group: nil) ⇒ Object
- #baseref ⇒ Object
- #build(parallel: [], pass: nil, **kwargs) {|_self| ... } ⇒ Object
- #chain(task, *action, project: nil, step: 0, with: nil, before: nil, after: nil, sync: false, group: @group, ref: @ref) ⇒ Object
- #clean(script = nil, group: @group, ref: @ref, on: nil, &blk) ⇒ Object
- #compose(name, &blk) ⇒ Object
- #depend(script = nil, group: @group, ref: @ref, on: nil, &blk) ⇒ Object
- #describe(data) ⇒ Object
- #dev?(**kwargs) ⇒ Boolean
- #doc(script = nil, group: @group, ref: @ref, on: nil, &blk) ⇒ Object
- #docker? ⇒ Boolean
- #enabled? ⇒ Boolean
- #events_get(*args, group: nil, ref: nil) ⇒ Object
- #exclude(base, group: @group, ref: @ref) ⇒ Object
- #find(path = nil, name: nil, group: nil, ref: nil, &blk) ⇒ Object
- #find_base(obj) ⇒ Object
- #format_desc(val, opts = nil, arg: 'opts*', before: nil, after: nil, out: false) ⇒ Object
- #get(name, &blk) ⇒ Object
- #graph(script, group: @group, ref: @ref, on: nil) ⇒ Object
- #group(path, val, override: {}, **kwargs, &blk) ⇒ Object
- #home? ⇒ Boolean
- #homepath(*args) ⇒ Object
-
#initialize(home = (ARG[:HOME] && ENV[ARG[:HOME]]) || Dir.pwd, main: nil, prefix: nil, verbose: , common: , pipe: , exception: ) ⇒ Application
constructor
A new instance of Application.
- #initialize_session ⇒ Object
- #inspect ⇒ Object
- #invokeargs ⇒ Object
- #lint(script = nil, group: @group, ref: @ref, on: nil, &blk) ⇒ Object
- #log(script, group: @group, ref: @ref) ⇒ Object
- #pass(name, group: @group, ref: @ref, &blk) ⇒ Object
- #powershell? ⇒ Boolean
- #prod?(**kwargs) ⇒ Boolean
- #pwd ⇒ Object
- #rootpath(*args) ⇒ Object
- #run(script = nil, group: @group, ref: @ref, on: nil, &blk) ⇒ Object
- #script(script, group: @group, ref: @ref, on: nil) ⇒ Object
- #script_find(*args) ⇒ Object
- #script_get(*args, group: nil, ref: nil) ⇒ Object
- #style(obj, *args, target: nil, empty: false) ⇒ Object
- #task_base?(key) ⇒ Boolean
- #task_defined?(*key) ⇒ Boolean
- #task_desc(*args, **kwargs) ⇒ Object
- #task_exclude?(key, obj = nil) ⇒ Boolean
- #task_extend?(obj, key) ⇒ Boolean
- #task_include?(obj, key, ref = nil) ⇒ Boolean
- #task_localname(val) ⇒ Object
- #task_name(val) ⇒ Object
- #task_namespace(val, first: false) ⇒ Object
- #task_resolve(obj, key) ⇒ Object
- #task_sync(key) ⇒ Object
- #test(script = nil, group: @group, ref: @ref, on: nil, &blk) ⇒ Object
- #to_s ⇒ Object
- #windows? ⇒ Boolean
- #with(*val, group: nil, **kwargs, &blk) ⇒ Object
Methods included from Repo
Methods included from Git
#git, #git_clone?, #git_repo, #rev_clear, #rev_entry, #rev_timesince, #rev_timeutc, #rev_write, #revbuild
Methods included from Common::Format
#enable_aixterm, #enable_drawing
Constructor Details
#initialize(home = (ARG[:HOME] && ENV[ARG[:HOME]]) || Dir.pwd, main: nil, prefix: nil, verbose: , common: , pipe: , exception: ) ⇒ Application
Returns a new instance of Application.
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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/squared/workspace/application.rb', line 80 def initialize(home = (ARG[:HOME] && ENV[ARG[:HOME]]) || Dir.pwd, *, main: nil, prefix: nil, verbose: ARG[:VERBOSE], common: ARG[:COMMON], pipe: ARG[:PIPE], exception: ARG[:FAIL], **) @home = Pathname.new(home).realdirpath basename = @home.basename.to_s if main @main = main.to_s.freeze @home += @main unless @main == basename || (windows? && @main.downcase == basename.downcase) else @main = basename.freeze end @home.mkpath rescue nil @root = @home.parent @prefix = prefix @series = Application.series_wrap(self) @project = {} @kind = {} @extensions = [] @envname = @main.gsub(/[^\w]+/, '_').upcase.freeze @pipe = env_pipe(pipe, (ARG[:OUT] && env(ARG[:OUT])) || 1, root: @home) @exception = env_bool exception @verbose = env_bool(verbose, verbose.nil? || verbose.is_a?(String) ? @pipe != 0 : verbose, index: true) @warning = @verbose != false @closed = false if common @theme = __get__(:theme)[:workspace] ARG[:COLOR] = false if @pipe == 0 || @pipe.is_a?(Pathname) else @theme = {} end @chain = {} @script = { group: {}, ref: {}, group!: {}, ref!: {} }.freeze @events = { group: {}, ref: {} }.freeze @pass = { group: {}, ref: {}, global: {}, pattern: [] }.freeze @banner = { group: {}, ref: {} }.freeze initialize_session end |
Class Attribute Details
.attr_banner ⇒ Object
Returns the value of attribute attr_banner.
72 73 74 |
# File 'lib/squared/workspace/application.rb', line 72 def @attr_banner end |
.impl_project ⇒ Object
Returns the value of attribute impl_project.
72 73 74 |
# File 'lib/squared/workspace/application.rb', line 72 def impl_project @impl_project end |
.impl_series ⇒ Object
Returns the value of attribute impl_series.
72 73 74 |
# File 'lib/squared/workspace/application.rb', line 72 def impl_series @impl_series end |
.kind_project ⇒ Object (readonly)
Returns the value of attribute kind_project.
71 72 73 |
# File 'lib/squared/workspace/application.rb', line 71 def kind_project @kind_project end |
Instance Attribute Details
#closed ⇒ Object (readonly)
Returns the value of attribute closed.
78 79 80 |
# File 'lib/squared/workspace/application.rb', line 78 def closed @closed end |
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
78 79 80 |
# File 'lib/squared/workspace/application.rb', line 78 def exception @exception end |
#home ⇒ Object (readonly)
Returns the value of attribute home.
78 79 80 |
# File 'lib/squared/workspace/application.rb', line 78 def home @home end |
#main ⇒ Object (readonly)
Returns the value of attribute main.
78 79 80 |
# File 'lib/squared/workspace/application.rb', line 78 def main @main end |
#pipe ⇒ Object (readonly)
Returns the value of attribute pipe.
78 79 80 |
# File 'lib/squared/workspace/application.rb', line 78 def pipe @pipe end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
78 79 80 |
# File 'lib/squared/workspace/application.rb', line 78 def prefix @prefix end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
78 79 80 |
# File 'lib/squared/workspace/application.rb', line 78 def root @root end |
#series ⇒ Object (readonly)
Returns the value of attribute series.
78 79 80 |
# File 'lib/squared/workspace/application.rb', line 78 def series @series end |
#theme ⇒ Object (readonly)
Returns the value of attribute theme.
78 79 80 |
# File 'lib/squared/workspace/application.rb', line 78 def theme @theme end |
#verbose ⇒ Object (readonly)
Returns the value of attribute verbose.
78 79 80 |
# File 'lib/squared/workspace/application.rb', line 78 def verbose @verbose end |
#warning ⇒ Object (readonly)
Returns the value of attribute warning.
78 79 80 |
# File 'lib/squared/workspace/application.rb', line 78 def warning @warning end |
Class Method Details
.baseref ⇒ Object
63 64 65 |
# File 'lib/squared/workspace/application.rb', line 63 def baseref impl_project.ref end |
.exclude(*args) ⇒ Object
55 56 57 |
# File 'lib/squared/workspace/application.rb', line 55 def exclude(*args) @task_exclude.merge(args.map!(&:to_sym)) end |
.find(ref = nil, path: nil) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/squared/workspace/application.rb', line 47 def find(ref = nil, path: nil) if ref && (ret = kind_project.find { |proj| proj.ref == ref }) ret elsif path kind_project.find { |proj| proj.config?(path) } end end |
.implement(*objs, base: false) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/squared/workspace/application.rb', line 22 def implement(*objs, base: false) return if base && objs.size > 1 objs.each do |obj| next unless base || obj < impl_project if base @impl_project = obj impl_series.base_set(obj) else kind_project.unshift(obj) obj.tasks&.each { |task| impl_series.add(task, obj) } end if (args = obj.batchargs) impl_series.batch(*args) end if (args = obj.aliasargs) impl_series.alias(*args) end if (args = obj.) @attr_banner.merge(args) end end end |
.series_wrap(app) ⇒ Object
59 60 61 |
# File 'lib/squared/workspace/application.rb', line 59 def series_wrap(app) impl_series.new(app, exclude: @task_exclude.to_a) end |
.to_s ⇒ Object
67 68 69 |
# File 'lib/squared/workspace/application.rb', line 67 def to_s super[/[^:]+\z/, 0] end |
Instance Method Details
#add(path, project = nil, **kwargs, &blk) ⇒ Object
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
# File 'lib/squared/workspace/application.rb', line 318 def add(path, project = nil, **kwargs, &blk) if @withargs data = @withargs.dup data.merge!(kwargs) kwargs = data end ref = if kwargs.key?(:ref) kwargs = kwargs.dup unless @withargs kwargs.delete(:ref) elsif @ref.is_a?(Symbol) @ref end if @group.is_a?(String) && !kwargs.key?(:group) kwargs = kwargs.dup unless @withargs kwargs[:group] = @group end path = root + path project = (project || path.basename).to_s name = task_name project index = 0 while @project[name] index += 1 name = task_name "#{project}-#{index}" end proj = ((if !ref.is_a?(Class) Application.find(ref, path: path) elsif ref < Project::Base ref end) || @kind[name]&.last || Project::Base).new(self, path, name, **kwargs) @project[name] = proj __get__(:project)[name] = proj unless kwargs[:private] proj.instance_eval(&blk) if block_given? self end |
#apply(&blk) ⇒ Object
373 374 375 376 |
# File 'lib/squared/workspace/application.rb', line 373 def apply(&blk) instance_eval(&blk) self end |
#banner(*args, command: true, styles: nil, border: nil, group: @group, ref: @ref) ⇒ Object
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
# File 'lib/squared/workspace/application.rb', line 280 def (*args, command: true, styles: nil, border: nil, group: @group, ref: @ref) data = { command: command, order: [], styles: check_style(styles, empty: false), border: check_style(border) } args.each do |meth| if meth.is_a?(Array) found = false meth = meth.select do |val| case val when Symbol found = true Application..include?(val) when String true else false end end if !found next elsif meth.size == 1 meth = meth.first end elsif !Application..include?(meth = meth.to_sym) next end data[:order] << meth end data = {} if !command && data[:order].empty? if group label = :group items = as_a group else label = :ref items = ref ? as_a(ref) : [:_] end items.each { |val| @banner[label][val.to_sym] = data } self end |
#banner_get(*ref, group: nil) ⇒ Object
575 576 577 578 579 580 581 |
# File 'lib/squared/workspace/application.rb', line 575 def (*ref, group: nil) ret = nil return ret if group && (ret = @banner[:group][group.to_sym]) ref.reverse_each { |val| return ret if (ret = @banner[:ref][val]) } @banner[:ref][:''] end |
#baseref ⇒ Object
660 661 662 |
# File 'lib/squared/workspace/application.rb', line 660 def baseref Application.baseref end |
#build(parallel: [], pass: nil, **kwargs) {|_self| ... } ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/squared/workspace/application.rb', line 141 def build(parallel: [], pass: nil, **kwargs) return self unless enabled? && !@closed if kwargs[:pattern].is_a?(Array) kwargs[:parallel] = parallel.map(&:to_s) else kwargs[:pattern] = [] kwargs[:parallel] = parallel.reject { |val| val.is_a?(Regexp) && (kwargs[:pattern] << val) } .map(&:to_s) end @pass[:pattern].concat(pass.map { |val| val.is_a?(Regexp) ? val : val.to_s }) if pass @project.each_value do |proj| if proj.enabled? proj.populate(series.keys.dup, **kwargs) elsif proj.enabled?(base: false) proj.generate([], **kwargs) else next end series.populate(proj, **kwargs) end Application.kind_project.each { |obj| obj.populate(self, **kwargs) } @extensions.uniq.each { |ext| __send__(ext, **kwargs) } series.build(**kwargs) __build__(**kwargs) yield self if block_given? __chain__(**kwargs) @closed = true self end |
#chain(task, *action, project: nil, step: 0, with: nil, before: nil, after: nil, sync: false, group: @group, ref: @ref) ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/squared/workspace/application.rb', line 204 def chain(task, *action, project: nil, step: 0, with: nil, before: nil, after: nil, sync: false, group: @group, ref: @ref) keys = if project action.map! { |val| task_join(project.name, val) } nil elsif (target = group || ref) action.map! { |val| task_name(task_join(val, target)) } nil else action.map! { |val| task_name(val) } prefix ? nil : @project.keys end ns = lambda do |val| next if (ret = as_a(val, :to_s, flat: true)).empty? ret.map! do |arg| if arg.include?(':') || (keys && !keys.include?(arg)) task_name(arg) else /\A#{Regexp.escape(task_name(arg))}:/ end end end data = Support::ChainData.new(action, step, ns.call(with), ns.call(before), ns.call(after), sync) (@chain[task_name(task.to_s)] ||= []) << data self end |
#clean(script = nil, group: @group, ref: @ref, on: nil, &blk) ⇒ Object
244 245 246 |
# File 'lib/squared/workspace/application.rb', line 244 def clean(script = nil, group: @group, ref: @ref, on: nil, &blk) script_command :clean, script, group, ref, on, &blk end |
#compose(name, &blk) ⇒ Object
368 369 370 371 |
# File 'lib/squared/workspace/application.rb', line 368 def compose(name, &blk) namespace(task_name(name), &blk) if block_given? self end |
#depend(script = nil, group: @group, ref: @ref, on: nil, &blk) ⇒ Object
236 237 238 |
# File 'lib/squared/workspace/application.rb', line 236 def depend(script = nil, group: @group, ref: @ref, on: nil, &blk) script_command :depend, script, group, ref, on, &blk end |
#describe(data) ⇒ Object
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 |
# File 'lib/squared/workspace/application.rb', line 393 def describe(data) @describe ||= { alias: {}, replace: [], pattern: {} } data.each do |key, val| key = key.to_s if key.match?(/\A(\\A|\^)/) || key.match?(/(\\z|\$)\z/) @describe[:replace] << [Regexp.new(key), val] else @describe[val.is_a?(Regexp) ? :pattern : :alias][key.to_s] = val end end self end |
#dev?(**kwargs) ⇒ Boolean
616 617 618 |
# File 'lib/squared/workspace/application.rb', line 616 def dev?(**kwargs) script?(:dev, **kwargs) end |
#doc(script = nil, group: @group, ref: @ref, on: nil, &blk) ⇒ Object
248 249 250 |
# File 'lib/squared/workspace/application.rb', line 248 def doc(script = nil, group: @group, ref: @ref, on: nil, &blk) script_command :doc, script, group, ref, on, &blk end |
#docker? ⇒ Boolean
632 633 634 |
# File 'lib/squared/workspace/application.rb', line 632 def docker? !Dir['/.dockerenv', '/docker-*.{sh,d}'].empty? end |
#enabled? ⇒ Boolean
583 584 585 |
# File 'lib/squared/workspace/application.rb', line 583 def enabled? !@extensions.empty? || @project.values.any? { |proj| proj.enabled?(base: false) } end |
#events_get(*args, group: nil, ref: nil) ⇒ Object
571 572 573 |
# File 'lib/squared/workspace/application.rb', line 571 def events_get(*args, group: nil, ref: nil) data_get(*args, group: group, ref: ref, target: @events) end |
#exclude(base, group: @group, ref: @ref) ⇒ Object
264 265 266 |
# File 'lib/squared/workspace/application.rb', line 264 def exclude(base, group: @group, ref: @ref) script_command :exclude, as_a(base, :to_sym).freeze, group, ref end |
#find(path = nil, name: nil, group: nil, ref: nil, &blk) ⇒ Object
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
# File 'lib/squared/workspace/application.rb', line 410 def find(path = nil, name: nil, group: nil, ref: nil, &blk) ret = group ? @project.select { |_, item| item.group == group }.map(&:last) : [] if path.is_a?(Symbol) ref ||= path path = nil end if ret.empty? ret = @project.select { |_, item| item.ref?(ref) }.map(&:last) if ref if ret.empty? && (path || name) path &&= rootpath(path) name &&= name.to_s proj = @project.find { |_, item| (path && item.path == path) || (name && item.name == name) }&.last ret << proj if proj end end return (group || ref ? ret : ret[0]) unless block_given? ret.each(&blk) self end |
#find_base(obj) ⇒ Object
439 440 441 |
# File 'lib/squared/workspace/application.rb', line 439 def find_base(obj) Application.kind_project.find { |proj| obj.instance_of?(proj) } end |
#format_desc(val, opts = nil, arg: 'opts*', before: nil, after: nil, out: false) ⇒ Object
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 |
# File 'lib/squared/workspace/application.rb', line 538 def format_desc(val, opts = nil, arg: 'opts*', before: nil, after: nil, out: false) return unless TASK_METADATA || out val = val.split(':') if val.is_a?(String) if before || after || opts pos = [] pos << (before.is_a?(Array) ? before.join(',') : before) if before if opts pos << if opts.is_a?(Array) arg ? "#{arg}=#{opts.join(',')}" : opts.join('|') else opts end end pos << (after.is_a?(Array) ? after.join(',') : after) if after val << "#{val.pop}[#{pos.join(',')}]" end out ? (*val) : task_desc(*val) end |
#get(name, &blk) ⇒ Object
431 432 433 434 435 436 437 |
# File 'lib/squared/workspace/application.rb', line 431 def get(name, &blk) ret = @project[name.to_s] return ret unless block_given? ret&.instance_eval(&blk) self end |
#graph(script, group: @group, ref: @ref, on: nil) ⇒ Object
240 241 242 |
# File 'lib/squared/workspace/application.rb', line 240 def graph(script, group: @group, ref: @ref, on: nil) script_command :graph, as_a(script, :to_s).freeze, group, ref, on end |
#group(path, val, override: {}, **kwargs, &blk) ⇒ Object
353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
# File 'lib/squared/workspace/application.rb', line 353 def group(path, val, override: {}, **kwargs, &blk) rootpath(path).children.map! do |dir| next unless dir.directory? basename = dir.basename.to_s [dir, basename, override[basename.to_sym]] end .each do |dir, basename, opts| args = kwargs.dup args.merge!(opts) if opts add(dir, basename, group: val, **args, &blk) end self end |
#home? ⇒ Boolean
624 625 626 |
# File 'lib/squared/workspace/application.rb', line 624 def home? !(proj = find(home)).nil? && proj.enabled? end |
#homepath(*args) ⇒ Object
652 653 654 |
# File 'lib/squared/workspace/application.rb', line 652 def homepath(*args) home.join(*args) end |
#initialize_session ⇒ Object
133 134 135 136 137 138 139 |
# File 'lib/squared/workspace/application.rb', line 133 def initialize_session return unless @pipe.is_a?(Pathname) msg = "Session started on #{Time.now} by #{@main}" bord = '#' * s.size puts bord, msg, bord end |
#inspect ⇒ Object
672 673 674 |
# File 'lib/squared/workspace/application.rb', line 672 def inspect "#<#{self.class}: #{main} => #{self}>" end |
#invokeargs ⇒ Object
664 665 666 |
# File 'lib/squared/workspace/application.rb', line 664 def invokeargs { exception: exception, warning: warning } end |
#lint(script = nil, group: @group, ref: @ref, on: nil, &blk) ⇒ Object
252 253 254 |
# File 'lib/squared/workspace/application.rb', line 252 def lint(script = nil, group: @group, ref: @ref, on: nil, &blk) script_command :lint, script, group, ref, on, &blk end |
#log(script, group: @group, ref: @ref) ⇒ Object
260 261 262 |
# File 'lib/squared/workspace/application.rb', line 260 def log(script, group: @group, ref: @ref) script_command :log, script, group, ref end |
#pass(name, group: @group, ref: @ref, &blk) ⇒ Object
268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/squared/workspace/application.rb', line 268 def pass(name, group: @group, ref: @ref, &blk) data = if group @pass[:group][group] ||= {} elsif ref @pass[:ref][ref] ||= {} else @pass[:global] end data[name.to_sym] = blk self end |
#powershell? ⇒ Boolean
636 637 638 639 640 641 642 643 644 645 646 |
# File 'lib/squared/workspace/application.rb', line 636 def powershell? return true if ENV['SHELL']&.end_with?(File.join('', 'pwsh')) return false unless windows? case ENV['TERM_PROGRAM'] when 'powershell.exe', 'vscode' true else ENV.fetch('PSModulePath', '').split(';', 2).size > 1 end end |
#prod?(**kwargs) ⇒ Boolean
620 621 622 |
# File 'lib/squared/workspace/application.rb', line 620 def prod?(**kwargs) script?(:prod, **kwargs) end |
#pwd ⇒ Object
656 657 658 |
# File 'lib/squared/workspace/application.rb', line 656 def pwd Pathname.new(Rake.application.original_dir) end |
#rootpath(*args) ⇒ Object
648 649 650 |
# File 'lib/squared/workspace/application.rb', line 648 def rootpath(*args) root.join(*args) end |
#run(script = nil, group: @group, ref: @ref, on: nil, &blk) ⇒ Object
200 201 202 |
# File 'lib/squared/workspace/application.rb', line 200 def run(script = nil, group: @group, ref: @ref, on: nil, &blk) script_command :run, script, group, ref, on, &blk end |
#script(script, group: @group, ref: @ref, on: nil) ⇒ Object
232 233 234 |
# File 'lib/squared/workspace/application.rb', line 232 def script(script, group: @group, ref: @ref, on: nil) script_command :script, script, group, ref, on end |
#script_find(*args) ⇒ Object
558 559 560 561 562 563 564 565 |
# File 'lib/squared/workspace/application.rb', line 558 def script_find(*args) args.reverse_each do |val| next unless val && (ret = val.is_a?(Symbol) ? @script[:ref!][val] : @script[:group!][val.to_sym]) return ret end @script[:ref!][:''] || SCRIPT_OBJ end |
#script_get(*args, group: nil, ref: nil) ⇒ Object
567 568 569 |
# File 'lib/squared/workspace/application.rb', line 567 def script_get(*args, group: nil, ref: nil) data_get(*args, group: group, ref: ref, target: @script) end |
#style(obj, *args, target: nil, empty: false) ⇒ Object
378 379 380 381 382 383 384 385 386 387 388 389 390 391 |
# File 'lib/squared/workspace/application.rb', line 378 def style(obj, *args, target: nil, empty: false) data = nil if target as_a(target).each_with_index do |key, i| if i == 0 break unless (data = __get__(:theme)[key.to_sym]) else data = data[key.to_sym] ||= {} end end end apply_style(data || theme, obj, args, empty: empty) unless target && !data self end |
#task_base?(key) ⇒ Boolean
587 588 589 |
# File 'lib/squared/workspace/application.rb', line 587 def task_base?(key) series.base?(key) end |
#task_defined?(*key) ⇒ Boolean
612 613 614 |
# File 'lib/squared/workspace/application.rb', line 612 def task_defined?(*key) Rake::Task.task_defined?(key.size == 1 ? key.first : task_join(*key)) end |
#task_desc(*args, **kwargs) ⇒ Object
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 |
# File 'lib/squared/workspace/application.rb', line 451 def task_desc(*args, **kwargs) return unless TASK_METADATA name = kwargs.delete(:name) if @describe val = name || task_join(*args) found = false replace = lambda do |data, out| index = data.size data.to_a.reverse_each { |group| out.sub!("%#{index -= 1}", group) } out end @describe[:replace].each do |pat, tmpl| next unless val =~ pat val = replace.call($~, tmpl.dup) found = true end if (out = @describe[:alias][val]) val = out found = true else @describe[:pattern].each do |key, pat| next unless val =~ pat val = replace.call($~, key.dup) found = true break end end args = split_escape(val, char: ':').map! { |s| s.gsub('\\:', ':') } if found end desc (*args, **kwargs) end |
#task_exclude?(key, obj = nil) ⇒ Boolean
601 602 603 604 605 606 607 608 609 610 |
# File 'lib/squared/workspace/application.rb', line 601 def task_exclude?(key, obj = nil) if obj data = obj.group ? @pass[:group][obj.group] : @pass[:ref][obj.ref] blk = (data && data[key.to_sym]) || @pass[:global][key.to_sym] return true if blk && obj.instance_eval(&blk) key = task_join(task_localname(obj.name), key) end @pass[:pattern].any? { |item| item.is_a?(Regexp) ? key.to_s.match?(item) : key == item } end |
#task_extend?(obj, key) ⇒ Boolean
591 592 593 |
# File 'lib/squared/workspace/application.rb', line 591 def task_extend?(obj, key) series.extend?(obj, key) end |
#task_include?(obj, key, ref = nil) ⇒ Boolean
595 596 597 598 599 |
# File 'lib/squared/workspace/application.rb', line 595 def task_include?(obj, key, ref = nil) return false if @series.exclude?(key) task_base?(key) ? obj.has?(key, ref || baseref) : task_extend?(obj, key) end |
#task_localname(val) ⇒ Object
447 448 449 |
# File 'lib/squared/workspace/application.rb', line 447 def task_localname(val) prefix && val.is_a?(String) ? val.sub(/\A#{Regexp.escape(prefix)}:/, '') : val.to_s end |
#task_name(val) ⇒ Object
443 444 445 |
# File 'lib/squared/workspace/application.rb', line 443 def task_name(val) prefix ? task_join(prefix, val) : val.to_s end |
#task_namespace(val, first: false) ⇒ Object
486 487 488 489 490 |
# File 'lib/squared/workspace/application.rb', line 486 def task_namespace(val, first: false) return nil unless (ret = val.to_s.split(':')).size > 1 first ? ret.first : task_join(*ret[0..-2]) end |
#task_resolve(obj, key) ⇒ Object
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 |
# File 'lib/squared/workspace/application.rb', line 492 def task_resolve(obj, key) tasks = [] if (base = task_base?(key)) tasks << key if obj.has?(key, baseref) elsif (batch = series.batch_get(key)) obj.allref.each do |ref| next unless obj.has?(key, ref) && (data = batch[ref]) data.each do |val| if (items = task_resolve(obj, val)).empty? tasks.clear break end tasks.concat(items) end return tasks unless tasks.empty? end elsif task_extend?(obj, key) tasks << key end ret = [] if tasks.empty? return [] if (base && !obj.ref?(baseref)) || !(data = series.alias_get(key)) obj.allref.each do |ref| next unless obj.has?(key, ref) && (alt = data[ref]) ret = task_resolve(obj, alt) break unless ret.empty? end else tasks.each do |val| target = task_join(obj.name, series.name_get(val)) return [] unless task_defined?(target) ret << target end end ret end |
#task_sync(key) ⇒ Object
533 534 535 536 |
# File 'lib/squared/workspace/application.rb', line 533 def task_sync(key) key = task_name key task_defined?(ret = task_join(key, 'sync')) ? ret : key end |
#test(script = nil, group: @group, ref: @ref, on: nil, &blk) ⇒ Object
256 257 258 |
# File 'lib/squared/workspace/application.rb', line 256 def test(script = nil, group: @group, ref: @ref, on: nil, &blk) script_command :test, script, group, ref, on, &blk end |
#to_s ⇒ Object
668 669 670 |
# File 'lib/squared/workspace/application.rb', line 668 def to_s (home? ? home : root).to_s end |
#windows? ⇒ Boolean
628 629 630 |
# File 'lib/squared/workspace/application.rb', line 628 def windows? Rake::Win32.windows? end |
#with(*val, group: nil, **kwargs, &blk) ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/squared/workspace/application.rb', line 176 def with(*val, group: nil, **kwargs, &blk) @group = nil @ref = nil @withargs = kwargs.empty? ? nil : kwargs val = as_a(group || kwargs[:ref], flat: true, compact: true) if val.empty? kind = val.first val = kind if val.size == 1 case kind when String @group = val when Symbol @ref = val else raise_error 'missing group or ref' if block_given? end if block_given? instance_eval(&blk) @group = nil @ref = nil @withargs = nil end self end |