Class: Threatinator::Feed
- Inherits:
-
Object
- Object
- Threatinator::Feed
- Defined in:
- lib/threatinator/feed.rb
Instance Method Summary collapse
- #decoder_builders ⇒ Object
- #event_types ⇒ Object
- #fetcher_builder ⇒ Object
- #filter_builders ⇒ Object
-
#initialize(opts = {}) ⇒ Feed
constructor
A new instance of Feed.
- #name ⇒ Object
- #parser_block ⇒ Object
- #parser_builder ⇒ Object
- #provider ⇒ Object
- #validate! ⇒ Object
- #validate_attribute!(name, val, &block) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Feed
Returns a new instance of Feed.
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/threatinator/feed.rb', line 19 def initialize(opts = {}) @provider = opts.delete(:provider) @name = opts.delete(:name) @event_types = opts.delete(:event_types) || [:uknown] @parser_block = opts.delete(:parser_block) @parser_builder = opts.delete(:parser_builder) @fetcher_builder = opts.delete(:fetcher_builder) @filter_builders = opts.delete(:filter_builders) || [] @decoder_builders = opts.delete(:decoder_builders) || [] validate! end |
Instance Method Details
#decoder_builders ⇒ Object
60 61 62 |
# File 'lib/threatinator/feed.rb', line 60 def decoder_builders @decoder_builders.dup end |
#event_types ⇒ Object
40 41 42 |
# File 'lib/threatinator/feed.rb', line 40 def event_types @event_types.dup end |
#fetcher_builder ⇒ Object
48 49 50 |
# File 'lib/threatinator/feed.rb', line 48 def fetcher_builder @fetcher_builder end |
#filter_builders ⇒ Object
56 57 58 |
# File 'lib/threatinator/feed.rb', line 56 def filter_builders @filter_builders.dup end |
#name ⇒ Object
36 37 38 |
# File 'lib/threatinator/feed.rb', line 36 def name @name.dup end |
#parser_block ⇒ Object
44 45 46 |
# File 'lib/threatinator/feed.rb', line 44 def parser_block @parser_block end |
#parser_builder ⇒ Object
52 53 54 |
# File 'lib/threatinator/feed.rb', line 52 def parser_builder @parser_builder end |
#provider ⇒ Object
32 33 34 |
# File 'lib/threatinator/feed.rb', line 32 def provider @provider.dup end |
#validate! ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/threatinator/feed.rb', line 64 def validate! validate_attribute!(:provider, @provider) { |x| x.kind_of?(::String) } validate_attribute!(:name, @name) { |x| x.kind_of?(::String) } validate_attribute!(:event_types, @event_types) { |x| x.kind_of?(::Array) } validate_attribute!(:parser_block, @parser_block) { |x| x.kind_of?(::Proc) } validate_attribute!(:fetcher_builder, @fetcher_builder) { |x| x.kind_of?(::Proc) } validate_attribute!(:parser_builder, @parser_builder) { |x| x.kind_of?(::Proc) } validate_attribute!(:filter_builders, @filter_builders) do |x| x.kind_of?(::Array) && x.all? { |e| e.kind_of?(::Proc) } end validate_attribute!(:decoder_builders, @decoder_builders) do |x| x.kind_of?(::Array) && x.all? { |e| e.kind_of?(::Proc) } end end |
#validate_attribute!(name, val, &block) ⇒ Object
82 83 84 85 86 |
# File 'lib/threatinator/feed.rb', line 82 def validate_attribute!(name, val, &block) unless block.call(val) == true raise Threatinator::Exceptions::InvalidAttributeError.new("Invalid attribute (#{name}). Got: #{val.inspect}") end end |