Sha256: 94002f3921492d9e43d372f34f256ae5d9193fdbe2e56b15e9494faf2354f27f

Contents?: true

Size: 1.18 KB

Versions: 35

Compression:

Stored size: 1.18 KB

Contents

module Nanoc::Int
  # Nanoc::Int::CodeSnippet represent a piece of custom code of a Nanoc site.
  #
  # @api private
  class CodeSnippet
    include Nanoc::Int::ContractsSupport

    # A string containing the actual code in this code snippet.
    #
    # @return [String]
    attr_reader :data

    # The filename corresponding to this code snippet.
    #
    # @return [String]
    attr_reader :filename

    contract String, String => C::Any
    # Creates a new code snippet.
    #
    # @param [String] data The raw source code which will be executed before
    #   compilation
    #
    # @param [String] filename The filename corresponding to this code snippet
    def initialize(data, filename)
      @data     = data
      @filename = filename
    end

    contract C::None => nil
    # Loads the code by executing it.
    #
    # @return [void]
    def load
      eval(@data, TOPLEVEL_BINDING, @filename)
      nil
    end

    # Returns an object that can be used for uniquely identifying objects.
    #
    # @return [Object] An unique reference to this object
    def reference
      [:code_snippet, filename]
    end

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

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
nanoc-4.7.9 lib/nanoc/base/entities/code_snippet.rb
nanoc-4.7.8 lib/nanoc/base/entities/code_snippet.rb
nanoc-4.7.7 lib/nanoc/base/entities/code_snippet.rb
nanoc-4.7.6 lib/nanoc/base/entities/code_snippet.rb
nanoc-4.7.5 lib/nanoc/base/entities/code_snippet.rb
nanoc-4.7.4 lib/nanoc/base/entities/code_snippet.rb
nanoc-4.7.3 lib/nanoc/base/entities/code_snippet.rb
nanoc-4.7.2 lib/nanoc/base/entities/code_snippet.rb
nanoc-4.7.1 lib/nanoc/base/entities/code_snippet.rb
nanoc-4.7.0 lib/nanoc/base/entities/code_snippet.rb
nanoc-4.6.4 lib/nanoc/base/entities/code_snippet.rb
nanoc-4.6.3 lib/nanoc/base/entities/code_snippet.rb
nanoc-4.6.2 lib/nanoc/base/entities/code_snippet.rb
nanoc-4.6.1 lib/nanoc/base/entities/code_snippet.rb
nanoc-4.6.0 lib/nanoc/base/entities/code_snippet.rb
nanoc-4.5.4 lib/nanoc/base/entities/code_snippet.rb
nanoc-4.5.3 lib/nanoc/base/entities/code_snippet.rb
nanoc-4.5.2 lib/nanoc/base/entities/code_snippet.rb
nanoc-4.5.1 lib/nanoc/base/entities/code_snippet.rb
nanoc-4.5.0 lib/nanoc/base/entities/code_snippet.rb