Class: HolePunch::DSL

Inherits:
BaseDSL show all
Defined in:
lib/holepunch/dsl.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseDSL

#env

Constructor Details

#initialize(env) ⇒ DSL

Returns a new instance of DSL.



94
95
96
# File 'lib/holepunch/dsl.rb', line 94

def initialize(env)
  super(env, Definition.new(env))
end

Class Method Details

.evaluate(filename, env) ⇒ Object



90
91
92
# File 'lib/holepunch/dsl.rb', line 90

def self.evaluate(filename, env)
  DSL.new(env).eval_dsl(filename)
end

Instance Method Details

#depends(id) ⇒ Object

Raises:



106
107
108
109
110
111
# File 'lib/holepunch/dsl.rb', line 106

def depends(id)
  id = id.to_s
  raise GroupError, "duplicate group id #{id}" if @model.groups.include?(id)
  raise HolePunchSyntaxError, "dependency group #{id} cannot have a block" if block_given?
  @model.add_group(SecurityGroup.new(id, dependency: true))
end

#eval_dsl(filename) ⇒ Object



98
99
100
101
102
103
104
# File 'lib/holepunch/dsl.rb', line 98

def eval_dsl(filename)
  super(filename)
  @model.validate!
  @model
rescue SyntaxError => e
  raise SecurityGroupsFileError, "SecurityGroups syntax error #{e.message.gsub("#{filename.to_s}:", 'on line ')}"
end

#group(id, &block) ⇒ Object

Raises:



113
114
115
116
117
# File 'lib/holepunch/dsl.rb', line 113

def group(id, &block)
  id = id.to_s
  raise GroupError, "duplicate group id #{id}" if @model.groups.include?(id)
  @model.add_group(GroupDSL.evaluate(@env, id, &block))
end

#service(id, &block) ⇒ Object



119
120
121
122
# File 'lib/holepunch/dsl.rb', line 119

def service(id, &block)
  id = id.to_s
  @model.services[id] = ServiceDSL.evaluate(@env, id, &block)
end