Class: Transpec::Syntax::Matcher
- Inherits:
-
Transpec::Syntax
- Object
- Transpec::Syntax
- Transpec::Syntax::Matcher
- Includes:
- AST::Sexp, SendNodeSyntax, Util
- Defined in:
- lib/transpec/syntax/matcher.rb
Instance Attribute Summary
Attributes inherited from Transpec::Syntax
#ancestor_nodes, #node, #report, #source_rewriter
Class Method Summary collapse
Instance Method Summary collapse
- #correct_operator!(parenthesize_arg = true) ⇒ Object
-
#initialize(node, source_rewriter, report = Report.new) ⇒ Matcher
constructor
A new instance of Matcher.
- #parenthesize!(always = true) ⇒ Object
Methods included from SendNodeSyntax
#arg_node, #arg_nodes, #arg_range, #method_name, #parentheses_range, #range_after_arg, #range_in_between_receiver_and_selector, #range_in_between_selector_and_arg, #receiver_node, #receiver_range, #selector_range
Methods included from Util
const_name, here_document?, in_parentheses?, indentation_of_line, proc_literal?
Methods inherited from Transpec::Syntax
all, #context, #expression_range, inherited, #parent_node, snake_case_name
Constructor Details
Class Method Details
.target_node?(node) ⇒ Boolean
12 13 14 |
# File 'lib/transpec/syntax/matcher.rb', line 12 def self.target_node?(node) false end |
Instance Method Details
#correct_operator!(parenthesize_arg = true) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/transpec/syntax/matcher.rb', line 22 def correct_operator!(parenthesize_arg = true) case method_name when :== convert_to_eq!(parenthesize_arg) when :===, :<, :<=, :>, :>= convert_to_be_operator! when :=~ convert_to_match!(parenthesize_arg) end end |
#parenthesize!(always = true) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/transpec/syntax/matcher.rb', line 33 def parenthesize!(always = true) return if argument_is_here_document? left_of_arg_source = range_in_between_selector_and_arg.source if left_of_arg_source.match(/\A *\Z/) parenthesize_single_line!(always) elsif left_of_arg_source.match(/\n|\r/) parenthesize_multi_line!(Regexp.last_match(0)) end end |