Module: Docter::Resource::Reloadable

Included in:
Base
Defined in:
lib/docter/common.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#filenameObject (readonly)

The filename, if this resource comes from a file, otherwise nil.



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

def filename
  @filename
end

Instance Method Details

#modifiedObject

:call-seq:

modified => time

Returns the date/time this resource was last modified. If the resource comes from a file, the timestamp of the file, otherwise the when the resource was created.



84
85
86
# File 'lib/docter/common.rb', line 84

def modified
  @filename ? File.stat(@filename).mtime : @modified
end

#modified?Boolean

:call-seq:

modified? => boolean

Returns true if the resource was modified since it was lase (re)loaded. Only applies to resources created from a file, all other resources return false.

Returns:

  • (Boolean)


93
94
95
# File 'lib/docter/common.rb', line 93

def modified?
  @filename ? File.stat(@filename).mtime > @modified : false
end

#reloadObject

:call-seq:

reload

Reloads the resource. Only applies to resources created from a file, otherwise acts like load. You can safely call it for all resources, for example:

page.reload if page.modified?


103
104
105
106
# File 'lib/docter/common.rb', line 103

def reload
  @loaded = false if @filename
  load
end

#to_sObject

:nodoc:



108
109
110
# File 'lib/docter/common.rb', line 108

def to_s #:nodoc:
  @filename || super
end