Sha256: 9f7044547346d85a13526420b71974adb14eee5f7ee177112cbf5ad08f80a7ea

Contents?: true

Size: 891 Bytes

Versions: 15

Compression:

Stored size: 891 Bytes

Contents

module Radiosonde::DSL::Validator
  def _required(name, value)
    invalid = false

    if value
      case value
      when String
        invalid = value.strip.empty?
      when Array, Hash
        invalid = value.empty?
      end
    elsif value.nil?
      invalid = true
    end

    raise _identify("`#{name}` is required") if invalid
  end

  def _call_once(method_name)
    @called ||= []

    if @called.include?(method_name)
      raise _identify("`#{method_name}` is already defined")
    end

    @called << method_name
  end

  def _expected_type(value, *types)
    unless types.any? {|t| value.kind_of?(t) }
      raise _identify("Invalid type: #{value}")
    end
  end

  def _validate(errmsg)
    raise _identify(errmsg) unless yield
  end

  def _identify(errmsg)
    if @error_identifier
      errmsg = "#{@error_identifier}: #{errmsg}"
    end

    return errmsg
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
radiosonde-0.2.0.beta5 lib/radiosonde/dsl/validator.rb
radiosonde-0.2.0.beta4 lib/radiosonde/dsl/validator.rb
radiosonde-0.2.0.beta3 lib/radiosonde/dsl/validator.rb
radiosonde-0.2.0.beta2 lib/radiosonde/dsl/validator.rb
radiosonde-0.2.0.beta lib/radiosonde/dsl/validator.rb
radiosonde-0.1.1 lib/radiosonde/dsl/validator.rb
radiosonde-0.1.0 lib/radiosonde/dsl/validator.rb
radiosonde-0.0.8 lib/radiosonde/dsl/validator.rb
radiosonde-0.0.7 lib/radiosonde/dsl/validator.rb
radiosonde-0.0.6 lib/radiosonde/dsl/validator.rb
radiosonde-0.0.5 lib/radiosonde/dsl/validator.rb
radiosonde-0.0.4 lib/radiosonde/dsl/validator.rb
radiosonde-0.0.3 lib/radiosonde/dsl/validator.rb
radiosonde-0.0.2 lib/radiosonde/dsl/validator.rb
radiosonde-0.0.1 lib/radiosonde/dsl/validator.rb