class LuigiProject
Attributes
status[R]
using_erb[R]
Public Class Methods
new(hash)
click to toggle source
initializes the project opens project from :path. if :template_path is given it will create a fresh project from template first and store it in path
# File lib/luigi_project.rb, line 13 def initialize hash @path = hash[:path] @settings = hash[:settings] @template_path = hash[:template_path] @data = hash[:data] @data ||= {} @logger = Logger.new STDOUT @logger.progname = "LuigiProject" unless @template_path.nil? create @template_path end open @path end
Public Instance Methods
create(template_path)
click to toggle source
attempting to fill erb if template ends in .erb filling with @settings
# File lib/luigi_project.rb, line 32 def create(template_path) @using_erb = File.extname(@template_path) == ".erb" template_basename = File.basename @template_path template_basename = File.basename @template_path, ".erb" if using_erb raise "Project file extension error!" unless File.extname(@path) == @settings['project_file_extension'] raise "Template file extension error!" unless File.extname(template_basename) == @settings['project_file_extension'] raise "Template does not exist!" unless File.exists? @template_path raise "Project file already exists! (#{@path})" if File.exists? @path if @using_erb create_with_erb(template_path) else FileUtils.cp @template_path, @path end end
create_with_erb(template_path)
click to toggle source
# File lib/luigi_project.rb, line 54 def create_with_erb template_path engine=ERB.new(File.read(template_path),nil,'<>') b = fill_template() result = engine.result(b) file = File.new @path, "w" result.lines.each do |line| file.write line end file.close end
date()
click to toggle source
# File lib/luigi_project.rb, line 86 def date return Date.today end
fill_template()
click to toggle source
# File lib/luigi_project.rb, line 50 def fill_template return binding end
index()
click to toggle source
returns index
# File lib/luigi_project.rb, line 82 def index 123 end
name()
click to toggle source
returns name
# File lib/luigi_project.rb, line 77 def name File.basename @path, ".yml" end
open(path)
click to toggle source
opens project form path
# File lib/luigi_project.rb, line 67 def open path @path = path end
path()
click to toggle source
returns path
# File lib/luigi_project.rb, line 72 def path @path end