Class: Mongo::Options::Redacted
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
| Class Chain: 
          self,
          BSON::Document
         | |
| Instance Chain: 
          self,
          BSON::Document
         | |
| Inherits: | BSON::Document 
 | 
| Defined in: | lib/mongo/options/redacted.rb | 
Overview
Class for wrapping options that could be sensitive. When printed, the sensitive values will be redacted.
Constant Summary
- 
    SENSITIVE_OPTIONS =
    # File 'lib/mongo/options/redacted.rb', line 30The options whose values will be redacted. [ :password, :pwd ].freeze 
- 
    STRING_REPLACEMENT =
    # File 'lib/mongo/options/redacted.rb', line 36The replacement string used in place of the value for sensitive keys. '<REDACTED>'.freeze 
Instance Method Summary
- 
    
      #has_key?(key)  ⇒ true, false 
      (also: #key?)
    
    Whether these options contain a given key. 
- 
    
      #inspect  ⇒ String 
    
    Get a string representation of the options. 
- 
    
      #key?(key)  
    
    Alias for #has_key?. 
- 
    
      #reject {|The| ... } ⇒ Options::Redacted 
    
    Returns a new options object consisting of pairs for which the block returns false. 
- 
    
      #reject! {|The| ... } ⇒ Options::Redacted? 
    
    Only keeps pairs for which the block returns false. 
- 
    
      #select {|The| ... } ⇒ Options::Redacted 
    
    Returns a new options object consisting of pairs for which the block returns true. 
- 
    
      #select! {|The| ... } ⇒ Options::Redacted? 
    
    Only keeps pairs for which the block returns true. 
- 
    
      #to_s  ⇒ String 
    
    Get a string representation of the options. 
- #redact(k, v, method) private
- #redacted_string(method) private
Instance Method Details
    #has_key?(key)  ⇒ true, false 
    Also known as: #key?
  
Whether these options contain a given key.
# File 'lib/mongo/options/redacted.rb', line 66
def has_key?(key) super(convert_key(key)) end
    #inspect  ⇒ String 
  
Get a string representation of the options.
# File 'lib/mongo/options/redacted.rb', line 43
def inspect redacted_string(:inspect) end
#key?(key)
Alias for #has_key?.
# File 'lib/mongo/options/redacted.rb', line 69
alias_method :key?, :has_key?
#redact(k, v, method) (private)
# File 'lib/mongo/options/redacted.rb', line 153
def redact(k, v, method) return STRING_REPLACEMENT if SENSITIVE_OPTIONS.include?(k.to_sym) v.send(method) end
#redacted_string(method) (private)
# File 'lib/mongo/options/redacted.rb', line 147
def redacted_string(method) '{' + reduce([]) do |list, (k, v)| list << "#{k.send(method)}=>#{redact(k, v, method)}" end.join(', ') + '}' end
#reject {|The| ... } ⇒ Options::Redacted
Returns a new options object consisting of pairs for which the block returns false.
# File 'lib/mongo/options/redacted.rb', line 81
def reject(&block) = dup .reject!(&block) || end
#reject! {|The| ... } ⇒ Options::Redacted?
Only keeps pairs for which the block returns false.
# File 'lib/mongo/options/redacted.rb', line 96
def reject! if block_given? n_keys = keys.size keys.each do |key| delete(key) if yield(key, self[key]) end n_keys == keys.size ? nil : self else to_enum end end
#select {|The| ... } ⇒ Options::Redacted
Returns a new options object consisting of pairs for which the block returns true.
# File 'lib/mongo/options/redacted.rb', line 118
def select(&block) = dup .select!(&block) || end
#select! {|The| ... } ⇒ Options::Redacted?
Only keeps pairs for which the block returns true.
# File 'lib/mongo/options/redacted.rb', line 133
def select! if block_given? n_keys = keys.size keys.each do |key| delete(key) unless yield(key, self[key]) end n_keys == keys.size ? nil : self else to_enum end end
    #to_s  ⇒ String 
  
Get a string representation of the options.
# File 'lib/mongo/options/redacted.rb', line 52
def to_s redacted_string(:to_s) end