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.
- #input_file(filename) ⇒ Object
- #load_resources ⇒ Object
- #reader ⇒ Object
- #resource_class_for(resource_type) ⇒ Object
- #resource_group(type) ⇒ Object
- #resource_reader(resource_type, filename) ⇒ 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
44 45 46 |
# File 'lib/arc_weld/cli/project.rb', line 44 def archive @archive ||= Archive.new end |
#archive_resources(resource_type) ⇒ Object
40 41 42 |
# File 'lib/arc_weld/cli/project.rb', line 40 def archive_resources(resource_type) archive.resources.select {|r| r.resource_type == constantize(resource_type)} end |
#assign_model_relations ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/arc_weld/cli/project.rb', line 84 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
96 97 98 99 100 101 102 103 104 |
# File 'lib/arc_weld/cli/project.rb', line 96 def assign_resource_groups unzoned = resources['asset'].select {|a| a.in_zone.nil?} resource_roots['asset'].add_children(*unzoned) %w{ network customer location asset_category zone }.each do |type| unrooted = resources[type].select {|instance| instance.parent_ref==instance.class.toplevel } resource_roots[type].add_children(*unrooted) end end |
#generate_archive ⇒ Object
106 107 108 109 110 111 112 113 114 |
# File 'lib/arc_weld/cli/project.rb', line 106 def generate_archive resource_roots load_resources zone_assets assign_resource_groups assign_model_relations archive.add(*resources.values.flatten) archive end |
#input_file(filename) ⇒ Object
17 18 19 |
# File 'lib/arc_weld/cli/project.rb', line 17 def input_file(filename) File.join(self.input_dir, filename) end |
#load_resources ⇒ Object
48 49 50 51 52 53 |
# File 'lib/arc_weld/cli/project.rb', line 48 def load_resources reader.each do |type, type_readers| res=type_readers.flat_map &:to_a resources[type].push(*res) end end |
#reader ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/arc_weld/cli/project.rb', line 27 def reader @readers ||= Hash[ resource_inputs.map do |resource_type,*filenames| resource_type_readers = filenames.flatten.map {|filename| resource_reader(resource_type,filename)} [resource_type, resource_type_readers] end ] 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
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/arc_weld/cli/project.rb', line 55 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_reader(resource_type, filename) ⇒ Object
21 22 23 24 25 |
# File 'lib/arc_weld/cli/project.rb', line 21 def resource_reader(resource_type,filename) klass = ArcWeld::Cli::ResourceReaders.const_get(constantize(resource_driver)) klass.new( path: input_file(filename), target_class: resource_class_for(resource_type) ) end |
#resource_roots ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/arc_weld/cli/project.rb', line 68 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
36 37 38 |
# File 'lib/arc_weld/cli/project.rb', line 36 def resources @resources ||= Hash.new {|h,k| h[k]=Array.new } end |
#zone_assets ⇒ Object
78 79 80 81 82 |
# File 'lib/arc_weld/cli/project.rb', line 78 def zone_assets resources['asset'].each do |asset| asset.auto_zone(*resources['zone']) end end |