Class: Gem::Create::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/rubygems/create/builder.rb

Overview

The Builder class is used to provide variables in ERB templates.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Builder

Creates a new Builder

name - The name of the gem. options - The options used to create the gem.



14
15
16
17
# File 'lib/rubygems/create/builder.rb', line 14

def initialize(name, options = {})
  @options = options
  @name    = name
end

Instance Attribute Details

#nameObject (readonly)

The name of the gem.



5
6
7
# File 'lib/rubygems/create/builder.rb', line 5

def name
  @name
end

#optionsObject (readonly)

The options supplied to the command line.



8
9
10
# File 'lib/rubygems/create/builder.rb', line 8

def options
  @options
end

Instance Method Details

#authorObject

Returns the gem author’s name.



25
26
27
# File 'lib/rubygems/create/builder.rb', line 25

def author
  options[:author] || git_config('user.name')
end

#emailObject

Returns the gem author’s email address.



30
31
32
# File 'lib/rubygems/create/builder.rb', line 30

def email
  options[:email] || git_config('user.email')
end

#gem_classObject

The class name of the gem in CamelCase.



59
60
61
# File 'lib/rubygems/create/builder.rb', line 59

def gem_class
  name.split('-').map { |seg| seg.gsub(/(?:^|_| )(.)/) { $1.upcase } }.join('::')
end

#get_bindingObject

Returns the binding of this object.



20
21
22
# File 'lib/rubygems/create/builder.rb', line 20

def get_binding
  binding
end

#gitObject

The path to git.



49
50
51
# File 'lib/rubygems/create/builder.rb', line 49

def git
  options[:git] || "git"
end

#git_config(key) ⇒ Object

Returns the given variable from ‘git config`

key - The key to query.

Returns a String.



44
45
46
# File 'lib/rubygems/create/builder.rb', line 44

def git_config(key)
  %x{#{git} config --global #{key} 2> /dev/null}.chomp.strip
end

#github_nameObject

Returns the gem author’s Github username.



35
36
37
# File 'lib/rubygems/create/builder.rb', line 35

def github_name
  options[:github_name] || git_config('github.user')
end

#pathObject

The path of the gem.



54
55
56
# File 'lib/rubygems/create/builder.rb', line 54

def path
  name.gsub('-', '/')
end