Class: Threatinator::FeedRegistry

Inherits:
Registry
  • Object
show all
Defined in:
lib/threatinator/feed_registry.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Registry

#clear, #count, #initialize, #keys

Constructor Details

This class inherits a constructor from Threatinator::Registry

Class Method Details

.build(config) ⇒ Object

Builds a new FeedRegistry based on the provided config

Parameters:



36
37
38
39
40
41
42
43
44
45
# File 'lib/threatinator/feed_registry.rb', line 36

def self.build(config)
  ret = self.new
  config.search_path.each do |path|
    pattern = File.join(path, "**", "*.feed")
    Dir.glob(pattern).each do |filename|
      ret.register_from_file(filename)
    end
  end
  ret
end

Instance Method Details

#eachObject



20
21
22
23
24
25
# File 'lib/threatinator/feed_registry.rb', line 20

def each
  return enum_for(:each) unless block_given?
  super do |key, feed|
    yield(feed)
  end
end

#get(provider, name) ⇒ Threatinator::Feed

Parameters:

  • provider (String)
  • name (String)

Returns:



16
17
18
# File 'lib/threatinator/feed_registry.rb', line 16

def get(provider, name)
  super([provider, name])
end

#register(feed) ⇒ Object

Parameters:

Raises:



9
10
11
# File 'lib/threatinator/feed_registry.rb', line 9

def register(feed)
  super([feed.provider, feed.name], feed)
end

#register_from_file(filename) ⇒ Object



27
28
29
30
31
32
# File 'lib/threatinator/feed_registry.rb', line 27

def register_from_file(filename)
  builder = Threatinator::FeedBuilder.from_file(filename)
  feed = builder.build
  register(feed)
  feed
end