Method: CORL::Configuration::File#load

Defined in:
lib/CORL/configuration/file.rb

#load(options = {}) ⇒ Object


Configuration loading / saving



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/CORL/configuration/file.rb', line 39

def load(options = {})
  super do |method_config, properties|
    success = true

    myself.status = code.success

    generate_routes = lambda do |config_name, file_properties, parents = []|
      file_properties.each do |name, value|
        keys = [ parents, name ].flatten

        if value.is_a?(Hash) && ! value.empty?
          generate_routes.call(config_name, value, keys)
        else
          router.set(keys, config_name)
        end
      end
    end

    if fetch_project(method_config)
      search.export.each do |config_name, info|
        provider = info[:provider]
        file     = info[:file]

        logger.info("Loading #{provider} translated source configuration from #{file}")

        parser = CORL.translator(method_config, provider)
        raw    = Util::Disk.read(file)

        if parser && raw && ! raw.empty?
          logger.debug("Source configuration file contents: #{raw}")

          begin
            parse_properties = parser.parse(raw)

            generate_routes.call(config_name, parse_properties)
            properties.import(parse_properties)

          rescue => error
            ui_group(file) do
              error(error.message.sub(/^[^\:]+\:\s+/, ''), { :i18n => false })
            end
            myself.status = 255
            success       = false
          end
        end
        CORL.remove_plugin(parser) if parser
      end
    end
    success
  end
end