class Radiosonde::DSL::Context

Attributes

result[R]

Public Class Methods

eval(dsl, path, opts = {}) click to toggle source
# File lib/radiosonde/dsl/context.rb, line 6
def eval(dsl, path, opts = {})
  self.new(path, opts) {
    eval(dsl, binding, path)
  }
end
new(path, options = {}, &block) click to toggle source
# File lib/radiosonde/dsl/context.rb, line 15
def initialize(path, options = {}, &block)
  @path = path
  @options = options
  @result = OpenStruct.new(:alarms => [])
  @alarm_names = []

  @context = Hashie::Mash.new(
    :path => path,
    :options => options,
    :templates => {}
  )

  instance_eval(&block)
end

Private Instance Methods

alarm(name, &block) click to toggle source
# File lib/radiosonde/dsl/context.rb, line 48
def alarm(name, &block)
  _required(:alarm_name, name)
  _validate("Alarm `#{name}` is already defined") do
    not @alarm_names.include?(name)
  end

  @result.alarms << Radiosonde::DSL::Context::Alarm.new(@context, name, &block).result
  @alarm_names << name
end
require(file) click to toggle source
# File lib/radiosonde/dsl/context.rb, line 36
def require(file)
  alarmfile = (file =~ %r|\A/|) ? file : File.expand_path(File.join(File.dirname(@path), file))

  if File.exist?(alarmfile)
    instance_eval(File.read(alarmfile), alarmfile)
  elsif File.exist?(alarmfile + '.rb')
    instance_eval(File.read(alarmfile + '.rb'), alarmfile + '.rb')
  else
    Kernel.require(file)
  end
end
template(name, &block) click to toggle source
# File lib/radiosonde/dsl/context.rb, line 32
def template(name, &block)
  @context.templates[name.to_s] = block
end