Class: Ablerc::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/ablerc/context.rb

Constant Summary collapse

DEFAULTS =
{global: {path: '/etc/'},
user:   {path: '~/'},
local:  {path: './'}}
@@contexts =
Hashie::Mash.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Context

Returns a new instance of Context.



13
14
15
16
17
# File 'lib/ablerc/context.rb', line 13

def initialize(name, options={})
  @name = name
  @path = options.delete(:path)
  Ablerc::Context << self
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



10
11
12
# File 'lib/ablerc/context.rb', line 10

def name
  @name
end

#pathObject

Returns the value of attribute path.



10
11
12
# File 'lib/ablerc/context.rb', line 10

def path
  @path
end

Class Method Details

.<<(context) ⇒ Object



25
26
27
# File 'lib/ablerc/context.rb', line 25

def <<(context)
  @@contexts.merge!(context.name => context)
end

.exists?(context) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/ablerc/context.rb', line 44

def exists?(context)
  @@contexts.has_key? context
end

.listObject



35
36
37
# File 'lib/ablerc/context.rb', line 35

def list
  @@contexts
end

.method_missing(method_name, *args, &block) ⇒ Object



48
49
50
# File 'lib/ablerc/context.rb', line 48

def method_missing(method_name, *args, &block)
  @@contexts.send(method_name, *args, &block) || super
end

.namesObject



39
40
41
# File 'lib/ablerc/context.rb', line 39

def names
  @@contexts.keys
end

.pathsObject



30
31
32
# File 'lib/ablerc/context.rb', line 30

def paths
  @@contexts.collect { |name, context| context.path }
end