Class: String
- Defined in:
- lib/mysh/pre_processor.rb,
lib/mysh/handlebars/string.rb,
lib/mysh/internal/to_file_spec.rb,
lib/mysh/shell_variables/evaluate.rb
Overview
Monkey patches for Mysh variables
Instance Method Summary collapse
-
#dress_up_quotes ⇒ Object
Dress up in quotes if needed.
-
#dress_up_slashes ⇒ Object
Dress up slashes and backslashes.
-
#eval_handlebars(evaluator = $mysh_exec_binding) ⇒ Object
Evaluate any variable substitutions in the input.
-
#eval_variables ⇒ Object
Evaluate any variable substitutions in the input.
-
#extract_boolean ⇒ Object
Extract common mysh data from this string.
-
#preprocess(evaluator = $mysh_exec_binding) ⇒ Object
The mysh string pre-processor stack.
-
#to_host_spec ⇒ Object
Make the file name fit the local system.
-
#to_std_spec ⇒ Object
Make the file name fit the standard notation.
Instance Method Details
#dress_up_quotes ⇒ Object
Dress up in quotes if needed.
18 19 20 |
# File 'lib/mysh/internal/to_file_spec.rb', line 18 def dress_up_quotes self[' '] ? "\"#{self}\"" : self end |
#dress_up_slashes ⇒ Object
Dress up slashes and backslashes.
13 14 15 |
# File 'lib/mysh/internal/to_file_spec.rb', line 13 def dress_up_slashes MiniTerm.windows? ? self.gsub("/", "\\") : self end |
#eval_handlebars(evaluator = $mysh_exec_binding) ⇒ Object
Evaluate any variable substitutions in the input.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/mysh/handlebars/string.rb', line 7 def (evaluator=$mysh_exec_binding) string, text, buffer = self, "", [] until string.empty? text, code, string = string.partition(/{{.*?}}/m) if not text.empty? text = text.gsub(/\\[{}]/) {|found| found[1]} buffer << "_m_<<#{text.inspect};" elsif buffer.empty? buffer << "" end unless code.empty? if code[-3] == "#" buffer << "#{code[2...-3]};" else buffer << "_m_<<(#{code[2...-2]}).to_s;" end end end if buffer.length > 1 evaluator.eval("_m_ = '';" + buffer.join + "_m_") else text end end |
#eval_variables ⇒ Object
Evaluate any variable substitutions in the input.
16 17 18 19 20 21 22 |
# File 'lib/mysh/shell_variables/evaluate.rb', line 16 def eval_variables self.gsub(/((?<!\\)\$\$)|((?<!\\)\$[a-z][a-z0-9_]*)/) do |str| sym = str[1..-1].to_sym MNV.key?(sym) ? MNV[sym].to_s : str end.gsub(/\\\$/, "$") end |
#extract_boolean ⇒ Object
Extract common mysh data from this string.
7 8 9 10 11 12 13 |
# File 'lib/mysh/shell_variables/evaluate.rb', line 7 def extract_boolean if self =~ /\A(false|no|off)\z/i false else self end end |
#preprocess(evaluator = $mysh_exec_binding) ⇒ Object
The mysh string pre-processor stack.
7 8 9 |
# File 'lib/mysh/pre_processor.rb', line 7 def preprocess(evaluator=$mysh_exec_binding) self.eval_variables.(evaluator) end |
#to_host_spec ⇒ Object
Make the file name fit the local system.
7 8 9 10 |
# File 'lib/mysh/internal/to_file_spec.rb', line 7 def to_host_spec self.dress_up_slashes .dress_up_quotes end |
#to_std_spec ⇒ Object
Make the file name fit the standard notation.
23 24 25 |
# File 'lib/mysh/internal/to_file_spec.rb', line 23 def to_std_spec self.gsub("\\", "/") end |