Class: Nanoc2::Code
- Inherits:
-
Object
- Object
- Nanoc2::Code
- Defined in:
- lib/nanoc2/base/code.rb
Overview
Nanoc2::Code represent the custom code of a nanoc site. It contains the textual source code as well as a mtime, which is used to speed up site compilation.
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
The textual source code representation.
-
#mtime ⇒ Object
readonly
The time where the code was last modified.
-
#site ⇒ Object
The Nanoc2::Site this code belongs to.
Instance Method Summary collapse
-
#initialize(data, mtime = nil) ⇒ Code
constructor
Creates a new code object.
-
#load ⇒ Object
Loads the code by executing it.
-
#save ⇒ Object
Saves the code in the database, creating it if it doesn’t exist yet or updating it if it already exists.
Constructor Details
#initialize(data, mtime = nil) ⇒ Code
Creates a new code object. data
is the raw source code, which will be executed before compilation. mtime
is the time when the code was last modified (optional).
20 21 22 23 |
# File 'lib/nanoc2/base/code.rb', line 20 def initialize(data, mtime=nil) @data = data @mtime = mtime end |
Instance Attribute Details
#data ⇒ Object (readonly)
The textual source code representation.
12 13 14 |
# File 'lib/nanoc2/base/code.rb', line 12 def data @data end |
#mtime ⇒ Object (readonly)
The time where the code was last modified.
15 16 17 |
# File 'lib/nanoc2/base/code.rb', line 15 def mtime @mtime end |
#site ⇒ Object
The Nanoc2::Site this code belongs to.
9 10 11 |
# File 'lib/nanoc2/base/code.rb', line 9 def site @site end |
Instance Method Details
#load ⇒ Object
Loads the code by executing it.
26 27 28 |
# File 'lib/nanoc2/base/code.rb', line 26 def load eval(@data, TOPLEVEL_BINDING) end |
#save ⇒ Object
Saves the code in the database, creating it if it doesn’t exist yet or updating it if it already exists. Tells the site’s data source to save the code.
33 34 35 36 37 |
# File 'lib/nanoc2/base/code.rb', line 33 def save @site.data_source.loading do @site.data_source.save_code(self) end end |