Class: MVCLI::Provisioning::Scope

Inherits:
Object
  • Object
show all
Defined in:
lib/mvcli/provisioning.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, provisioner) ⇒ Scope

Returns a new instance of Scope.



21
22
23
24
# File 'lib/mvcli/provisioning.rb', line 21

def initialize(command, provisioner)
  @command = command
  @provisioner = provisioner
end

Class Method Details

.[](name) ⇒ Object



50
51
52
# File 'lib/mvcli/provisioning.rb', line 50

def self.[](name)
  current![name] or fail UnsatisfiedRequirement, "'#{name}' is required, but can't find it"
end

.current ⇒ Object



38
39
40
# File 'lib/mvcli/provisioning.rb', line 38

def self.current
  Thread.current[self.class.name]
end

.current! ⇒ Object



42
43
44
# File 'lib/mvcli/provisioning.rb', line 42

def self.current!
  current or fail MissingScope, "attempting to access scope, but none is active!"
end

.current=(scope) ⇒ Object



46
47
48
# File 'lib/mvcli/provisioning.rb', line 46

def self.current=(scope)
  Thread.current[self.class.name] = scope
end

Instance Method Details

#[](name) ⇒ Object



26
27
28
# File 'lib/mvcli/provisioning.rb', line 26

def [](name)
  name.to_s == "command" ? @command : @provisioner[name]
end

#evaluate ⇒ Object



30
31
32
33
34
35
36
# File 'lib/mvcli/provisioning.rb', line 30

def evaluate
  old = self.class.current
  self.class.current = self
  yield
ensure
  self.class.current = old
end