Class: Xapixctl::SyncCli::ResourcePath
- Inherits:
-
Object
- Object
- Xapixctl::SyncCli::ResourcePath
- Defined in:
- lib/xapixctl/sync_cli.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(shell, path) ⇒ ResourcePath
constructor
A new instance of ResourcePath.
- #load_resource(res_name, &block) ⇒ Object
- #load_resources(&block) ⇒ Object
- #remove_outdated_resources ⇒ Object
- #write_file(content, filename) ⇒ Object
- #write_resource_yaml(res_details, res_name) ⇒ Object
Constructor Details
#initialize(shell, path) ⇒ ResourcePath
Returns a new instance of ResourcePath.
162 163 164 165 166 |
# File 'lib/xapixctl/sync_cli.rb', line 162 def initialize(shell, path) @shell = shell @path = path @resource_files = [] end |
Instance Method Details
#load_resource(res_name, &block) ⇒ Object
190 191 192 |
# File 'lib/xapixctl/sync_cli.rb', line 190 def load_resource(res_name, &block) Util.resources_from_file(@path.join("#{res_name}.yaml"), ignore_missing: false, &block) end |
#load_resources(&block) ⇒ Object
186 187 188 |
# File 'lib/xapixctl/sync_cli.rb', line 186 def load_resources(&block) Util.resources_from_file(@path, ignore_missing: true, &block) end |
#remove_outdated_resources ⇒ Object
194 195 196 197 198 199 |
# File 'lib/xapixctl/sync_cli.rb', line 194 def remove_outdated_resources (@path.glob('*.yaml') - @resource_files).each do |outdated_file| outdated_file.delete say "removed #{outdated_file}" end end |
#write_file(content, filename) ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/xapixctl/sync_cli.rb', line 168 def write_file(content, filename) @path.mkpath unless @path.directory? && @path.writable? warn "Cannot write to #{@path}, please check directory exists and is writable" exit 1 end file = @path.join(filename) file.write(content) say "updated #{file}..." file end |
#write_resource_yaml(res_details, res_name) ⇒ Object
180 181 182 183 184 |
# File 'lib/xapixctl/sync_cli.rb', line 180 def write_resource_yaml(res_details, res_name) file = write_file(res_details.to_yaml, "#{res_name}.yaml") @resource_files << file file end |