Class: Tzispa::Rig::File

Inherits:
Object
  • Object
show all
Defined in:
lib/tzispa/rig/template.rb

Direct Known Subclasses

Template

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ File

Returns a new instance of File.



14
15
16
17
# File 'lib/tzispa/rig/template.rb', line 14

def initialize(file)
  @file = file
  @loaded = false
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



12
13
14
# File 'lib/tzispa/rig/template.rb', line 12

def content
  @content
end

#fileObject (readonly)

Returns the value of attribute file.



12
13
14
# File 'lib/tzispa/rig/template.rb', line 12

def file
  @file
end

#modifiedObject (readonly)

Returns the value of attribute modified.



12
13
14
# File 'lib/tzispa/rig/template.rb', line 12

def modified
  @modified
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/tzispa/rig/template.rb', line 27

def exists?
  ::File.exists?(@file)
end

#load!Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/tzispa/rig/template.rb', line 31

def load!
  begin
    raise NotFound.new("Template file '#{@file}' not found") unless exists?
    ::File.open(@file, 'r:UTF-8') { |f|
      @content = String.new
      @modified = f.mtime
      while line = f.gets
        @content << line
      end
    }
    @loaded = true
  rescue Errno::ENOENT
    raise ReadError.new "Template file '#{@file}' could not be read"
  end
  self
end

#loaded?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/tzispa/rig/template.rb', line 19

def loaded?
  @loaded
end

#modified?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/tzispa/rig/template.rb', line 23

def modified?
  @modified != File.mtime(@file)
end