module SkullIsland::Validations::Resource

Resource validation methods

Public Instance Methods

validate_id() click to toggle source

The 'id' field should not be set manually

# File lib/skull_island/validations/resource.rb, line 12
def validate_id
  raise Exceptions::NewInstanceWithID if @entity.key?('id') && @tainted
end
validate_mutability() click to toggle source
# File lib/skull_island/validations/resource.rb, line 7
def validate_mutability
  raise Exceptions::ImmutableModification if immutable? && @tainted # this shouldn't happen
end
validate_required_properties(data) click to toggle source

Ensure that required properties are set before saving

# File lib/skull_island/validations/resource.rb, line 17
def validate_required_properties(data)
  required_properties.each do |name, _value|
    raise Exceptions::InvalidArguments, "Missing argument: #{name}" if data[name.to_s].nil?
  end
end
validate_tags(value) click to toggle source

Used to validate tags on set

# File lib/skull_island/validations/resource.rb, line 24
def validate_tags(value)
  # allow only valid hostnames
  value.each do |tag|
    return false unless tag.is_a?(String) && tag.match?(/^[\w_\-.~]+$/)
  end
  true
end