Class: Hephaestus::Actions::StripCommentsAction::StripComments
- Inherits:
-
Object
- Object
- Hephaestus::Actions::StripCommentsAction::StripComments
- Defined in:
- lib/hephaestus/actions/strip_comments_action.rb
Overview
Strips full-line and inline comments from a buffer but does not remove whitespaces or newlines after the fact. Example input:
MyGem.application.configure do |config|
# Full-line comment
config.option1 = :value # Inline comment
end
The output is:
MyGem.application.configure do |config|
config.option1 = :value
end
Class Method Summary collapse
Class Method Details
.call(source, parser) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/hephaestus/actions/strip_comments_action.rb', line 56 def call(source, parser) buffer = Parser::Source::Buffer.new(nil, source: source) rewriter = Parser::Source::TreeRewriter.new(buffer) _, comments = parser.parse_with_comments(buffer) comments.each do |comment| strip_comment(comment, buffer, rewriter) end rewriter.process end |