lib/datacaster/runtimes/user_context.rb in datacaster-4.0.1 vs lib/datacaster/runtimes/user_context.rb in datacaster-4.1.0
- old
+ new
@@ -2,24 +2,25 @@
module Datacaster
module Runtimes
class UserContext < Base
class ContextStruct
+ def self.context_has_key?(context, key)
+ context.respond_to?(:key?) && context.key?(key) || context.to_h.key?(key.to_sym)
+ end
+
def initialize(context, node)
@context = context
@node = node
end
def method_missing(m, *args)
if args.length > 1 || block_given?
return super
end
- key_present = @context.respond_to?(:key?) && @context.key?(m) ||
- @context.to_h.key?(m.to_sym)
-
- if key_present && args.empty?
+ if self.class.context_has_key?(@context, m) && args.empty?
return @context[m]
end
if m =~ /\A.+=\z/ && args.length == 1
return @context[m[0..-2].to_sym] = args[0]
@@ -28,9 +29,15 @@
begin
@node.class.send_to_parent(@node, :context).public_send(m, *args)
rescue NoMethodError
raise NoMethodError.new("Key #{m.inspect} is not found in the context")
end
+ end
+
+ def has_key?(key)
+ self.class.context_has_key?(@context, key) || @node.class.send_to_parent(@node, :context).has_key?(key)
+ rescue NoMethodError
+ false
end
end
def initialize(parent, user_context)
super(parent)