lib/trailblazer/context/indifferent_access.rb in trailblazer-context-0.1.4 vs lib/trailblazer/context/indifferent_access.rb in trailblazer-context-0.2.0

- old
+ new

@@ -1,18 +1,35 @@ +require "trailblazer/context/aliasing" + module Trailblazer class Context class IndifferentAccess < Context - 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] + 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