Class: GitSafe::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/git-safe/configuration.rb

Constant Summary collapse

OPTIONS =
{
  logger:                              ::Logger.new(STDOUT),
  branch:                              'master',
  remote:                              'origin',
  clone_command_repo_dir_replace_text: '<REPO_DIR>',
  ssh_private_key:                     nil, # path or string
}.freeze

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Initializes defaults to be the environment varibales of the same names



17
18
19
20
21
# File 'lib/git-safe/configuration.rb', line 17

def initialize
  OPTIONS.each_pair do |key, value|
    send("#{key}=", value)
  end
end

Instance Method Details

#[](option) ⇒ Object

Allows config options to be read like a hash

Parameters:

  • option (Symbol)

    Key for a given attribute



26
27
28
# File 'lib/git-safe/configuration.rb', line 26

def [](option)
  send(option)
end

#merge(hash) ⇒ Object

Returns a hash of all configurable options merged with hash

precedence over the defaults

Parameters:

  • hash (Hash)

    A set of configuration options that will take



42
43
44
# File 'lib/git-safe/configuration.rb', line 42

def merge(hash)
  to_hash.merge(hash)
end

#to_hashObject

Returns a hash of all configurable options



31
32
33
34
35
36
# File 'lib/git-safe/configuration.rb', line 31

def to_hash
  OPTIONS.each_with_object({}) do |option, hash|
    key       = option.first
    hash[key] = send(key)
  end
end