class Gennaro

Attributes

appname[RW]
classname[RW]
path[RW]
template[RW]

Public Class Methods

get_templates(path) click to toggle source
# File lib/gennaro/gennaro.rb, line 51
def self.get_templates(path)
  Dir.glob("#{path}/*").map { |f| File.basename f}
end
new(template, classname, path, force = false) click to toggle source
# File lib/gennaro/gennaro.rb, line 14
def initialize(template, classname, path, force = false)
  @template  = template
  @classname = classname
  @appname   = classname.downcase
  @path      = File.join path, @appname

  delete_dir @path if force
  raise ArgumentError, "#{@path} already exists." if     Dir.exists? @path
  raise ArgumentError, "#{@template} not found."  unless Dir.exists? @template
end
template_exists?(path, template) click to toggle source
# File lib/gennaro/gennaro.rb, line 55
def self.template_exists?(path, template)
  self.get_templates(path).include? template
end
version() click to toggle source
# File lib/gennaro/version.rb, line 12
def self.version
  '0.3.6.5'
end

Public Instance Methods

delete_dir(path) click to toggle source
# File lib/gennaro/file.rb, line 12
def delete_dir(path)
  FileUtils.rm_r path if Dir.exists? path
end
generate!() click to toggle source
# File lib/gennaro/gennaro.rb, line 30
def generate!
  mkdir @path
  copy  @template, @path
end
get_random_string(length = 8) click to toggle source
# File lib/gennaro/gennaro.rb, line 25
def get_random_string(length = 8)
  dict = (?a..?z).to_a + (?A..?Z).to_a + (0..9).to_a
  (0..length).map { dict.sample}.join
end
replace_tags!() click to toggle source
# File lib/gennaro/gennaro.rb, line 35
def replace_tags!
  each_file(@appname) { |f|
    rename f, /_class_name_/, @appname
  }

  each_file(@appname) { |f|
    s = File.read f
    File.open(f, ?w) { |f|
      s.gsub! '${ClassName}',      @classname
      s.gsub! '${AppName}',        @appname
      s.gsub! '${GenerateString}', get_random_string(36)
      f.write s
    }
  }
end

Protected Instance Methods

copy(what, where) click to toggle source
# File lib/gennaro/file.rb, line 22
def copy(what, where)
  FileUtils.copy_entry what, where
end
each_file(path) { |f| ... } click to toggle source
# File lib/gennaro/file.rb, line 27
def each_file(path, &block)
  Dir.glob("#{path}/**/*").each { |f|
    next if File.directory? f
    yield f
  }
end
mkdir(path) click to toggle source
# File lib/gennaro/file.rb, line 17
def mkdir(path)
  Dir.mkdir path unless Dir.exists? path
end
rename(file, first, after) click to toggle source
# File lib/gennaro/file.rb, line 35
def rename(file, first, after)
  new_file = file.gsub(first, after)
  FileUtils.mv file, new_file if file != new_file
end