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.



58
59
60
# File 'lib/docter/common.rb', line 58

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.



65
66
67
# File 'lib/docter/common.rb', line 65

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)


74
75
76
# File 'lib/docter/common.rb', line 74

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?


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

def reload()
  @loaded = false if @filename
  load
end

#to_sObject

:nodoc:



89
90
91
# File 'lib/docter/common.rb', line 89

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