Module: Docter::Resource::Reloadable
- Included in:
- Base
- Defined in:
- lib/docter/common.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
The filename, if this resource comes from a file, otherwise nil.
Instance Method Summary collapse
-
#modified ⇒ Object
:call-seq: modified => time.
-
#modified? ⇒ Boolean
:call-seq: modified? => boolean.
-
#reload ⇒ Object
:call-seq: reload.
-
#to_s ⇒ Object
:nodoc:.
Instance Attribute Details
#filename ⇒ Object (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
#modified ⇒ Object
: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.
93 94 95 |
# File 'lib/docter/common.rb', line 93 def modified? @filename ? File.stat(@filename).mtime > @modified : false end |
#reload ⇒ Object
: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_s ⇒ Object
:nodoc:
108 109 110 |
# File 'lib/docter/common.rb', line 108 def to_s #:nodoc: @filename || super end |