summaryrefslogtreecommitdiff
path: root/qa/qa/runtime/address.rb
blob: af0537dc17c374f13d96fc8bfb1db997d83a215d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
module QA
  module Runtime
    class Address
      attr_reader :address

      def initialize(instance, page = nil)
        @instance = instance
        @address  = host + (page.is_a?(String) ? page : page&.path)
      end

      def host
        if @instance.is_a?(Symbol)
          Runtime::Scenario.send("#{@instance}_address")
        else
          @instance.to_s
        end
      end

      def self.valid?(value)
        uri = URI.parse(value)
        uri.is_a?(URI::HTTP) && !uri.host.nil?
      rescue URI::InvalidURIError
        false
      end
    end
  end
end