module Luban::Deployment::Helpers::Generator::Base

Protected Instance Methods

copy_dir(src_path, dst_path, stages: [], depth: 1) click to toggle source
# File lib/luban/deployment/helpers/generator.rb, line 51
def copy_dir(src_path, dst_path, stages: [], depth: 1)
  indent = '  ' * depth
  print indent + "- #{dst_path.basename}"
  mkdir(dst_path)
  src_files = []
  src_path.each_child do |p|
    if p.directory?
      if placeholder?(p.basename)
        stages.each do |s| 
          copy_dir(p, dst_path.join(staged_basename(s, p.basename)), depth: depth + 1)
        end
      else
        copy_dir(p, dst_path.join(p.basename), stages: stages, depth: depth + 1)
      end
    else
      src_files << p
    end
  end
  src_files.each do |f|
    basename = f.basename
    action = :copy_file
    if basename.extname == '.erb'
      basename = basename.sub_ext('')
      action = :render_file
    end
    if placeholder?(basename)
      stages.each do |stage|
        n = staged_basename(stage, basename)
        print indent + "  - #{n}"
        send(action, f, dst_path.join(n), context: binding)
      end
    else
      print indent + "  - #{basename}"
      send(action, f, dst_path.join(basename))
    end
  end
end
placeholder?(basename) click to toggle source
# File lib/luban/deployment/helpers/generator.rb, line 89
def placeholder?(basename)
  basename.to_s =~ /^__stage/
end
skeletons_path() click to toggle source
# File lib/luban/deployment/helpers/generator.rb, line 46
def skeletons_path
  @skeletons_path ||= 
    Pathname.new(__FILE__).dirname.join('..', 'templates').realpath
end
staged_basename(stage, basename) click to toggle source
# File lib/luban/deployment/helpers/generator.rb, line 93
def staged_basename(stage, basename)
  basename.to_s.sub!(/^__stage/, stage)
end