Module: Gembuild

Defined in:
lib/gembuild.rb,
lib/gembuild/project.rb,
lib/gembuild/version.rb,
lib/gembuild/pkgbuild.rb,
lib/gembuild/exceptions.rb,
lib/gembuild/aur_scraper.rb,
lib/gembuild/gem_scraper.rb

Overview

Gembuild: create Arch Linux PKGBUILDs for ruby gems. Copyright © 2015 Mario Finelli <[email protected]>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <www.gnu.org/licenses/>.

Defined Under Namespace

Classes: AurScraper, GemNotFoundError, GemScraper, InvalidPkgbuildError, Pkgbuild, Project, UndefinedGemNameError, UndefinedPkgnameError

Constant Summary collapse

VERSION =

Current version of Gembuild.

'1.0.0'

Class Method Summary collapse

Class Method Details

.conf_fileString

The path to the gembuild configuration file.

Returns:

  • (String)

    real path to the configuration file



34
35
36
# File 'lib/gembuild.rb', line 34

def conf_file
  File.expand_path(File.join('~', '.gembuild'))
end

.configureHash

Read from the configuration file if it exists, otherwise prompt for the configuration and save it to file.

Returns:

  • (Hash)

    the configuration options: maintainer name and email address and where to checkout packages



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/gembuild.rb', line 43

def configure
  unless File.file?(conf_file)
    name = fetch_git_global_name
    email = fetch_git_global_email
    pkgdir = fetch_pkgdir

    File.write(
      conf_file,
      { name: name, email: email, pkgdir: pkgdir }.to_yaml
    )
  end

  YAML.load_file(conf_file)
end

.fetch_git_global_emailString

Attempt to read the global git email, prompting the user for the email if unsuccessful.

Returns:

  • (String)

    the email to use as package maintainer



80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/gembuild.rb', line 80

def fetch_git_global_email
  email = `git config --global user.email`.strip

  if $CHILD_STATUS.success?
    if prompt_for_confirmation(email)
      return email
    else
      prompt_for_git_email
    end
  else
    prompt_for_git_email('Could not detect email from git configuration.')
  end
end

.fetch_git_global_nameString

Attempt to read the global git name, prompting the user for the name if unsuccessful.

Returns:

  • (String)

    the name to use as package maintainer



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/gembuild.rb', line 62

def fetch_git_global_name
  name = `git config --global user.name`.strip

  if $CHILD_STATUS.success?
    if prompt_for_confirmation(name)
      return name
    else
      prompt_for_git_name
    end
  else
    prompt_for_git_name('Could not detect name from git configuration.')
  end
end

.fetch_pkgdirString

Prompt the user for the location where they would like to store checked-out packages.

Returns:

  • (String)

    the filepath where to store package repositories



137
138
139
140
# File 'lib/gembuild.rb', line 137

def fetch_pkgdir
  puts 'Where should projects be checked out?'
  File.expand_path(gets.chomp)
end

.prompt_for_confirmation(detected) ⇒ Boolean

Ask the user to confirm the detected value.

Parameters:

  • detected (String)

    The value that was detected.

Returns:

  • (Boolean)

    whether or not the value is correct



126
127
128
129
130
131
# File 'lib/gembuild.rb', line 126

def prompt_for_confirmation(detected)
  puts "Detected \"#{detected}\", is this correct? (y/n)"
  response = gets.chomp.downcase[0, 1]

  response == 'y'
end

.prompt_for_git_email(msg = nil) ⇒ String

Prompt the user for the email to use.

This method is only called if reading the global git configuration was unsuccessful or the user specified that it was incorrect.

Parameters:

  • msg (String, nil) (defaults to: nil)

    An optional message to display before prompting.

Returns:

  • (String)

    the email address to use as package maintainer



116
117
118
119
120
# File 'lib/gembuild.rb', line 116

def prompt_for_git_email(msg = nil)
  puts msg unless msg.nil? || msg.empty?
  puts 'Please enter desired email: '
  gets.chomp
end

.prompt_for_git_name(msg = nil) ⇒ String

Prompt the user for the name to use.

This method is only called if reading the global git configuration was unsuccessful or the user specified that it was incorrect.

Parameters:

  • msg (String, nil) (defaults to: nil)

    An optional message to display before prompting.

Returns:

  • (String)

    the name to use as package maintainer



102
103
104
105
106
# File 'lib/gembuild.rb', line 102

def prompt_for_git_name(msg = nil)
  puts msg unless msg.nil? || msg.empty?
  puts 'Please enter desired name: '
  gets.chomp
end