Class: SystemDescriptionStore
Overview
The responsibility of the SystemDescriptionStore class is to handle the directory where the system description is stored. It provides methods to create, delete, and copy descriptions within the top-level directory.
System descriptions are represented by sub directories of this top-level directory. They are handled by the SystemDescription class.
Instance Attribute Summary collapse
-
#base_path ⇒ Object
readonly
Returns the value of attribute base_path.
Instance Method Summary collapse
- #backup(description_name) ⇒ Object
- #copy(from, to) ⇒ Object
- #default_path ⇒ Object
- #description_path(name) ⇒ Object
- #directory_for(name) ⇒ Object
- #html_path(name) ⇒ Object
-
#initialize(base_path = default_path) ⇒ SystemDescriptionStore
constructor
A new instance of SystemDescriptionStore.
- #list ⇒ Object
- #manifest_path(name) ⇒ Object
- #move(from, to) ⇒ Object
- #persistent? ⇒ Boolean
- #remove(name) ⇒ Object
- #rename(from, to) ⇒ Object
- #swap(description_name_1, description_name_2) ⇒ Object
Constructor Details
#initialize(base_path = default_path) ⇒ SystemDescriptionStore
Returns a new instance of SystemDescriptionStore.
35 36 37 38 |
# File 'lib/system_description_store.rb', line 35 def initialize(base_path = default_path) @base_path = base_path create_dir(@base_path) end |
Instance Attribute Details
#base_path ⇒ Object (readonly)
Returns the value of attribute base_path.
25 26 27 |
# File 'lib/system_description_store.rb', line 25 def base_path @base_path end |
Instance Method Details
#backup(description_name) ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/system_description_store.rb', line 87 def backup(description_name) SystemDescription.validate_name(description_name) validate_existence_of_description(description_name) backup_name = get_backup_name(description_name) FileUtils.cp_r(description_path(description_name), description_path(backup_name)) backup_name end |
#copy(from, to) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/system_description_store.rb', line 67 def copy(from, to) SystemDescription.validate_name(from) SystemDescription.validate_name(to) validate_existence_of_description(from) validate_nonexistence_of_description(to) FileUtils.cp_r(description_path(from), description_path(to)) end |
#default_path ⇒ Object
27 28 29 |
# File 'lib/system_description_store.rb', line 27 def default_path Machinery::DEFAULT_CONFIG_DIR end |
#description_path(name) ⇒ Object
40 41 42 |
# File 'lib/system_description_store.rb', line 40 def description_path(name) File.join(@base_path, name) end |
#directory_for(name) ⇒ Object
118 119 120 121 122 |
# File 'lib/system_description_store.rb', line 118 def directory_for(name) dir = description_path(name) create_dir(dir) dir end |
#html_path(name) ⇒ Object
48 49 50 |
# File 'lib/system_description_store.rb', line 48 def html_path(name) File.join(description_path(name), "index.html") end |
#list ⇒ Object
52 53 54 55 56 |
# File 'lib/system_description_store.rb', line 52 def list Dir["#{@base_path}/*"]. select { |item| File.exists?(manifest_path(File.basename(item)))}. map { |item| File.basename(item) }.sort end |
#manifest_path(name) ⇒ Object
44 45 46 |
# File 'lib/system_description_store.rb', line 44 def manifest_path(name) File.join(description_path(name), "manifest.json") end |
#move(from, to) ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/system_description_store.rb', line 77 def move(from, to) SystemDescription.validate_name(from) SystemDescription.validate_name(to) validate_existence_of_description(from) validate_nonexistence_of_description(to) FileUtils.mv(description_path(from), description_path(to)) end |
#persistent? ⇒ Boolean
31 32 33 |
# File 'lib/system_description_store.rb', line 31 def persistent? true end |
#remove(name) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/system_description_store.rb', line 58 def remove(name) unless name.empty? SystemDescription.validate_name(name) FileUtils.rm_rf(description_path(name)) else raise "The system description has no name specified and thus can't be deleted." end end |
#rename(from, to) ⇒ Object
97 98 99 100 101 102 103 104 105 |
# File 'lib/system_description_store.rb', line 97 def rename(from, to) SystemDescription.validate_name(from) SystemDescription.validate_name(to) validate_existence_of_description(from) validate_nonexistence_of_description(to) FileUtils.mv(description_path(from), description_path(to)) end |
#swap(description_name_1, description_name_2) ⇒ Object
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/system_description_store.rb', line 107 def swap(description_name_1, description_name_2) validate_existence_of_description(description_name_1) validate_existence_of_description(description_name_2) tmp_description_name = "#{description_name_1}-#{Time.now.to_i}-#{rand(1000)}" FileUtils.mv(description_path(description_name_1), description_path(tmp_description_name)) FileUtils.mv(description_path(description_name_2), description_path(description_name_1)) FileUtils.mv(description_path(tmp_description_name), description_path(description_name_2)) end |