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

===, #nameify, #nameify!, random, random_char, #unindent, #unindent!

Constructor Details

#initialize(path) ⇒ PathString

Returns a new instance of PathString.



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

def initialize(path)
  super
  defaults
end

Instance Attribute Details

#component_pathObject

Returns the value of attribute component_path.



53
54
55
# File 'lib/adhearsion/initializer.rb', line 53

def component_path
  @component_path
end

#dialplan_pathObject

Returns the value of attribute dialplan_path.



53
54
55
# File 'lib/adhearsion/initializer.rb', line 53

def dialplan_path
  @dialplan_path
end

#log_pathObject

Returns the value of attribute log_path.



53
54
55
# File 'lib/adhearsion/initializer.rb', line 53

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



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/adhearsion/initializer.rb', line 37

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



66
67
68
69
# File 'lib/adhearsion/initializer.rb', line 66

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

#defaultsObject



60
61
62
63
64
# File 'lib/adhearsion/initializer.rb', line 60

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



71
72
73
74
75
76
77
# File 'lib/adhearsion/initializer.rb', line 71

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