lib/glimmer/dsl/engine.rb in glimmer-1.0.7 vs lib/glimmer/dsl/engine.rb in glimmer-1.0.8

- old
+ new

@@ -26,11 +26,11 @@ module Glimmer module DSL # Glimmer DSL Engine # - # Follows Interpreter and Chain of Responsibility Design Patterns + # Follows Interpreter, Chain of Responsibility, and Singleton Design Patterns # # When DSL engine interprets an expression, it attempts to handle # with ordered expression array specified via `.expressions=` method. class Engine MESSAGE_NO_DSLS = "Glimmer has no DSLs configured. Add glimmer-dsl-swt gem or visit https://github.com/AndyObtiva/glimmer#multi-dsl-support for more details.\n" @@ -53,12 +53,12 @@ interpretation else raise Glimmer::Error, "Unsupported keyword: #{keyword}" unless static_expression_dsl || retrieved_static_expression Glimmer::DSL::Engine.dsl_stack.push(static_expression_dsl || Glimmer::DSL::Engine.dsl) static_expression = Glimmer::DSL::Engine.static_expressions[keyword][Glimmer::DSL::Engine.dsl] - if !static_expression.can_interpret?(Glimmer::DSL::Engine.parent, keyword, *args, &block) - raise Error, "Invalid use of Glimmer keyword #{keyword} with args #{args} under parent #{Glimmer::DSL::Engine.parent}" + if static_expression.nil? || !static_expression.can_interpret?(Glimmer::DSL::Engine.parent, keyword, *args, &block) + raise Error, "Invalid use of Glimmer keyword #{keyword} with args #{args} under parent #{Glimmer::DSL::Engine.parent.inspect}" else Glimmer::Config.logger.info {"#{static_expression.class.name} will handle expression keyword #{keyword}"} Glimmer::DSL::Engine.interpret_expression(static_expression, keyword, *args, &block) end end @@ -84,11 +84,11 @@ dsl_name = dsl_name.to_sym disabled_dsls.delete(dsl_name) end def disabled_dsls - @disabled_dsls ||= [] + @disabled_dsls ||= Concurrent::Array.new end def enabled_dsls=(dsl_names) dsls.each {|dsl_name| disable_dsl(dsl_name)} dsl_names.each {|dsl_name| enable_dsl(dsl_name)} @@ -107,16 +107,16 @@ static_expressions.empty? && dynamic_expression_chains_of_responsibility.empty? end # Dynamic expression chains of responsibility indexed by dsl def dynamic_expression_chains_of_responsibility - @dynamic_expression_chains_of_responsibility ||= {} + @dynamic_expression_chains_of_responsibility ||= Concurrent::Hash.new end # Static expressions indexed by keyword and dsl def static_expressions - @static_expressions ||= {} + @static_expressions ||= Concurrent::Hash.new end # Sets dynamic expression chains of responsibility. Useful for internal testing attr_writer :dynamic_expression_chains_of_responsibility @@ -145,11 +145,11 @@ def add_static_expression(static_expression) Glimmer::Config.logger.info {"Adding static expression: #{static_expression.class.name}"} keyword = static_expression.class.keyword static_expression_dsl = static_expression.class.dsl - static_expressions[keyword] ||= {} + static_expressions[keyword] ||= Concurrent::Hash.new static_expressions[keyword][static_expression_dsl] = static_expression Glimmer.send(:define_method, keyword, &STATIC_EXPRESSION_METHOD_FACTORY.call(keyword)) end def expression_class(dsl_namespace, expression_name) @@ -201,19 +201,19 @@ # Parents are maintained in a stack while evaluating Glimmer DSL # to ensure properly ordered interpretation of DSL syntax def_delegator :parent_stack, :last, :parent def parent_stack - parent_stacks[dsl] ||= [] + parent_stacks[dsl] ||= Concurrent::Array.new end def parent_stacks - @parent_stacks ||= {} + @parent_stacks ||= Concurrent::Hash.new end # Enables multiple DSLs to play well with each other when mixing together def dsl_stack - @dsl_stack ||= [] + @dsl_stack ||= Concurrent::Array.new end end end end end