Class: HomebrewAutomation::Tap
- Inherits:
-
Object
- Object
- HomebrewAutomation::Tap
- Defined in:
- lib/homebrew_automation/tap.rb
Overview
A representation of a Github repo that acts as a Homebrew Tap.
Instance Attribute Summary collapse
-
#repo ⇒ String
readonly
Github repo name, as appears in Github URLs.
-
#token ⇒ String
readonly
Github OAuth token.
-
#url ⇒ String
readonly
Repo URL, as expected by Git.
-
#user ⇒ String
readonly
Github username.
Instance Method Summary collapse
- #initialize(user, repo, token) ⇒ Tap constructor
-
#on_formula!(formula) {|formula| ... } ⇒ Formula
Overwrite the specified Formula file, in-place, on-disk.
Constructor Details
Instance Attribute Details
#repo ⇒ String (readonly)
Github repo name, as appears in Github URLs
25 26 27 |
# File 'lib/homebrew_automation/tap.rb', line 25 def repo @repo end |
#token ⇒ String (readonly)
Github OAuth token
Get a token for yourself here: github.com/settings/tokens
32 33 34 |
# File 'lib/homebrew_automation/tap.rb', line 32 def token @token end |
#url ⇒ String (readonly)
Repo URL, as expected by Git
37 38 39 |
# File 'lib/homebrew_automation/tap.rb', line 37 def url @url end |
#user ⇒ String (readonly)
Github username
20 21 22 |
# File 'lib/homebrew_automation/tap.rb', line 20 def user @user end |
Instance Method Details
#on_formula!(formula) {|formula| ... } ⇒ Formula
Overwrite the specified Formula file, in-place, on-disk
A directory named Formula
is assumed to be on Dir.pwd
.
If no block is passed, then this tries to find the formula file, but then makes no changes to that Formula.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/homebrew_automation/tap.rb', line 51 def on_formula!(formula, &block) name = "#{formula}.rb" block ||= ->(n) { n } Dir.chdir 'Formula' do File.open name, 'r' do |old_file| File.open "#{name}.new", 'w' do |new_file| new_file.write( block. call(Formula.parse_string(old_file.read)). to_s) end end File.rename "#{name}.new", name end end |