Class: Kontena::StacksCache::CachedStack
- Inherits:
-
Object
- Object
- Kontena::StacksCache::CachedStack
- Defined in:
- lib/kontena/stacks_cache.rb
Instance Attribute Summary collapse
-
#stack ⇒ Object
Returns the value of attribute stack.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #cached? ⇒ Boolean
- #delete ⇒ Object
-
#initialize(stack, version = nil) ⇒ CachedStack
constructor
A new instance of CachedStack.
- #load ⇒ Object
- #path ⇒ Object
- #read ⇒ Object
- #write(content) ⇒ Object
Constructor Details
#initialize(stack, version = nil) ⇒ CachedStack
Returns a new instance of CachedStack.
14 15 16 17 18 19 20 |
# File 'lib/kontena/stacks_cache.rb', line 14 def initialize(stack, version = nil) unless version stack, version = stack.split(':', 2) end @stack = stack @version = version end |
Instance Attribute Details
#stack ⇒ Object
Returns the value of attribute stack.
11 12 13 |
# File 'lib/kontena/stacks_cache.rb', line 11 def stack @stack end |
#version ⇒ Object
Returns the value of attribute version.
12 13 14 |
# File 'lib/kontena/stacks_cache.rb', line 12 def version @version end |
Instance Method Details
#cached? ⇒ Boolean
43 44 45 46 |
# File 'lib/kontena/stacks_cache.rb', line 43 def cached? return false unless version File.exist?(path) end |
#delete ⇒ Object
39 40 41 |
# File 'lib/kontena/stacks_cache.rb', line 39 def delete File.unlink(path) end |
#load ⇒ Object
26 27 28 |
# File 'lib/kontena/stacks_cache.rb', line 26 def load YAML.safe_load(read) end |
#path ⇒ Object
48 49 50 51 52 |
# File 'lib/kontena/stacks_cache.rb', line 48 def path path = File.(File.join(base_path, "#{stack}-#{version}.yml")) raise "Path traversal attempted" unless path.start_with?(base_path) path end |
#read ⇒ Object
22 23 24 |
# File 'lib/kontena/stacks_cache.rb', line 22 def read File.read(path) end |
#write(content) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/kontena/stacks_cache.rb', line 30 def write(content) raise ArgumentError, "Stack name and version required" unless @stack && @version unless File.directory?(File.dirname(path)) require 'fileutils' FileUtils.mkdir_p(File.dirname(path)) end File.write(path, content) end |