Class: DotCloud::DSL

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/dotcloud/dsl.rb

Instance Method Summary collapse

Constructor Details

#initializeDSL

Returns a new instance of DSL.



19
20
21
22
# File 'lib/dotcloud/dsl.rb', line 19

def initialize
  @current_namespace = nil
  @namespaces = {}
end

Instance Method Details

#namespace(name, &block) ⇒ Object Also known as: application



24
25
26
27
28
29
# File 'lib/dotcloud/dsl.rb', line 24

def namespace(name, &block)
  @current_namespace = Namespace.new
  @namespaces[name.to_s] = @current_namespace
  yield
  @current_namespace = nil
end

#runObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/dotcloud/dsl.rb', line 37

def run
  namespace_str = Host.instance.namespace
  namespace = @namespaces[namespace_str]
  unless namespace
    puts "No namespace '#{namespace_str}' found"
    return
  end

  service_str = Host.instance.service
  service = namespace[service_str]
  unless service
    puts "No service '#{service_str}' found in namespace '#{namespace_str}'"
    return
  end

  service.call
end

#service(name, &block) ⇒ Object

Raises:

  • (ArgumentError)


32
33
34
35
# File 'lib/dotcloud/dsl.rb', line 32

def service(name, &block)
  raise ArgumentError, "No current namespace set" unless @current_namespace
  @current_namespace.service(name, &block)
end