Class: Nanoc3::CodeSnippet
- Inherits:
-
Object
- Object
- Nanoc3::CodeSnippet
- Defined in:
- lib/nanoc3/base/source_data/code_snippet.rb
Overview
Nanoc3::CodeSnippet represent a piece of custom code of a nanoc site.
Instance Attribute Summary collapse
-
#data ⇒ String
readonly
A string containing the actual code in this code snippet.
-
#filename ⇒ String
readonly
The filename corresponding to this code snippet.
Instance Method Summary collapse
-
#checksum ⇒ String
The checksum for this object.
-
#initialize(data, filename, params = nil) ⇒ CodeSnippet
constructor
Creates a new code snippet.
- #inspect ⇒ Object
-
#load ⇒ void
Loads the code by executing it.
-
#reference ⇒ Object
Returns an object that can be used for uniquely identifying objects.
Constructor Details
#initialize(data, filename, params = nil) ⇒ CodeSnippet
Creates a new code snippet.
27 28 29 30 |
# File 'lib/nanoc3/base/source_data/code_snippet.rb', line 27 def initialize(data, filename, params=nil) @data = data @filename = filename end |
Instance Attribute Details
#data ⇒ String (readonly)
A string containing the actual code in this code snippet.
11 12 13 |
# File 'lib/nanoc3/base/source_data/code_snippet.rb', line 11 def data @data end |
#filename ⇒ String (readonly)
The filename corresponding to this code snippet.
16 17 18 |
# File 'lib/nanoc3/base/source_data/code_snippet.rb', line 16 def filename @filename end |
Instance Method Details
#checksum ⇒ String
Returns The checksum for this object. If its contents change, the checksum will change as well.
52 53 54 |
# File 'lib/nanoc3/base/source_data/code_snippet.rb', line 52 def checksum @data.checksum end |
#inspect ⇒ Object
46 47 48 |
# File 'lib/nanoc3/base/source_data/code_snippet.rb', line 46 def inspect "<#{self.class}:0x#{self.object_id.to_s(16)} filename=#{self.filename}>" end |
#load ⇒ void
This method returns an undefined value.
Loads the code by executing it.
35 36 37 |
# File 'lib/nanoc3/base/source_data/code_snippet.rb', line 35 def load eval(@data, TOPLEVEL_BINDING, @filename) end |
#reference ⇒ Object
Returns an object that can be used for uniquely identifying objects.
42 43 44 |
# File 'lib/nanoc3/base/source_data/code_snippet.rb', line 42 def reference [ :code_snippet, filename ] end |