Class: CSDL::InteractionFilterProcessor
- Defined in:
- lib/csdl/interaction_filter_processor.rb
Overview
InteractionFilterProcessor is a class that inherits from Processor, providing additional methods for building CSDL specifically for Interaction Filters.
Additional DSL methods provide the return statement, curly brace scopes (statement scopes), and VEDO tagging.
Instance Method Summary collapse
-
#on_return(node) ⇒ String
Generate a return statement by processing the child statement_scope node.
-
#on_statement_scope(node) ⇒ String
Wrap child nodes in braces.
-
#on_tag(node) ⇒ String
Process :tag node with it’s child nodes :tag_namespaces (optional), :tag_class, and :statement_scope.
-
#on_tag_class(node) ⇒ String
Process the first child of the :tag_class node.
-
#on_tag_namespace(node) ⇒ String
Process the terminal value of the :tag_namespace node.
-
#on_tag_namespaces(node) ⇒ String
Process the :tag_namespace child nodes of a :tag_namespaces node.
-
#validate_target!(target_key) ⇒ void
Raises an InvalidInteractionTargetError if the target isn’t a valid CSDL target for interaction filters.
Methods inherited from Processor
#on_and, #on_argument, #on_condition, #on_logical_group, #on_not, #on_operator, #on_or, #on_raw, #on_root, #on_string, #on_target
Instance Method Details
#on_return(node) ⇒ String
Generate a return statement by processing the child statement_scope node.
52 53 54 55 56 57 58 59 60 |
# File 'lib/csdl/interaction_filter_processor.rb', line 52 def on_return(node) statement_scope = node.children.compact.find { |child| child.type == :statement_scope } if statement_scope.nil? fail ::CSDL::MissingReturnStatementScopeError, "Invalid CSDL AST: return statment scope is missing" end "return #{process(statement_scope)}" end |
#on_statement_scope(node) ⇒ String
Wrap child nodes in braces. Generally not useful on its own, see #on_return or #on_tag for integrated usage.
76 77 78 |
# File 'lib/csdl/interaction_filter_processor.rb', line 76 def on_statement_scope(node) "{" + process_all(node.children.compact).join(" ") + "}" end |
#on_tag(node) ⇒ String
Process :tag node with it’s child nodes :tag_namespaces (optional), :tag_class, and :statement_scope.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/csdl/interaction_filter_processor.rb', line 109 def on_tag(node) children = node.children.compact tag_namespaces = children.find { |child| child.type == :tag_namespaces } tag_class = children.find { |child| child.type == :tag_class } statement_scope = children.find { |child| child.type == :statement_scope } if tag_class.nil? fail ::CSDL::MissingTagClassError, "Invalid CSDL AST: :tag node must have a :tag_class child node" end if statement_scope.nil? fail ::CSDL::MissingTagStatementScopeError, "Invalid CSDL AST: :tag node must have a :statement_scope child node" end tag_namespace = "tag" unless tag_namespaces.nil? tag_namespace += process(tag_namespaces) end children = [tag_namespace] + process_all([ tag_class, statement_scope ]) children.join(" ") end |
#on_tag_class(node) ⇒ String
Process the first child of the :tag_class node.
140 141 142 |
# File 'lib/csdl/interaction_filter_processor.rb', line 140 def on_tag_class(node) process(node.children.first) end |
#on_tag_namespace(node) ⇒ String
Process the terminal value of the :tag_namespace node.
152 153 154 |
# File 'lib/csdl/interaction_filter_processor.rb', line 152 def on_tag_namespace(node) node.children.first.to_s end |
#on_tag_namespaces(node) ⇒ String
Process the :tag_namespace child nodes of a :tag_namespaces node.
171 172 173 174 175 176 177 178 179 |
# File 'lib/csdl/interaction_filter_processor.rb', line 171 def on_tag_namespaces(node) child_tag_namespaces = node.children.compact.select { |child| child.type == :tag_namespace } if child_tag_namespaces.empty? fail ::CSDL::MissingTagNodesError, "Invalid CSDL AST: A :tag_namespaces node must have at least one :tag_namespace child" end "." + process_all(child_tag_namespaces).join(".") end |
#validate_target!(target_key) ⇒ void
This method returns an undefined value.
Raises an CSDL::InvalidInteractionTargetError if the target isn’t a valid CSDL target for interaction filters. Will be called from the base class when given a :condition node with a :target node.
196 197 198 199 200 |
# File 'lib/csdl/interaction_filter_processor.rb', line 196 def validate_target!(target_key) unless ::CSDL.interaction_target?(target_key) fail ::CSDL::InvalidInteractionTargetError, "Interaction filters cannot use target '#{target_key}'" end end |