Class: ArcWeld::Cli::Project
- Inherits:
-
Object
- Object
- ArcWeld::Cli::Project
- Includes:
- Helpers
- Defined in:
- lib/arc_weld/cli/project.rb
Instance Attribute Summary collapse
-
#base_model ⇒ Object
Returns the value of attribute base_model.
-
#input_dir ⇒ Object
Returns the value of attribute input_dir.
-
#name ⇒ Object
Returns the value of attribute name.
-
#output_dir ⇒ Object
Returns the value of attribute output_dir.
-
#relationships ⇒ Object
Returns the value of attribute relationships.
-
#resource_driver ⇒ Object
Returns the value of attribute resource_driver.
-
#resource_inputs ⇒ Object
Returns the value of attribute resource_inputs.
-
#resource_root ⇒ Object
Returns the value of attribute resource_root.
Instance Method Summary collapse
- #archive ⇒ Object
- #archive_resources(resource_type) ⇒ Object
- #assign_model_relations ⇒ Object
- #assign_resource_groups ⇒ Object
- #generate_archive ⇒ Object
-
#initialize(config) ⇒ Project
constructor
A new instance of Project.
- #load_resources ⇒ Object
- #reader ⇒ Object
- #resource_class_for(resource_type) ⇒ Object
- #resource_group(type) ⇒ Object
- #resource_input_path(resource_type) ⇒ Object
- #resource_reader(resource_type) ⇒ Object
- #resource_roots ⇒ Object
- #resources ⇒ Object
- #zone_assets ⇒ Object
Methods included from Helpers
Constructor Details
#initialize(config) ⇒ Project
Returns a new instance of Project.
8 9 10 11 |
# File 'lib/arc_weld/cli/project.rb', line 8 def initialize(config) config.each {|k,v| self.send(format('%s=',k),v)} self end |
Instance Attribute Details
#base_model ⇒ Object
Returns the value of attribute base_model.
5 6 7 |
# File 'lib/arc_weld/cli/project.rb', line 5 def base_model @base_model end |
#input_dir ⇒ Object
Returns the value of attribute input_dir.
5 6 7 |
# File 'lib/arc_weld/cli/project.rb', line 5 def input_dir @input_dir end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/arc_weld/cli/project.rb', line 5 def name @name end |
#output_dir ⇒ Object
Returns the value of attribute output_dir.
5 6 7 |
# File 'lib/arc_weld/cli/project.rb', line 5 def output_dir @output_dir end |
#relationships ⇒ Object
Returns the value of attribute relationships.
5 6 7 |
# File 'lib/arc_weld/cli/project.rb', line 5 def relationships @relationships end |
#resource_driver ⇒ Object
Returns the value of attribute resource_driver.
5 6 7 |
# File 'lib/arc_weld/cli/project.rb', line 5 def resource_driver @resource_driver end |
#resource_inputs ⇒ Object
Returns the value of attribute resource_inputs.
5 6 7 |
# File 'lib/arc_weld/cli/project.rb', line 5 def resource_inputs @resource_inputs end |
#resource_root ⇒ Object
Returns the value of attribute resource_root.
5 6 7 |
# File 'lib/arc_weld/cli/project.rb', line 5 def resource_root @resource_root end |
Instance Method Details
#archive ⇒ Object
41 42 43 |
# File 'lib/arc_weld/cli/project.rb', line 41 def archive @archive ||= Archive.new end |
#archive_resources(resource_type) ⇒ Object
37 38 39 |
# File 'lib/arc_weld/cli/project.rb', line 37 def archive_resources(resource_type) archive.resources.select {|r| r.resource_type == constantize(resource_type)} end |
#assign_model_relations ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/arc_weld/cli/project.rb', line 81 def assign_model_relations relationships.each do |rel| klass = ArcWeld::Cli::RelationReaders.const_get(constantize(rel['driver'])) rel_reader = klass.new( path: File.join(input_dir,rel['file']), relationship_type: rel['type'] ) rel_reader.relate(resources) end end |
#assign_resource_groups ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/arc_weld/cli/project.rb', line 93 def assign_resource_groups resource_roots['zone'].add_children(*resources['zone']) zone_assets unzoned = resources['asset'].select {|a| a.in_zone.nil?} resource_roots['asset'].add_children(*unzoned) %w{ network customer location asset_category }.each do |type| resource_roots[type].add_children(*resources[type]) end end |
#generate_archive ⇒ Object
106 107 108 109 110 111 112 113 |
# File 'lib/arc_weld/cli/project.rb', line 106 def generate_archive resource_roots load_resources assign_resource_groups assign_model_relations archive.add(*resources.values.flatten) archive end |
#load_resources ⇒ Object
45 46 47 48 49 50 |
# File 'lib/arc_weld/cli/project.rb', line 45 def load_resources reader.each do |type, type_reader| res=type_reader.to_a resources[type].push(*res) end end |
#reader ⇒ Object
27 28 29 30 31 |
# File 'lib/arc_weld/cli/project.rb', line 27 def reader @readers ||= Hash[ resource_inputs.keys.map { |type| [type, resource_reader(type)]} ] end |
#resource_class_for(resource_type) ⇒ Object
13 14 15 |
# File 'lib/arc_weld/cli/project.rb', line 13 def resource_class_for(resource_type) ArcWeld.const_get(constantize(resource_type)) end |
#resource_group(type) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/arc_weld/cli/project.rb', line 52 def resource_group(type) klass = ArcWeld.const_get(constantize(type)) group_name = resource_root[type] ArcWeld::Group.new( name: group_name, externalID: format('weld_%s_root', type), description: format('ArcWeld root %s group', constantize(type)), containedResourceType: klass.class_id, parent_ref: klass.toplevel ) end |
#resource_input_path(resource_type) ⇒ Object
17 18 19 |
# File 'lib/arc_weld/cli/project.rb', line 17 def resource_input_path(resource_type) File.join(self.input_dir, resource_inputs.fetch(resource_type)) end |
#resource_reader(resource_type) ⇒ Object
21 22 23 24 25 |
# File 'lib/arc_weld/cli/project.rb', line 21 def resource_reader(resource_type) klass = ArcWeld::Cli::ResourceReaders.const_get(constantize(resource_driver)) klass.new( path: resource_input_path(resource_type), target_class: resource_class_for(resource_type) ) end |
#resource_roots ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/arc_weld/cli/project.rb', line 65 def resource_roots @roots ||= Hash[ resource_root.map do |type, group_name| grp = resource_group(type) resources['group'].push(grp) [type, grp ] end ] end |
#resources ⇒ Object
33 34 35 |
# File 'lib/arc_weld/cli/project.rb', line 33 def resources @resources ||= Hash.new {|h,k| h[k]=Array.new } end |
#zone_assets ⇒ Object
75 76 77 78 79 |
# File 'lib/arc_weld/cli/project.rb', line 75 def zone_assets resources['asset'].each do |asset| asset.auto_zone(*resources['zone']) end end |