Class: Aquatone::Collector

Inherits:
Object
  • Object
show all
Defined in:
lib/aquatone/collector.rb

Defined Under Namespace

Classes: Error, InvalidMetadataError, MetadataNotSetError, MissingKeyRequirement

Constant Summary collapse

DEFAULT_PRIORITY =
1

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(domain) ⇒ Collector

Returns a new instance of Collector.



31
32
33
34
35
# File 'lib/aquatone/collector.rb', line 31

def initialize(domain)
  check_key_requirements!
  @domain = domain
  @hosts  = []
end

Instance Attribute Details

#domainObject (readonly)

Returns the value of attribute domain.



8
9
10
# File 'lib/aquatone/collector.rb', line 8

def domain
  @domain
end

#hostsObject (readonly)

Returns the value of attribute hosts.



8
9
10
# File 'lib/aquatone/collector.rb', line 8

def hosts
  @hosts
end

Class Method Details

.descendantsObject



21
22
23
24
# File 'lib/aquatone/collector.rb', line 21

def self.descendants
  collectors = ObjectSpace.each_object(Class).select { |klass| klass < self }
  collectors.sort { |x, y| x.priority <=> y.priority }
end

.metaObject



12
13
14
# File 'lib/aquatone/collector.rb', line 12

def self.meta
  @meta || fail(MetadataNotSetError, "Metadata has not been set")
end

.meta=(meta) ⇒ Object



16
17
18
19
# File 'lib/aquatone/collector.rb', line 16

def self.meta=(meta)
  (meta)
  @meta = meta
end

.priorityObject



46
47
48
# File 'lib/aquatone/collector.rb', line 46

def self.priority
  meta[:priority] || DEFAULT_PRIORITY
end

.sluggified_nameObject



26
27
28
29
# File 'lib/aquatone/collector.rb', line 26

def self.sluggified_name
  return meta[:slug].downcase if meta[:slug]
  meta[:name].strip.downcase.gsub(/[^a-z0-9]+/, '-').gsub("--", "-")
end

Instance Method Details

#execute!Object



41
42
43
44
# File 'lib/aquatone/collector.rb', line 41

def execute!
  run
  hosts
end

#runObject



37
38
39
# File 'lib/aquatone/collector.rb', line 37

def run
  fail NotImplementedError
end