Class: Qravan::Cargo
- Inherits:
-
Object
- Object
- Qravan::Cargo
- Defined in:
- lib/qravan/cargo.rb
Overview
Load models and sources to cargo
Instance Attribute Summary collapse
-
#connections ⇒ Object
Returns the value of attribute connections.
-
#models ⇒ Object
Returns the value of attribute models.
-
#sources ⇒ Object
Returns the value of attribute sources.
Instance Method Summary collapse
- #concat_models ⇒ Object
- #connect_sources ⇒ Object
-
#initialize ⇒ Cargo
constructor
A new instance of Cargo.
- #list(what = "sources") ⇒ Object
- #preload_models ⇒ Object
- #preload_sources ⇒ Object
Constructor Details
#initialize ⇒ Cargo
Returns a new instance of Cargo.
8 9 10 11 12 13 |
# File 'lib/qravan/cargo.rb', line 8 def initialize Console.logger.info "Cargo initialized:" Console.logger.info "Sources: #{sources.count}" Console.logger.info "Models: #{models.count}" Console.logger.info "Connections: #{connections.count}" end |
Instance Attribute Details
#connections ⇒ Object
Returns the value of attribute connections.
6 7 8 |
# File 'lib/qravan/cargo.rb', line 6 def connections @connections end |
#models ⇒ Object
Returns the value of attribute models.
6 7 8 |
# File 'lib/qravan/cargo.rb', line 6 def models @models end |
#sources ⇒ Object
Returns the value of attribute sources.
6 7 8 |
# File 'lib/qravan/cargo.rb', line 6 def sources @sources end |
Instance Method Details
#concat_models ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/qravan/cargo.rb', line 37 def concat_models model_files = {} (list("models") - %w[models/current models/base]).each do |model| Console.logger.info "Reading model file #{model}/1.0/model.yaml" model_files[model] = File.readlines("#{model}/1.0/model.yaml").map(&:chomp) end File.open("models/current/model.yaml", "w") do |output_file| output_file.puts File.readlines("models/base/1.0/model.yaml").map(&:chomp) model_files.each { |elem| output_file.puts elem[1] } end end |
#connect_sources ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/qravan/cargo.rb', line 61 def connect_sources @connections = {} sources.each do |source| case source[1]["type"] when "rest" @connections[source[0]] = Qravan::Rest.new(source[1]) when "db" @connections[source[0]] = Qravan::Db.new(source[1]) else Console.logger.warn "Not supported resource" end end @connections end |
#list(what = "sources") ⇒ Object
76 77 78 |
# File 'lib/qravan/cargo.rb', line 76 def list(what = "sources") Dir["#{what}/*"] end |
#preload_models ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/qravan/cargo.rb', line 50 def preload_models concat_models @models = {} Console.logger.info "Preparing models" preloaded_models = YAML.load_file("models/current/model.yaml") preloaded_models["resources"].each do |model| @models[model.keys.first] = model end @models end |
#preload_sources ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/qravan/cargo.rb', line 27 def preload_sources @sources = {} list("sources").each do |source| Console.logger.info "Reading source #{source}" preloaded_source = YAML.load_file("#{source}/1.0/source.yaml") @sources[preloaded_source.keys.first] = preloaded_source.first.last end @sources end |