Module: Inspec::Utils::CommentParser
- Included in:
- Resources::AideConf, Resources::Crontab, Resources::EtcFstab, Resources::EtcGroup, Resources::EtcHosts, Resources::EtcHostsAllow, Resources::LinuxUser, SimpleConfig
- Defined in:
- lib/inspec/utils/parser.rb
Instance Method Summary collapse
-
#parse_comment_line(raw, opts) ⇒ Array
Parse a line with a command.
Instance Method Details
#parse_comment_line(raw, opts) ⇒ Array
Parse a line with a command. For example: ‘a = b # comment`. Retrieves the actual content.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/inspec/utils/parser.rb', line 44 def parse_comment_line(raw, opts) idx_nl = raw.index("\n") idx_comment = raw.index(opts[:comment_char]) idx_nl = raw.length if idx_nl.nil? idx_comment = idx_nl + 1 if idx_comment.nil? line = "" # is a comment inside this line if idx_comment < idx_nl && idx_comment != 0 line = raw[0..(idx_comment - 1)] # in case we don't allow comments at the end # of an assignment/statement, ignore it and fall # back to treating this as a regular line if opts[:standalone_comments] && !is_empty_line(line) line = raw[0..(idx_nl - 1)] end # if there is no comment in this line elsif idx_comment > idx_nl && idx_nl != 0 line = raw[0..(idx_nl - 1)] end [line, idx_nl] end |