Class: Nanoc::Int::CodeSnippet Private

Inherits:
Object
  • Object
show all
Includes:
ContractsSupport
Defined in:
lib/nanoc/base/entities/code_snippet.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Nanoc::Int::CodeSnippet represent a piece of custom code of a Nanoc site.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ContractsSupport

included

Constructor Details

#initialize(data, filename) ⇒ CodeSnippet

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates a new code snippet.

Parameters:

  • data (String)

    The raw source code which will be executed before compilation

  • filename (String)

    The filename corresponding to this code snippet



25
26
27
28
# File 'lib/nanoc/base/entities/code_snippet.rb', line 25

def initialize(data, filename)
  @data     = data
  @filename = filename
end

Instance Attribute Details

#dataString (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

A string containing the actual code in this code snippet.

Returns:



11
12
13
# File 'lib/nanoc/base/entities/code_snippet.rb', line 11

def data
  @data
end

#filenameString (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The filename corresponding to this code snippet.

Returns:



16
17
18
# File 'lib/nanoc/base/entities/code_snippet.rb', line 16

def filename
  @filename
end

Instance Method Details

#inspectObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



46
47
48
# File 'lib/nanoc/base/entities/code_snippet.rb', line 46

def inspect
  "<#{self.class} filename=\"#{filename}\">"
end

#loadvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Loads the code by executing it.



34
35
36
37
# File 'lib/nanoc/base/entities/code_snippet.rb', line 34

def load
  eval(@data, TOPLEVEL_BINDING, @filename)
  nil
end

#referenceObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns an object that can be used for uniquely identifying objects.

Returns:

  • (Object)

    An unique reference to this object



42
43
44
# File 'lib/nanoc/base/entities/code_snippet.rb', line 42

def reference
  [:code_snippet, filename]
end