Module: Gemstrapper

Extended by:
Gemstrapper
Includes:
Utility::StringHelpers
Included in:
Gemstrapper
Defined in:
lib/gemstrapper.rb,
lib/gemstrapper/version.rb,
lib/gemstrapper/utility/string_helpers.rb

Overview

Top level module for the app.

Defined Under Namespace

Modules: Utility

Constant Summary collapse

VERSION =

Version Constant. Called as part of the gemspec definition

'1.0.0'

Instance Method Summary collapse

Methods included from Utility::StringHelpers

#module_name_for

Instance Method Details

#init(options) ⇒ void

This method returns an undefined value.

Initialises a gem folder structure based on the project name passed in from the command line and populates it with command files and configuration

Parameters:

  • options (Hash)

    The options passed in from the command line execution



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/gemstrapper.rb', line 18

def init(options)
	@options = options

	new_files = []

	@options[:module_name] = module_name_for(@options[:project_name])
	# Getting a list of folders to create based on folder structure within lib/templates
	templates_directory = File.expand_path('gemstrapper/templates', File.dirname(__FILE__))

	files = Dir.chdir(templates_directory) do
		Dir.glob('**/*.erb')
	end

	files.each do |file|
		## creates directories
		# converting project name placeholder to actual project name and stripping off erb extension
		new_file_path = file.gsub('project_name', @options[:project_name]).gsub('.erb', '')
		directory = File.dirname(new_file_path)

		unless File.exist? directory
			FileUtils.mkdir_p directory
		end

		data = process_template(File.join(templates_directory, file), options)
		File.write(new_file_path, data)
		new_files << new_file_path
	end

	#reporting
	new_files.each do |nf|
		puts "#{nf} created"
	end
end

#process_template(file_path, options) ⇒ String

Reads an ERB file and populates the templated data from info in the current execution scope

Parameters:

  • file_path (String)

    The absolute path of the ERB file

  • options (Hash)

    A Hash of options passed in from command line and generated dynamically. Is part of the execution scope so can be used as part of the ERB template

Returns:

  • (String)

    the data from the ERB file filled out with data



60
61
62
63
64
# File 'lib/gemstrapper.rb', line 60

def process_template(file_path, options)
	template_data = File.read(file_path)

	ERB.new(template_data).result binding
end