Module: EasyAppHelper::Tasks::TemplateManager

Defined in:
lib/tasks/template_manager.rb

Constant Summary collapse

TEMPLATE =
File.expand_path '../template.rb.erb', __FILE__

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#current_dateObject (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_nameObject (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_moduleObject (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_nameObject (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_classObject (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

#taskObject (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_dirObject



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_specObject



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_templateObject



13
14
15
# File 'lib/tasks/template_manager.rb', line 13

def get_template
  File.read TEMPLATE
end