Class: DynDynDong::Service

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

Direct Known Subclasses

Afraid, DynDNS, ZoneEdit

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Service

Returns a new instance of Service.



26
27
28
29
30
31
# File 'lib/dyndyndong/services.rb', line 26

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



58
59
60
# File 'lib/dyndyndong/services.rb', line 58

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

Class Method Details

.eachObject



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

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



67
68
69
70
# File 'lib/dyndyndong/services.rb', line 67

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

.instancesObject



62
63
64
65
# File 'lib/dyndyndong/services.rb', line 62

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

.servicesObject



72
73
74
75
# File 'lib/dyndyndong/services.rb', line 72

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

Instance Method Details

#fetchObject



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

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