Class: Kontena::Cli::Stacks::YAML::FileLoader

Inherits:
StackFileLoader show all
Defined in:
lib/kontena/cli/stacks/yaml/stack_file_loader/file_loader.rb

Instance Attribute Summary

Attributes inherited from StackFileLoader

#parent, #source

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from StackFileLoader

#content, #dependencies, #flat_dependencies, for, inherited, #inspect, loaders, #reader, #stack_name, #to_h, #yaml

Constructor Details

#initialize(*args) ⇒ FileLoader

Returns a new instance of FileLoader.



22
23
24
25
# File 'lib/kontena/cli/stacks/yaml/stack_file_loader/file_loader.rb', line 22

def initialize(*args)
  super
  @source = self.class.with_context(@source, @parent)
end

Class Method Details

.is_file?(parent) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/kontena/cli/stacks/yaml/stack_file_loader/file_loader.rb', line 10

def self.is_file?(parent)
  parent.is_a?(FileLoader)
end

.match?(source, parent = nil) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/kontena/cli/stacks/yaml/stack_file_loader/file_loader.rb', line 6

def self.match?(source, parent = nil)
  ::File.exist?(with_context(source, parent))
end

.with_context(source, parent = nil) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/kontena/cli/stacks/yaml/stack_file_loader/file_loader.rb', line 14

def self.with_context(source, parent = nil)
  if is_file?(parent)
    File.join(File.dirname(parent.source),  source)
  else
    File.absolute_path(source)
  end
end

Instance Method Details

#originObject



31
32
33
# File 'lib/kontena/cli/stacks/yaml/stack_file_loader/file_loader.rb', line 31

def origin
  "file"
end

#read_contentObject



27
28
29
# File 'lib/kontena/cli/stacks/yaml/stack_file_loader/file_loader.rb', line 27

def read_content
  ::File.read(source)
end

#registryObject



35
36
37
# File 'lib/kontena/cli/stacks/yaml/stack_file_loader/file_loader.rb', line 35

def registry
  "file://"
end