Class: Nanoc::Core::CodeSnippet Private

Inherits:
Object
  • Object
show all
Includes:
ContractsSupport
Defined in:
lib/nanoc/core/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::Core::CodeSnippet represent a piece of custom code of a Nanoc site.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ContractsSupport

enabled?, included, setup_once

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



28
29
30
31
# File 'lib/nanoc/core/code_snippet.rb', line 28

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:



14
15
16
# File 'lib/nanoc/core/code_snippet.rb', line 14

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:



19
20
21
# File 'lib/nanoc/core/code_snippet.rb', line 19

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.



52
53
54
# File 'lib/nanoc/core/code_snippet.rb', line 52

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.



37
38
39
40
41
42
43
# File 'lib/nanoc/core/code_snippet.rb', line 37

def load
  # rubocop:disable Security/Eval
  eval('def self.use_helper(mod); Nanoc::Core::Context.instance_eval { include mod }; end', TOPLEVEL_BINDING)
  eval(@data, TOPLEVEL_BINDING, @filename)
  # rubocop:enable Security/Eval
  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



48
49
50
# File 'lib/nanoc/core/code_snippet.rb', line 48

def reference
  "code_snippet:#{filename}"
end