lib/mihari/models/port.rb in mihari-5.6.1 vs lib/mihari/models/port.rb in mihari-5.6.2

- old
+ new

@@ -1,30 +1,32 @@ # frozen_string_literal: true module Mihari - class Port < ActiveRecord::Base - belongs_to :artifact + module Models + class Port < ActiveRecord::Base + belongs_to :artifact - class << self - include Dry::Monads[:result] + class << self + include Dry::Monads[:result] - # - # Build ports - # - # @param [String] ip - # @param [Mihari::Enrichers::Shodan] enricher - # - # @return [Array<Mihari::Port>] - # - def build_by_ip(ip, enricher: Enrichers::Shodan.new) - result = enricher.query_result(ip).bind do |res| - if res.nil? - Success [] - else - Success(res.ports.map { |port| new(port: port) }) + # + # Build ports + # + # @param [String] ip + # @param [Mihari::Enrichers::Shodan] enricher + # + # @return [Array<Mihari::Port>] + # + def build_by_ip(ip, enricher: Enrichers::Shodan.new) + result = enricher.query_result(ip).bind do |res| + if res.nil? + Success [] + else + Success(res.ports.map { |port| new(port: port) }) + end end + result.value_or [] end - result.value_or [] end end end end