Class: MKBrut::Ops::InsertCodeInMethod
- Inherits:
-
PrismParsingOp
- Object
- BaseOp
- PrismParsingOp
- MKBrut::Ops::InsertCodeInMethod
- Defined in:
- lib/mkbrut/ops/insert_code_in_method.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(file:, class_name:, method_name:, code:, where: :end) ⇒ InsertCodeInMethod
constructor
A new instance of InsertCodeInMethod.
Methods inherited from BaseOp
dry_run=, dry_run?, #dry_run?, fileutils_args, #fileutils_args
Constructor Details
#initialize(file:, class_name:, method_name:, code:, where: :end) ⇒ InsertCodeInMethod
Returns a new instance of InsertCodeInMethod.
2 3 4 5 6 7 8 |
# File 'lib/mkbrut/ops/insert_code_in_method.rb', line 2 def initialize(file:, class_name:, method_name:, code:, where: :end) @file = file @class_name = class_name @method_name = method_name.to_sym @code = code @where = where end |
Instance Method Details
#call ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/mkbrut/ops/insert_code_in_method.rb', line 10 def call method_node = find_method(class_name: @class_name, method_name: @method_name) insertion_point = if @where == :start insertion_point_for_code_at_start_of_method(method_node: method_node) else insertion_point_for_code_at_end_of_method(method_node: method_node) end indented_code = indent_code_for_method(method_node: method_node) new_source = @source.dup.insert(insertion_point, indented_code) File.write(@file, new_source) end |