Class: Obfuscate::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/obfuscate/config.rb

Overview

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



19
20
21
22
23
24
# File 'lib/obfuscate/config.rb', line 19

def initialize
  # defaults
  @remove_trailing_equal = true
  @encode = true
  @mode = :string
end

Instance Attribute Details

#encodeObject

Returns the value of attribute encode.



17
18
19
# File 'lib/obfuscate/config.rb', line 17

def encode
  @encode
end

#modeObject

Returns the value of attribute mode.



17
18
19
# File 'lib/obfuscate/config.rb', line 17

def mode
  @mode
end

#remove_trailing_equalObject

Returns the value of attribute remove_trailing_equal.



17
18
19
# File 'lib/obfuscate/config.rb', line 17

def remove_trailing_equal
  @remove_trailing_equal
end

#saltObject

Returns the value of attribute salt.



17
18
19
# File 'lib/obfuscate/config.rb', line 17

def salt
  @salt
end

Instance Method Details

#apply(options = {}, &blk) {|config| ... } ⇒ Obfuscate::Config

Creates a new instance of Config with applied changes. Does not change the original Config.

Parameters:

  • options (Hash) (defaults to: {})

    of configurations

  • blk (Block)

    of configuration, has precedence over options hash.

Options Hash (options):

  • :salt (Symbol)

    A Model specific salt

  • :encode (Symbol)

    Enable Base64 and URL encoding for this Model. Enabled by default.

  • :remove_trailing_equal (Symbol)

    When in :block mode, removes the trailing = from the obfuscated text.

Yields:

Returns:



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/obfuscate/config.rb', line 55

def apply(options = {}, &blk)
  config = self.class.new

  changes = self.to_hash.merge( options )

  config.salt = changes[:salt] unless changes[:salt].nil?
  config.mode = changes[:mode] unless changes[:mode].nil?
  config.encode = changes[:encode] unless changes[:encode].nil?
  config.remove_trailing_equal = changes[:remove_trailing_equal] unless changes[:remove_trailing_equal].nil?


  yield(config) if blk

  config
end

#remove_trailing_equal?Boolean

Check if mode is :block and remove_trailing_equal is true

Returns:

  • (Boolean)


41
42
43
# File 'lib/obfuscate/config.rb', line 41

def remove_trailing_equal?
  self.mode == :block && self.remove_trailing_equal == true
end

#to_hashHash

Hash of Config

Returns:

  • (Hash)


73
74
75
# File 'lib/obfuscate/config.rb', line 73

def to_hash
  { :salt => salt, :mode => mode, :encode => encode, :remove_trailing_equal => remove_trailing_equal }
end