Class: PgVerify::CliUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/pg-verify/cli/cli_utils.rb

Class Method Summary collapse

Class Method Details

.load_models(options) ⇒ Object

Raises:



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/pg-verify/cli/cli_utils.rb', line 3

def self.load_models(options)
    dsl_script_file = options[:script]
    json_file       = options[:"json-file"]
    yaml_file       = options[:"yaml-file"]
    default_script_file = Settings.ruby_dsl.default_script_name

    unless dsl_script_file.nil?
        raise NoSuchFileError.new(dsl_script_file) unless File.file?(dsl_script_file)
        return Interpret::PgScript.new.interpret(dsl_script_file)
    end

    unless json_file.nil?
        raise NoSuchFileError.new(json_file) unless File.file?(json_file)
        json_string = File.read(json_file)
        array = JSON.load(json_string)
        array = [ array ] unless array.is_a?(Array)
        return array.map { |hash| Transform::HashTransformation.new.parse_graph(hash) }
    end

    unless yaml_file.nil?
        raise NoSuchFileError.new(yaml_file) unless File.file?(yaml_file)
        array = YAML.load_file(yaml_file)
        array = [ array ] unless array.is_a?(Array)
        return array.map { |hash| Transform::HashTransformation.new.parse_graph(hash) }
    end

    raise NoDefaultFileError.new(default_script_file) unless File.file?(default_script_file)
    return Interpret::PgScript.new.interpret(default_script_file)
end