Module: RBoss::Cli::Mappings
- Included in:
- Invoker
- Defined in:
- lib/rboss/cli/mappings.rb
Class Method Summary collapse
- .load_default_resources ⇒ Object
- .load_resource(file) ⇒ Object
- .load_resources(dir) ⇒ Object
- .resource_mappings ⇒ Object
Class Method Details
.load_default_resources ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/rboss/cli/mappings.rb', line 64 def load_default_resources load_resources File.join(File.dirname(__FILE__), 'mappings/resources') file = File.("~/.rboss/rboss-cli/resources") if File.exist? file load_resources file end @resource_mappings[''] = { :path => '' } end |
.load_resource(file) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rboss/cli/mappings.rb', line 35 def load_resource(file) name = File.basename(file, '.yaml').gsub('_', '-') mapping = YAML::load_file(file).symbolize_keys @resource_mappings[name] = mapping if mapping[:print] mapping[:print].each do |table| if table[:id] new_mapping = mapping.dup new_mapping[:print] = [table] new_mapping[:description] = table[:title] new_mapping[:derived] = true if table[:path] new_mapping[:path] = table[:path].gsub '${PATH}', mapping[:path] table[:path] = new_mapping[:path] end new_key = "#{name}-#{table[:id]}" @resource_mappings[new_key] = new_mapping end end end end |
.load_resources(dir) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/rboss/cli/mappings.rb', line 57 def load_resources(dir) resource_files = Dir.entries(dir).find_all { |f| f.end_with?('.yaml') } resource_files.each do |file| load_resource File.join(dir, file) end end |
.resource_mappings ⇒ Object
29 30 31 32 33 |
# File 'lib/rboss/cli/mappings.rb', line 29 def resource_mappings @resource_mappings ||= {} load_default_resources if @resource_mappings.empty? @resource_mappings end |