Class: Adhearsion::PathString

Inherits:
String show all
Defined in:
lib/adhearsion/initializer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from String

===

Constructor Details

#initialize(path) ⇒ PathString

Returns a new instance of PathString.



45
46
47
48
# File 'lib/adhearsion/initializer.rb', line 45

def initialize(path)
  super
  defaults
end

Instance Attribute Details

#component_pathObject

Returns the value of attribute component_path.



43
44
45
# File 'lib/adhearsion/initializer.rb', line 43

def component_path
  @component_path
end

#dialplan_pathObject

Returns the value of attribute dialplan_path.



43
44
45
# File 'lib/adhearsion/initializer.rb', line 43

def dialplan_path
  @dialplan_path
end

#log_pathObject

Returns the value of attribute log_path.



43
44
45
# File 'lib/adhearsion/initializer.rb', line 43

def log_path
  @log_path
end

Class Method Details

.from_application_subdirectory(folder) ⇒ nil, PathString

Will return a PathString for the application root folder to which the specified arbitrarily nested subfolder belongs. It works by traversing parent directories looking for the .ahnrc file. If no .ahnrc is found, nil is returned.

Parameters:

  • folder (String)

    The path to the directory which should be a

Returns:

  • (nil)

    if the subdirectory does not belong to a parent Adhearsion app directory

  • (PathString)

    if a directory is found



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/adhearsion/initializer.rb', line 27

def from_application_subdirectory(folder)
  folder = File.expand_path folder
  ahn_rc = nil
  
  until ahn_rc || folder == "/"
    possible_ahn_rc = File.join(folder, ".ahnrc")
    if File.exists?(possible_ahn_rc)
      ahn_rc = possible_ahn_rc
    else
      folder = File.expand_path(folder + "/..")
    end
  end
  ahn_rc ? new(folder) : nil
end

Instance Method Details

#base_path=(value) ⇒ Object



56
57
58
59
# File 'lib/adhearsion/initializer.rb', line 56

def base_path=(value)
  replace(value)
  defaults
end

#defaultsObject



50
51
52
53
54
# File 'lib/adhearsion/initializer.rb', line 50

def defaults
  @component_path = build_path_for "components"
  @dialplan_path  = dup
  @log_path       = build_path_for "logs"
end

#using_base_path(temporary_base_path, &block) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/adhearsion/initializer.rb', line 61

def using_base_path(temporary_base_path, &block)
  original_path = dup
  self.base_path = temporary_base_path
  block.call
ensure
  self.base_path = original_path
end