Class: GitStart

Inherits:
Object
  • Object
show all
Includes:
Hooks, Hooks::InstanceHooks
Defined in:
lib/git-start.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.default_branchObject

Returns the value of attribute default_branch.



23
24
25
# File 'lib/git-start.rb', line 23

def default_branch
  @default_branch
end

.summaryObject

Returns the value of attribute summary.



25
26
27
# File 'lib/git-start.rb', line 25

def summary
  @summary
end

.titleObject

Returns the value of attribute title.



24
25
26
# File 'lib/git-start.rb', line 24

def title
  @title
end

Class Method Details

.ask_for(question, default = nil) ⇒ Object



56
57
58
59
60
# File 'lib/git-start.rb', line 56

def ask_for(question, default = nil)
  print "#{question}#{" [#{default}]" unless default.nil?}: "
  value = STDIN.readline.strip
  value == '' ? default : value
end

.branchObject



42
43
44
45
# File 'lib/git-start.rb', line 42

def branch
  @branch ||= ask_for('Branch name')
  @branch.strip.downcase.gsub(/[^\w\d\/]+/, '-')
end

.config(key, question = nil, scope = nil, default = nil) ⇒ Object



74
75
76
77
78
79
80
81
# File 'lib/git-start.rb', line 74

def config(key, question = nil, scope = nil, default = nil)
  value = git(:config, key).strip
  if value == '' and !question.nil?
    value = ask_for(question, default)
    git :config, scope, key, value
  end
  value
end

.current_branchObject



97
98
99
# File 'lib/git-start.rb', line 97

def current_branch
  `git rev-parse --abbrev-ref HEAD`.strip
end

.finishObject



34
35
36
37
38
39
40
# File 'lib/git-start.rb', line 34

def finish
  @branch = current_branch
  run_hook :setup
  run_hook :before_finish
  git :checkout, default_branch
  run_hook :after_finish
end

.git(command, *options) ⇒ Object



70
71
72
# File 'lib/git-start.rb', line 70

def git(command, *options)
  `git #{command} #{options.map{ |o| o.is_a?(Symbol) ? "--#{o}" : o}.join(' ')}`
end

.include_plugin(plugin) ⇒ Object



89
90
91
92
93
94
95
# File 'lib/git-start.rb', line 89

def include_plugin(plugin)
  @included_plugins ||= []
  return if @included_plugins.include?(plugin)
  @included_plugins << plugin
  file = File.expand_path("../git-start/plugins/#{plugin}.rb", __FILE__)
  instance_eval File.read(file)
end

.requires_gem(name) ⇒ Object



83
84
85
86
87
# File 'lib/git-start.rb', line 83

def requires_gem(name)
  require name
rescue LoadError
  abort "\nPlease install the `#{name}` Gem first:\n\ngem install #{name}\n\n"
end

.select_multiple_of(question, *option_lists) ⇒ Object



62
63
64
# File 'lib/git-start.rb', line 62

def select_multiple_of(question, *option_lists)
  select_of("#{question} (comma separated)", *option_lists)
end

.select_one_of(question, *option_lists) ⇒ Object



66
67
68
# File 'lib/git-start.rb', line 66

def select_one_of(question, *option_lists)
  select_of(question, *option_lists).first
end

.startObject



27
28
29
30
31
32
# File 'lib/git-start.rb', line 27

def start
  run_hook :setup
  run_hook :before_start
  git :checkout, "-b #{branch}"
  run_hook :after_start
end