Class: Nanoc::Core::CodeSnippet Private
- Inherits:
-
Object
- Object
- Nanoc::Core::CodeSnippet
- 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
-
#data ⇒ String
readonly
private
A string containing the actual code in this code snippet.
-
#filename ⇒ String
readonly
private
The filename corresponding to this code snippet.
Instance Method Summary collapse
-
#initialize(data, filename) ⇒ CodeSnippet
constructor
private
Creates a new code snippet.
- #inspect ⇒ Object private
-
#load ⇒ void
private
Loads the code by executing it.
-
#reference ⇒ Object
private
Returns an object that can be used for uniquely identifying objects.
Methods included from ContractsSupport
enabled?, included, setup_once, warn_about_performance
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.
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
#data ⇒ String (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.
14 15 16 |
# File 'lib/nanoc/core/code_snippet.rb', line 14 def data @data end |
#filename ⇒ String (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.
19 20 21 |
# File 'lib/nanoc/core/code_snippet.rb', line 19 def filename @filename end |
Instance Method Details
#inspect ⇒ Object
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.
58 59 60 |
# File 'lib/nanoc/core/code_snippet.rb', line 58 def inspect "<#{self.class} filename=\"#{filename}\">" end |
#load ⇒ void
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 44 45 46 47 48 49 |
# File 'lib/nanoc/core/code_snippet.rb', line 37 def load # rubocop:disable Security/Eval eval(<<~CODE, TOPLEVEL_BINDING) unless respond_to?(:use_helper) def self.use_helper(mod) Nanoc::Core::Context.instance_eval { include mod } end end CODE eval(@data, TOPLEVEL_BINDING, @filename) # rubocop:enable Security/Eval nil end |
#reference ⇒ Object
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.
54 55 56 |
# File 'lib/nanoc/core/code_snippet.rb', line 54 def reference "code_snippet:#{filename}" end |