class Kanji::Generate
Constants
- SOURCE_DIR
- TEMPLATES_DIR
Attributes
processor[R]
target_dir[R]
template_files[R]
template_scope[R]
Public Class Methods
new(target_dir, template_scope)
click to toggle source
# File lib/kanji/generate.rb, line 12 def initialize(target_dir, template_scope) @target_dir = target_dir @template_scope = template_scope @template_files = Dir[SOURCE_DIR.join('**/{.,}*')] @processor = Class.new(Thor) do include Thor::Actions end.new @processor.class.source_root SOURCE_DIR end
Public Instance Methods
call(source, target)
click to toggle source
# File lib/kanji/generate.rb, line 23 def call(source, target) source = Pathname(source) aboslute_source_path = source.expand_path(SOURCE_DIR) target_file = get_target_file(target) template_file = template_files.find { |f| f == aboslute_source_path.to_s } or raise "missing template file +#{source}+" template_file = Pathname(template_file) processor.template template_file, target_file, template_scope create_executable(target_file) if executable?(template_file) end
Private Instance Methods
create_executable(file)
click to toggle source
# File lib/kanji/generate.rb, line 41 def create_executable(file) FileUtils.chmod "a+x", file end
executable?(file)
click to toggle source
# File lib/kanji/generate.rb, line 45 def executable?(file) file.file? && file.executable? end
get_target_file(target)
click to toggle source
# File lib/kanji/generate.rb, line 37 def get_target_file(target) Pathname.getwd.join(target_dir, target) end