Class: HomebrewAutomation::Tap

Inherits:
Object
  • Object
show all
Defined in:
lib/homebrew_automation/tap.rb

Overview

A representation of a Github repo that acts as a Homebrew Tap.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, repo, token) ⇒ Tap

See #user, #repo, #token.



10
11
12
13
14
15
# File 'lib/homebrew_automation/tap.rb', line 10

def initialize(user, repo, token)
  @user = user
  @repo = repo
  @token = token
  @url = "https://#{token}@github.com/#{user}/#{repo}.git"
end

Instance Attribute Details

#repoString (readonly)

Github repo name, as appears in Github URLs

Returns:

  • (String)


25
26
27
# File 'lib/homebrew_automation/tap.rb', line 25

def repo
  @repo
end

#tokenString (readonly)

Github OAuth token

Get a token for yourself here: github.com/settings/tokens

Returns:

  • (String)


32
33
34
# File 'lib/homebrew_automation/tap.rb', line 32

def token
  @token
end

#urlString (readonly)

Repo URL, as expected by Git

Returns:

  • (String)


37
38
39
# File 'lib/homebrew_automation/tap.rb', line 37

def url
  @url
end

#userString (readonly)

Github username

Returns:

  • (String)


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.

Parameters:

  • formula (String)

    Part of the name to the file within the Formula directory inside the Tap repo’s directory, excluding the .rb suffix.

Yield Parameters:

  • formula (Formula)

    existing Formula

Yield Returns:

  • (Formula)

    after your modifications

Returns:



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