Module: EasyAppHelper::Tasks::TemplateManager
- Defined in:
- lib/tasks/template_manager.rb
Constant Summary collapse
- TEMPLATE =
File. '../template.rb.erb', __FILE__
Instance Attribute Summary collapse
-
#current_date ⇒ Object
readonly
Returns the value of attribute current_date.
-
#executable_name ⇒ Object
readonly
Returns the value of attribute executable_name.
-
#gem_module ⇒ Object
readonly
Returns the value of attribute gem_module.
-
#gem_name ⇒ Object
readonly
Returns the value of attribute gem_name.
-
#script_class ⇒ Object
readonly
Returns the value of attribute script_class.
-
#task ⇒ Object
readonly
Returns the value of attribute task.
Instance Method Summary collapse
- #build_executable(executable_name = current_gem_name) ⇒ Object
- #check_bin_dir ⇒ Object
- #current_gem_spec ⇒ Object
- #get_template ⇒ Object
Instance Attribute Details
#current_date ⇒ Object (readonly)
Returns the value of attribute current_date.
9 10 11 |
# File 'lib/tasks/template_manager.rb', line 9 def current_date @current_date end |
#executable_name ⇒ Object (readonly)
Returns the value of attribute executable_name.
9 10 11 |
# File 'lib/tasks/template_manager.rb', line 9 def executable_name @executable_name end |
#gem_module ⇒ Object (readonly)
Returns the value of attribute gem_module.
9 10 11 |
# File 'lib/tasks/template_manager.rb', line 9 def gem_module @gem_module end |
#gem_name ⇒ Object (readonly)
Returns the value of attribute gem_name.
9 10 11 |
# File 'lib/tasks/template_manager.rb', line 9 def gem_name @gem_name end |
#script_class ⇒ Object (readonly)
Returns the value of attribute script_class.
9 10 11 |
# File 'lib/tasks/template_manager.rb', line 9 def script_class @script_class end |
#task ⇒ Object (readonly)
Returns the value of attribute task.
9 10 11 |
# File 'lib/tasks/template_manager.rb', line 9 def task @task end |
Instance Method Details
#build_executable(executable_name = current_gem_name) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/tasks/template_manager.rb', line 25 def build_executable(executable_name=current_gem_name) executable_name ||= current_gem_spec.name @executable_name = executable_name @gem_name = current_gem_spec.name @gem_module = @gem_name.camelize @current_date = Time.now.strftime('%c') @script_class = executable_name == current_gem_spec.name ? '' : executable_name.camelize @script_class << 'MasterScript' renderer = ERB.new(File.read(TEMPLATE), nil, '-') renderer.result binding end |
#check_bin_dir ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/tasks/template_manager.rb', line 17 def check_bin_dir spec = current_gem_spec rel_bin_dir = spec.bindir.empty? ? 'bin' : spec.bindir bin_dir = File.join task.application.original_dir, rel_bin_dir FileUtils.mkdir bin_dir unless Dir.exists? bin_dir bin_dir end |
#current_gem_spec ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/tasks/template_manager.rb', line 37 def current_gem_spec searcher = if Gem::Specification.respond_to? :find # ruby 2.0 Gem::Specification elsif Gem.respond_to? :searcher # ruby 1.8/1.9 Gem.searcher.init_gemspecs end unless searcher.nil? searcher.find do |spec| original_file = task ? File.join(task.application.original_dir, task.application.rakefile) : __FILE__ File.fnmatch(File.join(spec.full_gem_path,'*'), original_file) end end end |
#get_template ⇒ Object
13 14 15 |
# File 'lib/tasks/template_manager.rb', line 13 def get_template File.read TEMPLATE end |