Class: Tzispa::Rig::File
Instance Attribute Summary collapse
Attributes inherited from TemplateBase
#content
Instance Method Summary
collapse
#loaded?, #parse!, #render
Constructor Details
#initialize(name, encoding: 'UTF-8') ⇒ File
Returns a new instance of File.
60
61
62
63
64
65
|
# File 'lib/tzispa/rig/template.rb', line 60
def initialize(name, encoding: 'UTF-8')
super()
@filename = name
@loaded = false
@encoding = encoding
end
|
Instance Attribute Details
#encoding ⇒ Object
Returns the value of attribute encoding.
58
59
60
|
# File 'lib/tzispa/rig/template.rb', line 58
def encoding
@encoding
end
|
#filename ⇒ Object
Returns the value of attribute filename.
58
59
60
|
# File 'lib/tzispa/rig/template.rb', line 58
def filename
@filename
end
|
Instance Method Details
#create(content = nil) ⇒ Object
88
89
90
|
# File 'lib/tzispa/rig/template.rb', line 88
def create(content = nil)
::File.open(filename, "w:#{encoding}") { |f| f.puts content }
end
|
#exist? ⇒ Boolean
71
72
73
|
# File 'lib/tzispa/rig/template.rb', line 71
def exist?
::File.exist?(filename)
end
|
#load! ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/tzispa/rig/template.rb', line 75
def load!
raise Tzispa::Rig::NotFound.new(filename) unless exist?
::File.open(filename, "r:#{encoding}") do |f|
@content = String.new
@modified = f.mtime
f.each { |line| @content << line }
@loaded = true
end
self
rescue Errno::ENOENT
raise Tzispa::Rig::ReadError.new(@file)
end
|
#modified? ⇒ Boolean
67
68
69
|
# File 'lib/tzispa/rig/template.rb', line 67
def modified?
@modified && (@modified != ::File.mtime(filename))
end
|