Module: AppIdentity::Validation

Included in:
App, Internal, Versions
Defined in:
lib/app_identity/validation.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#validate_config(config) ⇒ Object

:nodoc:



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/app_identity/validation.rb', line 41

def validate_config(config) # :nodoc:
  config.tap {
    raise AppIdentity::Error, "config must be nil or a map" unless config.nil? || config.is_a?(Hash)

    if config.is_a?(Hash)
      fuzz = config[:fuzz] || config["fuzz"]

      case fuzz
      when nil
        nil
      when Integer
        raise AppIdentity::Error, "config.fuzz must be a positive integer or nil" unless fuzz > 0
      else
        raise AppIdentity::Error, "config.fuzz must be a positive integer or nil"
      end
    end
  }
end

#validate_id(id) ⇒ Object

:nodoc:



7
8
9
10
11
12
13
# File 'lib/app_identity/validation.rb', line 7

def validate_id(id) # :nodoc:
  id.tap {
    validate_not_nil(:id, id)
    validate_not_empty(:id, id.to_s)
    validate_no_colons(:id, id.to_s)
  }.to_s
end

#validate_padlock(padlock) ⇒ Object

:nodoc:



60
61
62
63
64
65
66
67
# File 'lib/app_identity/validation.rb', line 60

def validate_padlock(padlock) # :nodoc:
  padlock.tap {
    validate_not_nil(:padlock, padlock)
    raise AppIdentity::Error, "padlock must be a string" unless padlock.is_a?(String)
    validate_not_empty(:padlock, padlock)
    validate_no_colons(:padlock, padlock)
  }
end

#validate_secret(secret) ⇒ Object

:nodoc:



15
16
17
18
19
20
21
22
23
# File 'lib/app_identity/validation.rb', line 15

def validate_secret(secret) # :nodoc:
  secret.tap {
    secret = secret.call if secret.respond_to?(:call)

    validate_not_nil(:secret, secret)
    raise AppIdentity::Error, "secret must be a binary string value" unless secret.is_a?(String)
    validate_not_empty(:secret, secret)
  }
end

#validate_version(version) ⇒ Object

:nodoc:



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/app_identity/validation.rb', line 25

def validate_version(version) # :nodoc:
  version.tap {
    validate_not_nil(:version, version)

    begin
      version = Integer(version) if version.is_a?(String)
    rescue
      raise AppIdentity::Error, "version cannot be converted to an integer"
    end

    if !version.is_a?(Integer) || version <= 0
      raise AppIdentity::Error, "version must be a positive integer"
    end
  }.to_i
end