Class: MVCLI::Provisioning::Scope

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

Defined Under Namespace

Classes: Constant

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ Scope

Returns a new instance of Scope.



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

def initialize(options = {}, &block)
  @providers = Map options
  evaluate &block if block_given?
end

Class Method Details

.[](name) ⇒ Object



73
74
75
# File 'lib/mvcli/provisioning.rb', line 73

def [](name)
  current![name]
end

.currentObject



61
62
63
# File 'lib/mvcli/provisioning.rb', line 61

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

.current!Object



65
66
67
# File 'lib/mvcli/provisioning.rb', line 65

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

.current=(scope) ⇒ Object



69
70
71
# File 'lib/mvcli/provisioning.rb', line 69

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

Instance Method Details

#[](name) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/mvcli/provisioning.rb', line 30

def [](name)
  unless provider = @providers[name]
    provider = @providers[name] = cortex.read :provider, name
  end
  if provider.respond_to?(:value)
    provider.value
  elsif provider.respond_to?(:instance_methods) && provider.instance_methods.member?(:value)
    provider.new.value
  else
    provider
  end
end

#evaluate(names = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/mvcli/provisioning.rb', line 43

def evaluate(names = {})
  old = self.class.current
  providers = @providers
  @providers = Map @providers.to_hash.merge(names)
  self.class.current = self
  yield
ensure
  @providers = providers
  self.class.current = old
end