Sha256: de885fb583c3a5bef1079473c2d78a9687c8c4341f8c0515f68580c328a39015

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

require "trailblazer/context/aliasing"

module Trailblazer
  class Context
    class IndifferentAccess < Context
      module InstanceMethods
        def [](name)
          # TODO: well...
          @mutable_options.key?(name.to_sym) and return @mutable_options[name.to_sym]
          @mutable_options.key?(name.to_s) and return @mutable_options[name.to_s]
          @wrapped_options.key?(name.to_sym) and return @wrapped_options[name.to_sym]
          @wrapped_options[name.to_s]
        end

        def self.build(wrapped_options, mutable_options, (ctx, flow_options), circuit_options)
          new(wrapped_options, mutable_options, flow_options)
        end
      end
      include InstanceMethods

      def key?(name)
        super(name.to_sym) || super(name.to_s)
      end

      include Aliasing # FIXME

      # This also builds IndifferentAccess::Aliasing.
      # The {#build} method is designed to take all args from {for_circuit} and then
      # translate that to the constructor.
      def self.build(wrapped_options, mutable_options, (ctx, flow_options), circuit_options)
        new(wrapped_options, mutable_options, **flow_options)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
trailblazer-context-0.2.0 lib/trailblazer/context/indifferent_access.rb