Class: MODL::Parser::ClassProcessor
- Inherits:
-
Object
- Object
- MODL::Parser::ClassProcessor
- Defined in:
- lib/modl/parser/class_processor.rb
Overview
This class handles the conversion of objects that refer to classes into instances of those classes. It works recursively since class usage can be nested.
Constant Summary collapse
- MAX_RECURSION_DEPTH =
How deep can the class structure be?
50
Class Method Summary collapse
-
.process(global, obj) ⇒ Object
global is a GlobalParseContext and obj is the extracted Array or Hash from MODL::Parser::Parsed.extract_json.
Class Method Details
.process(global, obj) ⇒ Object
global is a GlobalParseContext and obj is the extracted Array or Hash from MODL::Parser::Parsed.extract_json
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/modl/parser/class_processor.rb', line 33 def self.process(global, obj) # Process each object in the array or just process the object if its a hash. # Any other object is ignored. raise StandardError, 'parameter "global" should be a GlobalParseContext' unless global.is_a?(GlobalParseContext) if obj.is_a? Array root_class = global.classs 'root' unless root_class.nil? raise StandardError, 'root class has no *assign statement.' if root_class.assign.nil? raise StandardError, 'root class *assign statement should be of the form "*assign=[[class_name]]".' if root_class.assign.length > 1 || root_class.assign[0].length > 1 root_class_assign = root_class.assign[0][0] new_obj = {root_class_assign => obj} obj = new_obj end end process_recursive global, obj return obj end |