Class: Application::Makegit

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Makegit



13
14
15
16
# File 'lib/makegit.rb', line 13

def initialize(argv)
	@params, @project_name = parse_options(argv)
	@git_user, @git_token = Config.new.
end

Instance Attribute Details

#git_tokenObject (readonly)

Returns the value of attribute git_token.



11
12
13
# File 'lib/makegit.rb', line 11

def git_token
  @git_token
end

#git_userObject (readonly)

Returns the value of attribute git_user.



11
12
13
# File 'lib/makegit.rb', line 11

def git_user
  @git_user
end

#paramsObject (readonly)

Returns the value of attribute params.



11
12
13
# File 'lib/makegit.rb', line 11

def params
  @params
end

#project_nameObject (readonly)

Returns the value of attribute project_name.



11
12
13
# File 'lib/makegit.rb', line 11

def project_name
  @project_name
end

Instance Method Details

#parse_options(argv) ⇒ Object

Raises:

  • (ArgumentError)


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/makegit.rb', line 24

def parse_options(argv)
	argv << '-h' if argv.empty?
	params = {}
	OptionParser.new do |opts|
	 	opts.banner = "Usage: [project_name] [options]"

		opts.on("-h", "--help", "Prints this help") do
			puts opts
      	exit
		end

		opts.on("--rubygem", "Creates RubyGem project template") do
			params[:template] = "rubygem"
		end

	end.parse!
	
	project_name = argv[0]
	raise ArgumentError, "No Project Name Given", caller if project_name == nil || project_name.empty?
	
	[params, project_name]

end

#runObject



18
19
20
21
22
# File 'lib/makegit.rb', line 18

def run
	FSBuilder.new(project_name, params[:template]).build
	RepoBuilder.new(project_name, git_user, git_token).build
	STDOUT.puts "Project successfully created. Type \"cd #{project_name}\" and get to work!"
end