Class: HomebrewAutomation::Formula
- Inherits:
-
Object
- Object
- HomebrewAutomation::Formula
- Defined in:
- lib/homebrew_automation/formula.rb
Overview
An in-memory, programmable representation of some Formula.rb Ruby source file, containing the definition of a Homebrew Bottle. See Homebrew docs for concepts: docs.brew.sh/Bottles.html
Instance methods produce new instances where sensible, leaving all instances free from mutation.
#== and #hash delegates to the underlying Parser::AST::Node
.
Class Method Summary collapse
-
.parse_string(s) ⇒ Formula
Parse the string form of a Homebrew Formula source file into a Formula.
Instance Method Summary collapse
-
#==(o) ⇒ Boolean
(also: #eql?)
Both formulae are ==, as per Parser::AST::Node#==.
-
#hash ⇒ Integer
Hash of the
Parser::AST::Node
. -
#initialize(ast) ⇒ Formula
constructor
Take an post-parsing abstract syntax tree representation of a Homebrew Formula.
-
#put_bottle(os, sha256) ⇒ Formula
Insert or replace the Homebrew Bottle for a given OS.
-
#put_sdist(url, sha256) ⇒ Formula
Update two fields together.
-
#rm_all_bottles ⇒ Formula
Remove sha256 references to all bottles.
-
#to_s ⇒ String
Produce Homebrew Formula source code as a string, suitable for saving as a Ruby source file.
-
#update_field(field, value) ⇒ Formula
Update a top-level field in the Formula.
Constructor Details
#initialize(ast) ⇒ Formula
Take an post-parsing abstract syntax tree representation of a Homebrew Formula. This is mostly not intended for common use-cases.
33 34 35 |
# File 'lib/homebrew_automation/formula.rb', line 33 def initialize ast @ast = ast end |
Class Method Details
.parse_string(s) ⇒ Formula
Parse the string form of a Homebrew Formula source file into a HomebrewAutomation::Formula.
#to_s is the inverse of this method.
25 26 27 |
# File 'lib/homebrew_automation/formula.rb', line 25 def self.parse_string s Formula.new (Parser::CurrentRuby.parse s) end |
Instance Method Details
#==(o) ⇒ Boolean Also known as: eql?
Both formulae are ==, as per Parser::AST::Node#==.
In practice, I think this means both formulae are equivalent in terms of Ruby semantics.
106 107 108 |
# File 'lib/homebrew_automation/formula.rb', line 106 def == o self.class == o.class && @ast == o.ast end |
#hash ⇒ Integer
Hash of the Parser::AST::Node
113 114 115 |
# File 'lib/homebrew_automation/formula.rb', line 113 def hash @ast.hash end |
#put_bottle(os, sha256) ⇒ Formula
Insert or replace the Homebrew Bottle for a given OS
78 79 80 81 82 83 |
# File 'lib/homebrew_automation/formula.rb', line 78 def put_bottle os, sha256 Formula.new update( @ast, bot_begin_path, put_bottle_version(os, sha256)) end |
#put_sdist(url, sha256) ⇒ Formula
Update two fields together
68 69 70 71 |
# File 'lib/homebrew_automation/formula.rb', line 68 def put_sdist url, sha256 update_field("url", url). update_field("sha256", sha256) end |
#rm_all_bottles ⇒ Formula
Remove sha256 references to all bottles
This may leave the Formula in a non-standard state. Please add at lease one bottle referene back, otherwise why are you even declaring a bottles block at all.
92 93 94 95 96 97 |
# File 'lib/homebrew_automation/formula.rb', line 92 def rm_all_bottles Formula.new update( @ast, bot_begin_path, rm_all_bottle_sha256s) end |
#to_s ⇒ String
Produce Homebrew Formula source code as a string, suitable for saving as a Ruby source file.
This is the inverse of parse_string.
43 44 45 |
# File 'lib/homebrew_automation/formula.rb', line 43 def to_s Unparser.unparse @ast end |
#update_field(field, value) ⇒ Formula
Update a top-level field in the Formula
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/homebrew_automation/formula.rb', line 52 def update_field field, value Formula.new update( @ast, [ by_type('begin'), by_both( by_type('send'), by_msg(field)), by_type('str')], -> (n) { n.updated(nil, [value]) }) end |