module AplContextBuilder
Constants
- ALL_ENTITY_TYPES_CURRENT_LEVEL
Used as a place holder for contexts where validations are applicable for all types at parent level For instance if a validation is applicable for some item irrespective of which invoice it belongs to, we can use all in the context before specifying item type e.g. create_all_tax_item for tax_item validations irrespective of the invoice belongs to
- UNDERSCORE
Public Instance Methods
get_contexts(action, context_hierarchy, return_leaf_node_only = false)
click to toggle source
if leaf_node is not nil, return only leaf node i.e. the context containg all the elements in context_hierarchy
# File lib/apl-library/apl_context_builder.rb, line 15 def get_contexts(action, context_hierarchy, return_leaf_node_only = false) contexts = Array.new context = action + UNDERSCORE context_changer = 0 loop_run = 0 begin context_hierarchy.each do |context_node| if(context_changer > 0) index = context_hierarchy.index(context_node) context_node = ALL_ENTITY_TYPES_CURRENT_LEVEL context_hierarchy[index] = context_node context_changer -= 1 end if context_hierarchy.index(context_node) != (context_hierarchy.size - 1) context += context_node + UNDERSCORE else context += context_node end end loop_run += 1 context_changer = loop_run contexts << context context = action + UNDERSCORE end while loop_run < context_hierarchy.size if contexts.empty? return (!return_leaf_node_only) ? [] : nil else return (!return_leaf_node_only) ? contexts : contexts[0] end end