Class: StackedConfig::Layers::ProjectLayer

Inherits:
SuperStack::Layer
  • Object
show all
Defined in:
lib/stacked_config/layers/project_layer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_or_directory, project_file_basename = nil) ⇒ ProjectLayer

Returns a new instance of ProjectLayer.


8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/stacked_config/layers/project_layer.rb', line 8

def initialize(file_or_directory, project_file_basename=nil)
  if Dir.exists? file_or_directory
    raise 'You have to provide the basename of the project file !' if project_file_basename.nil?
    @started_from_directory = File.expand_path file_or_directory
    self.project_file_basename = project_file_basename
  else
    raise "Invalid project file '#{file_or_directory}' !" unless File.readable? file_or_directory
    normalized = File.expand_path file_or_directory
    @started_from_directory = File.dirname normalized
    self.project_file_basename = File.basename normalized
  end
end

Instance Attribute Details

#project_file_basenameObject

Returns the value of attribute project_file_basename


6
7
8
# File 'lib/stacked_config/layers/project_layer.rb', line 6

def project_file_basename
  @project_file_basename
end

#started_from_directoryObject (readonly)

Returns the value of attribute started_from_directory


6
7
8
# File 'lib/stacked_config/layers/project_layer.rb', line 6

def started_from_directory
  @started_from_directory
end

Instance Method Details

#file_nameObject


21
22
23
# File 'lib/stacked_config/layers/project_layer.rb', line 21

def file_name
  @file_name ||= find_root_file project_file_basename, started_from_directory
end

#project_rootObject


25
26
27
# File 'lib/stacked_config/layers/project_layer.rb', line 25

def project_root
  File.dirname file_name
end