Class: Utils::AST::CaskAST Private
Overview
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
Helper class for editing casks.
Constant Summary
Constants included from Utils::AST
BlockNode, DefNode, Node, ProcessedSource, SendNode, TreeRewriter
Constants included from Kernel
Kernel::IGNORE_INTERRUPTS_MUTEX
Instance Method Summary collapse
- #depends_on_macos? ⇒ Boolean private
- #initialize(cask_contents) ⇒ void constructor private
- #process ⇒ String private
- #replace_first_stanza_value(name, value) ⇒ void private
- #replace_stanza_value(name, old_value, new_value) ⇒ Integer private
Methods included from Utils::AST
body_children, call_node_match?, component_match?, literal_value, process_source, ruby_literal, stanza_text
Methods included from Kernel
#ensure_executable!, #exec_browser, #exec_editor, #ignore_interrupts, #interactive_shell, #quiet_system, #redirect_stdout, #safe_system, #which, #which_editor, #with_env, #with_homebrew_path
Constructor Details
#initialize(cask_contents) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
569 570 571 572 573 574 575 |
# File 'utils/ast.rb', line 569 def initialize(cask_contents) @cask_contents = cask_contents processed_source, cask_block = process_cask @processed_source = T.let(processed_source, ProcessedSource) @cask_block = T.let(cask_block, BlockNode) @tree_rewriter = T.let(TreeRewriter.new(processed_source.buffer), TreeRewriter) end |
Instance Method Details
#depends_on_macos? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
619 620 621 622 623 624 625 626 627 628 |
# File 'utils/ast.rb', line 619 def depends_on_macos? stanzas(:depends_on).any? do |stanza_node| stanza_node.arguments.any? do |argument| literal_value(argument) == :macos || (argument.hash_type? && T.cast(argument, RuboCop::AST::HashNode).pairs.any? do |pair| literal_value(pair.key) == :macos end) end end end |
#process ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
578 579 580 |
# File 'utils/ast.rb', line 578 def process tree_rewriter.process end |
#replace_first_stanza_value(name, value) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
583 584 585 586 587 588 |
# File 'utils/ast.rb', line 583 def replace_first_stanza_value(name, value) stanza_node = stanzas(name).first raise "Could not find '#{name}' stanza!" if stanza_node.blank? replace_stanza_argument(stanza_node, value) end |
#replace_stanza_value(name, old_value, new_value) ⇒ Integer
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 |
# File 'utils/ast.rb', line 597 def replace_stanza_value(name, old_value, new_value) replacement_count = T.let(0, Integer) stanzas(name).each do |stanza_node| if literal_value(stanza_node.first_argument) == old_value replace_stanza_argument(stanza_node, new_value) replacement_count += 1 end stanza_node.arguments.grep(RuboCop::AST::HashNode).each do |hash_node| hash_node.pairs.each do |pair| next if literal_value(pair.value) != old_value tree_rewriter.replace(pair.value.source_range, ruby_literal(new_value)) replacement_count += 1 end end end replacement_count end |