Class: Kontena::StacksCache::CachedStack
- Inherits:
-
Object
- Object
- Kontena::StacksCache::CachedStack
- Defined in:
- lib/kontena/stacks_cache.rb
Instance Attribute Summary collapse
-
#stack_name ⇒ Object
readonly
Returns the value of attribute stack_name.
Instance Method Summary collapse
- #cached? ⇒ Boolean
- #delete ⇒ Object
-
#initialize(stack_name) ⇒ CachedStack
constructor
A new instance of CachedStack.
- #load ⇒ Object
- #path ⇒ Object
- #read ⇒ Object
- #write(content) ⇒ Object
Constructor Details
#initialize(stack_name) ⇒ CachedStack
Returns a new instance of CachedStack.
9 10 11 |
# File 'lib/kontena/stacks_cache.rb', line 9 def initialize(stack_name) @stack_name = stack_name end |
Instance Attribute Details
#stack_name ⇒ Object (readonly)
Returns the value of attribute stack_name.
7 8 9 |
# File 'lib/kontena/stacks_cache.rb', line 7 def stack_name @stack_name end |
Instance Method Details
#cached? ⇒ Boolean
34 35 36 37 |
# File 'lib/kontena/stacks_cache.rb', line 34 def cached? return false unless stack_name.version File.exist?(path) end |
#delete ⇒ Object
30 31 32 |
# File 'lib/kontena/stacks_cache.rb', line 30 def delete File.unlink(path) end |
#load ⇒ Object
17 18 19 |
# File 'lib/kontena/stacks_cache.rb', line 17 def load ::YAML.safe_load(read, [], [], true, path) end |
#path ⇒ Object
39 40 41 42 43 |
# File 'lib/kontena/stacks_cache.rb', line 39 def path path = File.(File.join(base_path, "#{stack_name.stack_name}-#{stack_name.version}.yml")) raise "Path traversal attempted" unless path.start_with?(base_path) path end |
#read ⇒ Object
13 14 15 |
# File 'lib/kontena/stacks_cache.rb', line 13 def read File.read(path) end |
#write(content) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/kontena/stacks_cache.rb', line 21 def write(content) raise ArgumentError, "Stack name and version required" unless stack_name.stack_name && stack_name.version unless File.directory?(File.dirname(path)) require 'fileutils' FileUtils.mkdir_p(File.dirname(path)) end File.write(path, content) end |