Class: Wire::ProjectYamlLoader
- Inherits:
-
Object
- Object
- Wire::ProjectYamlLoader
- Defined in:
- lib/wire/model/loader.rb
Overview
ProjectYamlLoader is able to load a model from yaml files (as written by init command)
Instance Method Summary collapse
-
#load_model_element_file(filename) ⇒ Object
reads filename as yaml, returns elements.
-
#load_project(target_dir) ⇒ Object
loads project model from target_dir.
Instance Method Details
#load_model_element_file(filename) ⇒ Object
reads filename as yaml, returns elements
45 46 47 |
# File 'lib/wire/model/loader.rb', line 45 def load_model_element_file(filename) YAML.load(File.open(filename, 'r')) end |
#load_project(target_dir) ⇒ Object
loads project model from target_dir
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/wire/model/loader.rb', line 13 def load_project(target_dir) # ensure target dir exists, is a dir fail(ArgumentError, 'Nonexisting directory') unless File.exist?(target_dir) && File.directory?(target_dir) # create project project = Project.new(target_dir) # iterate all model element types, load if file exists MODEL_ELEMENTS.each do |model_element| filename = File.join(target_dir, "#{model_element}.yaml") # jump out unless file exists next unless File.exist?(filename) && File.readable?(filename) $log.debug "Loading model file #{filename}" element_data = load_model_element_file(filename) project.merge_element model_element, element_data end # dump some statistics puts(project.calc_stats.reduce([]) do |res, elem| type = elem[0] count = elem[1] res << "#{count} #{type}(s)" end.join(', ')) project end |