Class: DevSystem::UnitShell

Inherits:
Shell show all
Defined in:
lib/dev_system/shells/unit_shell.rb

Instance Attribute Summary

Attributes inherited from Liza::Controller

#menv

Class Method Summary collapse

Methods inherited from Shell

all, cruby?, engine, jruby?, linux?, mac?, os, ruby_version, unix?, windows?

Methods inherited from Liza::Controller

#`, `, attr_accessor, attr_reader, attr_writer, #attrs, box, #box, call, color, division, division!, division?, inherited, menv_accessor, menv_reader, menv_writer, on_connected, panel, #panel, plural, require, requirements, sh, #sh, singular, subsystem, subsystem!, subsystem?, subsystem_token, token

Methods inherited from Liza::Unit

_erbs_for, #add, add, cl, #cl, class_methods_defined, const_added, const_missing, constants_defined, define_error, descendants_select, division, erbs_available, erbs_defined, erbs_for, errors, #fetch, fetch, get, #get, instance_methods_defined, log, #log, log?, #log?, #log_array, log_array, log_hash, #log_hash, #log_level, log_level, #log_level?, log_level?, log_levels, #log_levels, #log_render_convert, #log_render_format, #log_render_in, #log_render_out, method_added, methods_defined, namespace, part, raise_error, #raise_error, reload!, #reload!, #render, #render!, #render_stack, renderable_formats_for, renderable_names, section, sections, #set, set, #settings, settings, singleton_method_added, sleep, #sleep, stick, #stick, sticks, #sticks, subclasses_select, subunits, system, #system, system?, test_class, time_diff, #time_diff

Class Method Details

.get_subunits_recursive(unit) ⇒ Array, Hash

Recursively retrieves subunits for a given unit and caches the result.

Parameters:

  • unit (Object)

    The unit to retrieve subunits for.

Returns:

  • (Array, Hash)

    An array or hash of subunits.



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/dev_system/shells/unit_shell.rb', line 26

def self.get_subunits_recursive(unit)
  subs = unit.subunits
  return [] if subs.empty?
  h = subs.map do |subunit|
    next_subs = get_subunits_recursive(subunit)
    [subunit, next_subs]
  end.to_h
  if h.values.all?(&:empty?)
    h.keys
  else
    h
  end
end

.subunits_flat(unit) ⇒ Array

Returns a flattened array of all subunits for a given unit.

Parameters:

  • unit (Object)

    The unit to retrieve subunits for.

Returns:

  • (Array)

    A flattened array of subunits.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/dev_system/shells/unit_shell.rb', line 7

def self.subunits_flat(unit)
  ret = []
  
  rec = get_subunits_recursive(unit)
  while rec.is_a? Hash
    rec.each do |subunit, next_subs|
      ret << subunit
      rec = next_subs
    end
  end
  ret += rec

  ret
end