Sha256: 2da60b79a6a541f102d3993622196ec48ad3daf4714650ea3286e99433571306

Contents?: true

Size: 710 Bytes

Versions: 10

Compression:

Stored size: 710 Bytes

Contents

# frozen_string_literal: true

module Coactive
  module Contextualizer
    extend ActiveSupport::Concern

    def contextualize
      self.class._contexts.each do |var|
        instance_variable_set("@#{var.name}", @context[var.name])
        define_singleton_method var.name do
          instance_variable_get("@#{var.name}")
        end
      end

      return_value = yield if block_given?

      self.class._contexts.each do |var|
        if var.output_return?
          @context[var.name] = return_value
        elsif var.output? && instance_variable_defined?("@#{var.name}")
          @context[var.name] = instance_variable_get("@#{var.name}")
        end
      end

      return_value
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
coactive-0.6.0 lib/coactive/contextualizer.rb
coactive-0.5.2 lib/coactive/contextualizer.rb
coactive-0.5.1 lib/coactive/contextualizer.rb
coactive-0.5.0 lib/coactive/contextualizer.rb
coactive-0.4.1 lib/coactive/contextualizer.rb
coactive-0.4.0 lib/coactive/contextualizer.rb
coactive-0.3.0 lib/coactive/contextualizer.rb
coactive-0.2.2 lib/coactive/contextualizer.rb
coactive-0.2.1 lib/coactive/contextualizer.rb
coactive-0.2.0 lib/coactive/contextualizer.rb