Class: Cline::SecretString
- Extended by:
- Forwardable
- Defined in:
- lib/cline/secret_string.rb
Overview
::SecretString wrapper that allows us to use it in our Shale schemas
Internal collapse
-
#secret_string ⇒ Hash
readonly
The internal secret string.
Attributes inherited from Schema
Public API collapse
-
#==(other) ⇒ Boolean
Equality check.
Internal collapse
-
.as_hash(instance, *_args, **_kwargs) ⇒ Hash
Get a Hash object from an instance.
-
.cast(value) ⇒ Schema?
Cast an input value to this Schema object.
-
.of_hash(hash, *_args, **_kwargs) ⇒ Schema
Parse a Hash object and instantiate the proper instance from it.
-
#initialize(unprotected_string) ⇒ SecretString
constructor
Constructor.
-
#to_hash ⇒ Hash
Output this object as a Hash.
Methods inherited from Schema
cline_snake_attributes, #to_cline_json
Constructor Details
#initialize(unprotected_string) ⇒ SecretString
Constructor
26 27 28 29 |
# File 'lib/cline/secret_string.rb', line 26 def initialize(unprotected_string) super() @secret_string = ::SecretString.new(unprotected_string) end |
Instance Attribute Details
#secret_string ⇒ Hash (readonly)
Returns The internal secret string.
32 33 34 |
# File 'lib/cline/secret_string.rb', line 32 def secret_string @secret_string end |
Class Method Details
.as_hash(instance, *_args, **_kwargs) ⇒ Hash
Get a Hash object from an instance.
60 61 62 |
# File 'lib/cline/secret_string.rb', line 60 def as_hash(instance, *_args, **_kwargs) instance.secret_string.to_unprotected end |
.cast(value) ⇒ Schema?
Cast an input value to this Schema object. Allow the attribute to be initialized directly using its Hash form.
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/cline/secret_string.rb', line 69 def cast(value) return nil if value.nil? # We expect the value to be a String, or a new instance already initialized. if value.is_a?(self) value elsif value.is_a?(String) new(value) else raise "Unable to cast #{value} into #{name}" end end |
.of_hash(hash, *_args, **_kwargs) ⇒ Schema
Parse a Hash object and instantiate the proper instance from it.
50 51 52 |
# File 'lib/cline/secret_string.rb', line 50 def of_hash(hash, *_args, **_kwargs) SecretString.new(hash) end |
Instance Method Details
#==(other) ⇒ Boolean
Equality check
16 17 18 19 |
# File 'lib/cline/secret_string.rb', line 16 def ==(other) other.is_a?(SecretString) && other.to_unprotected == to_unprotected end |
#to_hash ⇒ Hash
Output this object as a Hash.
37 38 39 |
# File 'lib/cline/secret_string.rb', line 37 def to_hash SecretString.as_hash(self) end |