Class: Halcyon::Config::Paths

Inherits:
Object
  • Object
show all
Defined in:
lib/halcyon/config/paths.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(paths = {}) ⇒ Paths

Creates a profile with the default paths.



8
9
10
# File 'lib/halcyon/config/paths.rb', line 8

def initialize(paths={})
  self.paths = Mash.new(self.defaults.merge(paths))
end

Instance Attribute Details

#pathsObject

Returns the value of attribute paths.



5
6
7
# File 'lib/halcyon/config/paths.rb', line 5

def paths
  @paths
end

Instance Method Details

#[](key) ⇒ Object

Alias to for.



24
25
26
# File 'lib/halcyon/config/paths.rb', line 24

def [](key)
  self.for(key)
end

#[]=(key, value) ⇒ Object

Alias for define.



50
51
52
# File 'lib/halcyon/config/paths.rb', line 50

def []=(key, value)
  self.define(key, value)
end

#defaultsObject

Default paths.



56
57
58
59
60
61
62
63
64
65
# File 'lib/halcyon/config/paths.rb', line 56

def defaults
  {
    :controller => Halcyon.root/'app',
    :model => Halcyon.root/'app'/'models',
    :lib => Halcyon.root/'lib',
    :config => Halcyon.root/'config',
    :init => Halcyon.root/'config'/'init',
    :log => Halcyon.root/'log'
  }
end

#define(key_or_hash, value = nil) ⇒ Object

Defines a path for the specified entity.

Examples:

Halcyon.paths.define(:tmp, Halcyon.root/'tmp')

OR

Halcyon.paths.define(:tmp => Halcyon.root/'tmp')


38
39
40
41
42
43
44
45
46
# File 'lib/halcyon/config/paths.rb', line 38

def define(key_or_hash, value = nil)
  if key_or_hash.is_a?(Hash) and value.nil?
    key_or_hash.keys.each do |key|
      self.define(key, key_or_hash[key])
    end
  else
    self.paths[key_or_hash] = value
  end
end

#for(key) ⇒ Object

Gets the path for the specified entity.

Examples:

Halcyon.paths.for(:log) #=> "/path/to/app/log/"


18
19
20
# File 'lib/halcyon/config/paths.rb', line 18

def for(key)
  self.paths[key] or raise ArgumentError.new("Path is not defined")
end

#inspectObject



67
68
69
# File 'lib/halcyon/config/paths.rb', line 67

def inspect
  "#<Halcyon::Config::Paths #{self.paths.keys.join(', ')}>"
end