Class: Gitosis::Forker

Inherits:
Object
  • Object
show all
Defined in:
lib/gitosis_easy_conf/forkers.rb

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Forker

Returns a new instance of Forker.



11
12
13
14
# File 'lib/gitosis_easy_conf/forkers.rb', line 11

def initialize(&block)
  @forkers = {}
  instance_eval(&block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/gitosis_easy_conf/forkers.rb', line 16

def method_missing(method, *args, &block)
  if args.length > 0

    if @forkers.values.include?(args.first.to_s)
      raise(SamePublicKeyForForkers, "Key '#{args.first}' used by '#{method}' "+
            "and #{@forkers.invert[args.first.to_s]}'")
    end

    if @forkers.keys.include?(method)
      raise(ForkerAlreadyDefined, "Forker '#{method}' already defined with key: " +
            "#{@forkers[method]}")
    end

    @forkers[method] = args.first.to_s
  else
    raise(Gitosis::UnknownForker,
          "Forker '#{method}' Not Found") unless @forkers.keys.include?(method)
    @forkers[method]
  end
end

Instance Method Details

#[](name) ⇒ Object



37
38
39
# File 'lib/gitosis_easy_conf/forkers.rb', line 37

def [](name)
  send(name.to_sym)
end

#allObject



41
42
43
# File 'lib/gitosis_easy_conf/forkers.rb', line 41

def all
  @forkers.keys
end