Sha256: fba2de6fd5f8f121f87400661c98aa55b07adc64b9b135829dfe12209c587ba7

Contents?: true

Size: 603 Bytes

Versions: 7

Compression:

Stored size: 603 Bytes

Contents

module Stamina
  class Engine
    class Context
      include Enumerable

      attr_reader :vars, :binding

      def initialize(vars, binding)
        @vars = vars.collect{|v| v.to_sym}
        @binding = binding
      end

      def each
        vars.each do |key|
          yield(key, self[key])
        end
      end

      def [](name)
        binding.eval(name.to_s)
      end

      def to_h
        Hash[collect{|k,v| [k,v]}]
      end

      def to_s
        collect{|k,v|
          "#{k}: #{v}"
        }.join("\n")
      end

    end # class Context
  end # class Engine
end # module Stamina

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
stamina-core-0.6.1 lib/stamina-core/stamina/engine/context.rb
stamina-core-0.6.0 lib/stamina-core/stamina/engine/context.rb
stamina-core-0.5.4 lib/stamina-core/stamina/engine/context.rb
stamina-core-0.5.3 lib/stamina-core/stamina/engine/context.rb
stamina-core-0.5.2 lib/stamina-core/stamina/engine/context.rb
stamina-core-0.5.1 lib/stamina-core/stamina/engine/context.rb
stamina-core-0.5.0 lib/stamina-core/stamina/engine/context.rb