Class: DevSystem::LineShell

Inherits:
Shell show all
Defined in:
lib/dev_system/subsystems/shell/shells/line_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

.extract_between(lines, range) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/dev_system/subsystems/shell/shells/line_shell.rb', line 58

def self.extract_between(lines, range)
  ret = []

  state = nil
  lines.each do |line|
    if state == :entered_region
      if line.start_with? range.max
        break
      else
        ret << line
      end
    else
      if line.start_with? range.min
        state = :entered_region
      end
    end
  end

  ret
end

.extract_wall_of(lines, string) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/dev_system/subsystems/shell/shells/line_shell.rb', line 5

def self.extract_wall_of(lines, string)
  ret = []

  state = nil
  lines.each do |line|
    if state == :entered_region
      if line.start_with? string
        ret << line
      else
        break
      end
    else
      if line.start_with? string
        state = :entered_region
        ret << line
      end
    end
  end

  ret
end

.replace_between(lines, range, with, stop_at = "__END__") ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/dev_system/subsystems/shell/shells/line_shell.rb', line 79

def self.replace_between(lines, range, with, stop_at="__END__")
  ret = []

  state = nil
  ignoring = false
  lines.each do |line|
    if state == :entered_region
      if line.start_with? range.max
        ret += with
        state = nil
      end
    else
      if line.start_with? range.min
        state = :entered_region
        ret << line
      end
    end unless ignoring

    ret << line unless state == :entered_region
    ignoring = true if line.start_with? stop_at
  end

  ret
end

.replace_wall_of(lines, string, with) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/dev_system/subsystems/shell/shells/line_shell.rb', line 29

def self.replace_wall_of(lines, string, with)
  ret = []
  
  state = nil
  lines.each do |line|

    if state == :entered_region
      if line.start_with? string
        #
      else
        ret << line
        state = nil
      end
    else
      if line.start_with? string
        ret += with
        state = :entered_region
      else
        ret << line
      end
    end

  end

  ret
end