class DtkCommon::DSL::FileParser
Public Class Methods
generate_hash(file_type,output_array,opts={})
click to toggle source
# File lib/dsl/file_parser.rb, line 102 def self.generate_hash(file_type,output_array,opts={}) file_parser = Loader.file_parser(file_type,opts[:version]) file_parser.generate_hash(output_array) end
implements_method?(method_name)
click to toggle source
# File lib/dsl/file_parser.rb, line 78 def self.implements_method?(method_name) [:parse_content,:generate_hash].include?(method_name) end
new(input_hash_class)
click to toggle source
# File lib/dsl/file_parser.rb, line 74 def initialize(input_hash_class) @input_hash_class = input_hash_class end
parse_content(file_type,file_content,opts={})
click to toggle source
# File lib/dsl/file_parser.rb, line 82 def self.parse_content(file_type,file_content,opts={}) ret = OutputArray.new # if there is no content (nil) return empty array as if content was empty return ret unless file_content file_parser = Loader.file_parser(file_type,opts[:version]) # raw_hash_content = convert_json_content_to_hash(file_content,opts) #TODO: for Rich # we need to implement dsl v3 parser, this is just temp fix for autoimport # just changed parser to yaml instead of json because new modules/services # are in yaml format now raw_hash_content = convert_yaml_content_to_hash(file_content,opts) return raw_hash_content if raw_hash_content.is_a?(ErrorUsage::DSLParsing::JSONParsing) file_parser.parse_hash_content_aux(raw_hash_content) end
Private Class Methods
convert_json_content_to_hash(json_file_content, opts={})
click to toggle source
# File lib/dsl/file_parser.rb, line 195 def self.convert_json_content_to_hash(json_file_content, opts={}) ret = Hash.new if json_file_content.empty? return ret end begin ::JSON.parse(json_file_content) rescue ::JSON::ParserError => e # raise ErrorUsage::JSONParse.new(e.to_s) return ErrorUsage::DSLParsing::JSONParsing.new("JSON parsing error #{e.to_s} in file", opts[:file_path]) if opts[:do_not_raise] raise ErrorUsage::DSLParsing::JSONParsing.new("JSON parsing error #{e.to_s} in file", opts[:file_path]) end end
convert_yaml_content_to_hash(content, opts={})
click to toggle source
# File lib/dsl/file_parser.rb, line 183 def self.convert_yaml_content_to_hash(content, opts={}) ret = Hash.new return ret if content.empty? begin YAML.load(content) rescue Exception => e return ErrorUsage::DSLParsing::JSONParsing.new("YAML parsing error #{e.to_s} in file", opts[:file_path]) if opts[:do_not_raise] raise ErrorUsage::DSLParsing::JSONParsing.new("YAML parsing error #{e.to_s} in file", opts[:file_path]) end end
Public Instance Methods
parse_hash_content_aux(raw_hash)
click to toggle source
# File lib/dsl/file_parser.rb, line 98 def parse_hash_content_aux(raw_hash) parse_hash_content(input_form(raw_hash)) end
Private Instance Methods
input_form(raw_hash)
click to toggle source
# File lib/dsl/file_parser.rb, line 179 def input_form(raw_hash) @input_hash_class.new(raw_hash) end