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
-
#init(options) ⇒ void
Initialises a gem folder structure based on the project name passed in from the command line and populates it with command files and configuration.
-
#process_template(file_path, options) ⇒ String
Reads an ERB file and populates the templated data from info in the current execution scope.
Methods included from Utility::StringHelpers
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
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 = 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.('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), ) 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
60 61 62 63 64 |
# File 'lib/gemstrapper.rb', line 60 def process_template(file_path, ) template_data = File.read(file_path) ERB.new(template_data).result binding end |