Class: Travis::Yaml::SecureString

Inherits:
Object
  • Object
show all
Defined in:
lib/travis/yaml/secure_string.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string, encrypted = true) ⇒ SecureString

Returns a new instance of SecureString.



4
5
6
7
8
9
10
11
12
13
# File 'lib/travis/yaml/secure_string.rb', line 4

def initialize(string, encrypted = true)
  unless string.respond_to? :to_str
    raise ArgumentError, "secure string needs to be a string, not a %p" % string.class.name.downcase
  end
  if encrypted
    @encrypted_string = string.to_str
  else
    @decrypted_string = string.to_str
  end
end

Instance Attribute Details

#decrypted_stringObject

Returns the value of attribute decrypted_string.



3
4
5
# File 'lib/travis/yaml/secure_string.rb', line 3

def decrypted_string
  @decrypted_string
end

#encrypted_stringObject

Returns the value of attribute encrypted_string.



3
4
5
# File 'lib/travis/yaml/secure_string.rb', line 3

def encrypted_string
  @encrypted_string
end

Instance Method Details

#==(other) ⇒ Object



37
38
39
# File 'lib/travis/yaml/secure_string.rb', line 37

def ==(other)
  other.encrypted_string == encrypted_string and other.decrypted_string == decrypted_string if other.is_a? SecureString
end

#decryptObject



23
24
25
26
# File 'lib/travis/yaml/secure_string.rb', line 23

def decrypt
  return unless encrypted?
  @decrypted_string = yield(encrypted_string)
end

#decrypted?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/travis/yaml/secure_string.rb', line 19

def decrypted?
  !!decrypted_string
end

#encryptObject



28
29
30
31
# File 'lib/travis/yaml/secure_string.rb', line 28

def encrypt
  return unless decrypted?
  @encrypted_string = yield(decrypted_string)
end

#encrypted?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/travis/yaml/secure_string.rb', line 15

def encrypted?
  !!encrypted_string
end

#hashObject



41
42
43
# File 'lib/travis/yaml/secure_string.rb', line 41

def hash
  encrypted_string.hash | decrypted_string.hash
end

#inspectObject



33
34
35
# File 'lib/travis/yaml/secure_string.rb', line 33

def inspect
  "[SECURE]".freeze
end