Class: Tengine::Resource::Credential::AuthField

Inherits:
Object
  • Object
show all
Defined in:
lib/tengine/resource/credential.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type_key, options = {}) ⇒ AuthField

Returns a new instance of AuthField.



57
58
59
60
61
62
# File 'lib/tengine/resource/credential.rb', line 57

def initialize(name, type_key, options = {})
  @name, @type_key = name.to_s, type_key.to_sym
  @options = options || {}
  @optional = !!@options[:optional]
  @default = @options[:default]
end

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default.



56
57
58
# File 'lib/tengine/resource/credential.rb', line 56

def default
  @default
end

#nameObject (readonly)

Returns the value of attribute name.



56
57
58
# File 'lib/tengine/resource/credential.rb', line 56

def name
  @name
end

#optionalObject (readonly)

Returns the value of attribute optional.



56
57
58
# File 'lib/tengine/resource/credential.rb', line 56

def optional
  @optional
end

#type_keyObject (readonly)

Returns the value of attribute type_key.



56
57
58
# File 'lib/tengine/resource/credential.rb', line 56

def type_key
  @type_key
end

Instance Method Details

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/tengine/resource/credential.rb', line 72

def eql?(other)
  self.name <=> other.to_s
end

#hashObject



75
76
77
# File 'lib/tengine/resource/credential.rb', line 75

def hash
  self.name.hash
end

#optional?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/tengine/resource/credential.rb', line 68

def optional?
  @optional
end

#to_sObject



78
79
80
# File 'lib/tengine/resource/credential.rb', line 78

def to_s
  self.name
end

#validate(credential, hash) ⇒ Object



63
64
65
66
67
# File 'lib/tengine/resource/credential.rb', line 63

def validate(credential, hash)
  unless optional
    credential.errors.add(:auth_values, "#{name.inspect} can't be blank") if hash[name].blank?
  end
end