Class: LuigiProject

Inherits:
Object
  • Object
show all
Defined in:
lib/luigi_project.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ LuigiProject

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



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 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

Instance Attribute Details

#statusObject (readonly)

Returns the value of attribute status.



7
8
9
# File 'lib/luigi_project.rb', line 7

def status
  @status
end

#using_erbObject (readonly)

Returns the value of attribute using_erb.



7
8
9
# File 'lib/luigi_project.rb', line 7

def using_erb
  @using_erb
end

Instance Method Details

#create(template_path) ⇒ Object

attempting to fill erb if template ends in .erb filling with @settings



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# 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) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
# 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

#dateObject



86
87
88
# File 'lib/luigi_project.rb', line 86

def date
  return Date.today
end

#fill_templateObject



50
51
52
# File 'lib/luigi_project.rb', line 50

def fill_template
  return binding
end

#indexObject

returns index



82
83
84
# File 'lib/luigi_project.rb', line 82

def index
  123
end

#nameObject

returns name



77
78
79
# File 'lib/luigi_project.rb', line 77

def name
  File.basename @path, ".yml"
end

#open(path) ⇒ Object

opens project form path



67
68
69
# File 'lib/luigi_project.rb', line 67

def open path
  @path = path
end

#pathObject

returns path



72
73
74
# File 'lib/luigi_project.rb', line 72

def path
  @path
end