Class: Pod::Helper::TemplateFile

Inherits:
Object
  • Object
show all
Defined in:
lib/pod/helper/template_file.rb

Instance Method Summary collapse

Constructor Details

#initialize(project_name, project_prefix) ⇒ TemplateFile

Returns a new instance of TemplateFile.



7
8
9
10
11
12
# File 'lib/pod/helper/template_file.rb', line 7

def initialize(project_name,project_prefix)
  @project_name = project_name
  @project_prefix = project_prefix
  @project_year = Date.today.strftime('%Y')
  @project_identifier = "com.icemobile.#{project_name.downcase}"
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/pod/helper/template_file.rb', line 26

def exists?
  File.exists?(name)
end

#fileObject



36
37
38
39
40
41
42
# File 'lib/pod/helper/template_file.rb', line 36

def file
  if exists?
    File.read(name)
  else
    write
  end
end

#fixture_pathObject



14
15
16
# File 'lib/pod/helper/template_file.rb', line 14

def fixture_path
  File.join(File.dirname(File.expand_path(__FILE__)), '../../../fixtures')
end

#nameObject



32
33
34
# File 'lib/pod/helper/template_file.rb', line 32

def name
  "TemplateFile" 
end

#templateObject



44
45
46
# File 'lib/pod/helper/template_file.rb', line 44

def template
  ERB.new(File.read("#{fixture_path}/#{template_name}.erb"))
end

#template_nameObject



48
49
50
# File 'lib/pod/helper/template_file.rb', line 48

def template_name
  name
end

#writeObject



18
19
20
21
22
23
24
# File 'lib/pod/helper/template_file.rb', line 18

def write
  output_file = nil
  File.open(name, 'w') do |output_file|
    output_file.puts template.result binding
  end
  output_file
end