Class: DynDynDong::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/dyndyndong/services.rb

Direct Known Subclasses

Afraid, Generic, ZoneEdit

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Service

Returns a new instance of Service.



24
25
26
27
28
29
# File 'lib/dyndyndong/services.rb', line 24

def initialize(&block)
  @@instances ||= []
  @@instances << self
  @hosts = []
  self.instance_eval(&block) if block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



56
57
58
# File 'lib/dyndyndong/services.rb', line 56

def method_missing(sym, *args, &block)
  STDERR.puts("#{sym.to_s.inspect} missed for #{self.class}, skipping...")
end

Class Method Details

.eachObject



75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/dyndyndong/services.rb', line 75

def self.each
  objs = []
  self.instances.each {|i|
    objs << i
    yield i if block_given?
  }
  if block_given?
    objs
  else
    Enumerator.new(objs)
  end
end

.inherited(obj) ⇒ Object



65
66
67
68
# File 'lib/dyndyndong/services.rb', line 65

def self.inherited(obj)
  @@services ||= []
  @@services << obj
end

.instancesObject



60
61
62
63
# File 'lib/dyndyndong/services.rb', line 60

def self.instances
  @@instances ||=[]
  @@instances
end

.servicesObject



70
71
72
73
# File 'lib/dyndyndong/services.rb', line 70

def self.services
  @@services ||= []
  @@services
end

Instance Method Details

#fetchObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/dyndyndong/services.rb', line 31

def fetch
  begin
    prefetch if self.respond_to?(:prefetch)
  rescue Exception => e
    STDERR.puts("Prefetch error: #{e}, skipping...")
    return
  end

  @hosts.each {|args|
    STDOUT.write("Aliasing #{args.is_a?(Array) ? args.first : args}...")
    begin
      res = alias_host(*args)
      STDOUT.write("\r--- #{args.is_a?(Array) ? args.first : args}        \n\t#{res.gsub(/\n/, "\n\t")}\n")
    rescue Exception => e
      STDERR.puts("\tFetch error: #{e}, skipping...")
    end
  }

  begin
    postfetch if self.respond_to?(:postfetch)
  rescue Exception => e
    STDERR.puts("Postfetch error: #{e}")
  end
end