Sha256: 1fe56dd7d4fada732d201609c71a3171e03482e2235807075cdf0c333e164daa

Contents?: true

Size: 1.05 KB

Versions: 12

Compression:

Stored size: 1.05 KB

Contents

require 'set'

module Datacaster
  module Runtimes
    class ObjectContext < Base
      def initialize(parent, object)
        super(parent)
        @object = object

        @reserved_instance_variables += instance_variables
      end

      def method_missing(m, *args, &block)
        if @object.respond_to?(m)
          @object.public_send(m, *args, &block)
        else
          super
        end
      end

      def respond_to_missing?(m, include_private = false)
        @object.respond_to?(m, include_private) || super
      end

      def after_call!(sender)
        (sender.instance_variables.to_set - sender.reserved_instance_variables).each do |k|
          @object.instance_variable_set(k, sender.instance_variable_get(k))
          sender.remove_instance_variable(k)
        end
        super
      end

      def before_call!(sender)
        super
        (@object.instance_variables.to_set - sender.reserved_instance_variables).each do |k|
          sender.instance_variable_set(k, @object.instance_variable_get(k))
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
datacaster-4.1.0 lib/datacaster/runtimes/object_context.rb
datacaster-4.0.1 lib/datacaster/runtimes/object_context.rb
datacaster-3.3.1 lib/datacaster/runtimes/object_context.rb
datacaster-3.3.0 lib/datacaster/runtimes/object_context.rb
datacaster-3.2.7 lib/datacaster/runtimes/object_context.rb
datacaster-3.2.6 lib/datacaster/runtimes/object_context.rb
datacaster-3.2.5 lib/datacaster/runtimes/object_context.rb
datacaster-3.2.4 lib/datacaster/runtimes/object_context.rb
datacaster-3.2.3 lib/datacaster/runtimes/object_context.rb
datacaster-3.2.2 lib/datacaster/runtimes/object_context.rb
datacaster-3.2.1 lib/datacaster/runtimes/object_context.rb
datacaster-3.2.0 lib/datacaster/runtimes/object_context.rb