Sha256: 972374237c4b0c5a63818ee055c7c52f5fa0dcf262da7457237b5ef59581cb2e

Contents?: true

Size: 1.63 KB

Versions: 70

Compression:

Stored size: 1.63 KB

Contents

# encoding: utf-8
# author: Steven Danna
# author: Victoria Jeffrey
require 'inspec/plugin/v1/plugin_types/resource'
require 'inspec/dsl_shared'

module Inspec
  #
  # LibaryEvalContext constructs an instance of an anonymous class
  # that library files will be instance_exec'd against.
  #
  # The anonymous class ensures that `Inspec.resource(1)` will return
  # an anonymouse class that is suitable as the parent class of an
  # inspec resource. The class returned will have the resource
  # registry used by all dsl methods bound to the resource registry
  # passed into the #create constructor.
  #
  #
  class LibraryEvalContext
    def self.create(registry, require_loader)
      c = Class.new do
        extend Inspec::ResourceDSL
        include Inspec::ResourceBehaviors
        define_singleton_method :__resource_registry do
          registry
        end
      end

      c2 = Class.new do
        define_singleton_method :resource do |version|
          Inspec.validate_resource_dsl_version!(version)
          c
        end
      end

      c3 = Class.new do
        include Inspec::DSL::RequireOverride
        def initialize(require_loader)
          @require_loader = require_loader
          @inspec_binding = nil
        end

        def __inspec_binding
          @inspec_binding
        end
      end

      c3.const_set(:Inspec, c2)
      res = c3.new(require_loader)

      # Provide the local binding for this context which is necessary for
      # calls to `require` to create all dependent objects in the correct
      # context.
      res.instance_variable_set('@inspec_binding', res.instance_eval('binding'))
      res
    end
  end
end

Version data entries

70 entries across 70 versions & 2 rubygems

Version Path
inspec-core-3.6.2 lib/inspec/library_eval_context.rb
inspec-3.6.2 lib/inspec/library_eval_context.rb
inspec-core-3.5.0 lib/inspec/library_eval_context.rb
inspec-3.5.0 lib/inspec/library_eval_context.rb
inspec-core-3.4.1 lib/inspec/library_eval_context.rb
inspec-3.4.1 lib/inspec/library_eval_context.rb
inspec-core-3.3.14 lib/inspec/library_eval_context.rb
inspec-3.3.14 lib/inspec/library_eval_context.rb
inspec-core-3.2.6 lib/inspec/library_eval_context.rb
inspec-3.2.6 lib/inspec/library_eval_context.rb
inspec-core-3.1.3 lib/inspec/library_eval_context.rb
inspec-3.1.3 lib/inspec/library_eval_context.rb
inspec-core-3.0.64 lib/inspec/library_eval_context.rb
inspec-3.0.64 lib/inspec/library_eval_context.rb
inspec-core-3.0.61 lib/inspec/library_eval_context.rb
inspec-3.0.61 lib/inspec/library_eval_context.rb
inspec-core-3.0.52 lib/inspec/library_eval_context.rb
inspec-3.0.52 lib/inspec/library_eval_context.rb
inspec-core-3.0.46 lib/inspec/library_eval_context.rb
inspec-3.0.46 lib/inspec/library_eval_context.rb