Class: DevSystem::TextShell
- Inherits:
-
FileShell
show all
- Defined in:
- lib/dev_system/subsystems/shell/shells/text_shell.rb
Instance Attribute Summary
#menv
Class Method Summary
collapse
Methods inherited from FileShell
_raise_if_blank, _raise_if_not_exists, category_for, copy, directory?, exist?, file?, gitkeep, read_binary, read_text, remove, size, symbolic_link?, touch, write_binary, write_text
Methods inherited from Shell
all, cruby?, engine, jruby?, linux?, mac?, os, ruby_version, unix?, windows?
#`, `, 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
.append_line_after_last_including(path:, newline:, after:) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/dev_system/subsystems/shell/shells/text_shell.rb', line 44
def self.append_line_after_last_including(path:, newline:, after:)
log "Appending to #{path}"
state = nil
lines = File.readlines(path)
File.open(path, "w") do |out|
lines.each do |line|
state = :entered_systems_region if state == nil && line =~ after
state = :left_systems_region if state == :entered_systems_region && line !~ after
if state == :left_systems_region
out.write("#{newline}\n")
log :high, (stick :light_green, newline.strip)
state = :done
end
out.write(line)
log :high, (stick :onyx, line.strip)
end
end
end
|
.read(path, log_level: self.log_level) ⇒ Object
19
20
21
22
23
24
25
|
# File 'lib/dev_system/subsystems/shell/shells/text_shell.rb', line 19
def self.read path, log_level: self.log_level
log log_level, "Reading #{path}"
_raise_if_blank path
_raise_if_not_exists path, log_level: log_level
File.read path
end
|
.read_lines(path, log_level: self.log_level) ⇒ Object
27
28
29
30
31
32
|
# File 'lib/dev_system/subsystems/shell/shells/text_shell.rb', line 27
def self.read_lines path, log_level: self.log_level
log log_level, "Reading lines from #{path}"
return [] unless exist? path
File.readlines path
end
|
.read_lines!(path, log_level: self.log_level) ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/dev_system/subsystems/shell/shells/text_shell.rb', line 34
def self.read_lines! path, log_level: self.log_level
log log_level, "Reading lines from #{path}"
_raise_if_blank path
_raise_if_not_exists path
File.readlines path
end
|
.write(path, content, create_dir: nil, log_level: self.log_level) ⇒ Object
7
8
9
10
11
12
13
14
15
|
# File 'lib/dev_system/subsystems/shell/shells/text_shell.rb', line 7
def self.write path, content, create_dir: nil, log_level: self.log_level
log log_level, "Writing #{content.to_s.size} characters (#{content.encoding}) to #{path}"
_raise_if_blank path
create_dir = get :create_dir if create_dir.nil?
DevSystem::DirShell.create File.dirname(path), log_level: log_level if create_dir
File.write path, content
end
|