Class: Mistilteinn::Ticket::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/mistilteinn/ticket/git_config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_hash, path) ⇒ Config

Returns a new instance of Config.



7
8
9
10
# File 'lib/mistilteinn/ticket/git_config.rb', line 7

def initialize(config_hash, path)
  @config = config_hash
  @path = path
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/mistilteinn/ticket/git_config.rb', line 26

def method_missing(name, *args)
  name = name.to_s
  is_assignment = create_if_nil = false
  if name[-1..-1] == '=' then
    is_assignment = true
    name.slice! -1
  end
  if name[-1..-1] == '_' then
    create_if_nil = true
    name.slice! -1
  end

  return assignment(name, args[0]) if is_assignment

  config_object = get_config_object(@path+[name.to_s])
  return nil if config_object.config.empty? and not create_if_nil

  if config_object.config.class == Hash then
    config_object
  else
    config_object.config
  end
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



11
12
13
# File 'lib/mistilteinn/ticket/git_config.rb', line 11

def config
  @config
end

Instance Method Details

#[](key) ⇒ Object



21
22
23
24
# File 'lib/mistilteinn/ticket/git_config.rb', line 21

def [](key)
  key = key.to_s if key.class == Symbol
  method_missing(key)
end

#[]=(*args) ⇒ Object



17
18
19
# File 'lib/mistilteinn/ticket/git_config.rb', line 17

def []=(*args)
  assignment(args[0], args[1])
end

#has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/mistilteinn/ticket/git_config.rb', line 13

def has_key?(key)
  @config.has_key?(key) || @config.has_key?(key.to_s)
end