Sha256: 66a5f3422027389acd75a7bf562f120c2e4088f5df9104aeb223f3879d304c90

Contents?: true

Size: 917 Bytes

Versions: 6

Compression:

Stored size: 917 Bytes

Contents

require 'ostruct'

module Datacaster
  module Runtimes
    class UserContext < Base
      class ContextStruct
        def initialize(context, node)
          @context = context
          @node = node
        end

        def method_missing(m, *args)
          if !args.empty? || block_given?
            return super
          end

          if @context.key?(m)
            return @context[m]
          end

          begin
            @node.class.send_to_parent(@node, :context).public_send(m)
          rescue NoMethodError
            raise NoMethodError.new("Key #{m.inspect} is not found in the context")
          end
        end
      end

      def initialize(parent, user_context)
        super(parent)
        @context_struct = ContextStruct.new(user_context, self)

        @reserved_instance_variables += instance_variables
      end

      def context
        @context_struct
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
datacaster-3.2.5 lib/datacaster/runtimes/user_context.rb
datacaster-3.2.4 lib/datacaster/runtimes/user_context.rb
datacaster-3.2.3 lib/datacaster/runtimes/user_context.rb
datacaster-3.2.2 lib/datacaster/runtimes/user_context.rb
datacaster-3.2.1 lib/datacaster/runtimes/user_context.rb
datacaster-3.2.0 lib/datacaster/runtimes/user_context.rb