Module: Cfruby::Cfp_ParserLogic
- Included in:
- Parser, CfrubyRuntime
- Defined in:
- lib/libcfenjin/cfp_parserlogic.rb
Instance Method Summary collapse
-
#conditional?(line) ⇒ Boolean
Returns whether a line is a Cfruby style conditional (double colon).
- #embed_exec_into_informer(s, msg) ⇒ Object
-
#form_conditional(line) ⇒ Object
Turns a double colon conditional into a Ruby conditional.
-
#form_control(line) ⇒ Object
Parse control lines for Cfruby assignments like ‘sshd = ( hostname1 hostname2 )’ Note that the notation is pretty strict.
-
#form_copy(line) ⇒ Object
Parse
line
and turn it into a valid Ruby call. - #form_directories(line) ⇒ Object
- #form_editfiles(line) ⇒ Object
- #form_files(line) ⇒ Object
-
#form_groups(line) ⇒ Object
Parse groups lines for Cfruby assignments like ‘sshd = ( hostname1 hostname2 )’.
-
#form_links(line) ⇒ Object
Parse
line
and turn it into a valid Ruby call. -
#form_shellcommands(line) ⇒ Object
In shellcommands lines starting with a (double) quote are executed by libcruby.
- #form_tidy(line) ⇒ Object
Instance Method Details
#conditional?(line) ⇒ Boolean
Returns whether a line is a Cfruby style conditional (double colon)
103 104 105 |
# File 'lib/libcfenjin/cfp_parserlogic.rb', line 103 def conditional? line line.strip =~ /[\w.|)(]+::$/ end |
#embed_exec_into_informer(s, msg) ⇒ Object
107 108 109 |
# File 'lib/libcfenjin/cfp_parserlogic.rb', line 107 def s,msg "Cfruby.controller.inform(\"verbose\", \""+msg+"\n\#{"+s+"}\")" end |
#form_conditional(line) ⇒ Object
Turns a double colon conditional into a Ruby conditional
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/libcfenjin/cfp_parserlogic.rb', line 82 def form_conditional line return line if !conditional? line # ---- Fetch statement line.strip =~ /(\S+)::/ s = $1 # ---- Split on separators toks = s.split(/[.|() !]+/) operators = s.split(/[^.| ()!]+/) r = 'if' idx = 0 # ---- Check for leading operators idx = -1 if toks[0] == '' toks.each do | tok | r += translate_operators(operators[idx]) + " isa?('#{tok}')" if tok != '' idx += 1 end r += translate_operators(operators[idx]) r end |
#form_control(line) ⇒ Object
Parse control lines for Cfruby assignments like ‘sshd = ( hostname1 hostname2 )’ Note that the notation is pretty strict. ‘sshd = (hostname1 hostname2)’, for example will not translate. This is to allow for standard Ruby assignments in a control block.
37 38 39 40 41 |
# File 'lib/libcfenjin/cfp_parserlogic.rb', line 37 def form_control line line = convert_class_assignments(line) line = convert_global_assignments(line) convert_global_variables(line) end |
#form_copy(line) ⇒ Object
Parse line
and turn it into a valid Ruby call
44 45 46 |
# File 'lib/libcfenjin/cfp_parserlogic.rb', line 44 def form_copy line cfline 'copy',line end |
#form_directories(line) ⇒ Object
52 53 54 |
# File 'lib/libcfenjin/cfp_parserlogic.rb', line 52 def form_directories line cfline 'directories',line end |
#form_editfiles(line) ⇒ Object
60 61 62 |
# File 'lib/libcfenjin/cfp_parserlogic.rb', line 60 def form_editfiles line convert_global_variables(line) end |
#form_files(line) ⇒ Object
56 57 58 |
# File 'lib/libcfenjin/cfp_parserlogic.rb', line 56 def form_files line cfline 'files',line end |
#form_groups(line) ⇒ Object
Parse groups lines for Cfruby assignments like ‘sshd = ( hostname1 hostname2 )’
23 24 25 26 27 28 29 30 31 |
# File 'lib/libcfenjin/cfp_parserlogic.rb', line 23 def form_groups line return line if remark? line # Test for assignment with spaces and braces if line.strip !~ /^\w+\s+\=\s+\(\s.*\s\)$/ raise 'Illegal groups command: "'+line+'"' if line.strip != '' end line = convert_class_assignments(line) convert_global_variables(line) end |
#form_links(line) ⇒ Object
Parse line
and turn it into a valid Ruby call
14 15 16 17 18 19 20 |
# File 'lib/libcfenjin/cfp_parserlogic.rb', line 14 def form_links line if line =~ /->/ from,to = line.split(/\s*->\s*/) line = 'link '+quotepath(to)+','+quotepath(from) end convert_global_variables(line) end |
#form_shellcommands(line) ⇒ Object
In shellcommands lines starting with a (double) quote are executed by libcruby. Backquotes are Ruby commands - and to see the return value we prepend an output statement.
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/libcfenjin/cfp_parserlogic.rb', line 67 def form_shellcommands line if line.strip =~ /^['"](.*)['"]$/ cmda = eval('%w{'+$1+'}') p cmda # TODO: fixme raise 'Cannot execute quoted shellcommand (yet)' # Exec::shellexec(line) elsif line.strip =~ /^[`]/ escline = line.strip.gsub(/"/,'\"') line = (line,'Shell: '+escline+"\n") end convert_global_variables(line) end |
#form_tidy(line) ⇒ Object
48 49 50 |
# File 'lib/libcfenjin/cfp_parserlogic.rb', line 48 def form_tidy line cfline 'tidy',line end |