Sha256: 217f5c693e56c9bf7d519341d9dffca3ccf513db19c1a8431ed671072a2a4a80

Contents?: true

Size: 1.07 KB

Versions: 8

Compression:

Stored size: 1.07 KB

Contents

module Fitting
  class Skip
    class Action
      attr_accessor :host, :method, :path, :code

      def initialize(host, method, path, code)
        @host = host
        @method = method
        @path = path
        @code = code
      end

      def self.all(actions)
        return [] unless actions
        actions.map do |action|
          next if action['method'].nil? || action['path'].nil?
          new(action['host'], action['method'], action['path'], action['code'])
        end.compact
      end

      def self.find(actions, log)
        actions.find do |action|
          if action.host == log.host &&
            action.method == log.method &&
            action.path_match(log.path)
            return action if action.code == nil
            return action if action.code.to_s == log.status
          end
        end
      end

      def path_match(find_path)
        regexp =~ find_path
      end

      def regexp
        str = Regexp.escape(path)
        str = str.gsub(/\\{\w+\\}/, '[^&=\/]+')
        str = "\\A#{str}\\z"
        Regexp.new(str)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
fitting-4.2.1 lib/fitting/skip/action.rb
fitting-4.2.0 lib/fitting/skip/action.rb
fitting-4.1.0 lib/fitting/skip/action.rb
fitting-4.0.4 lib/fitting/skip/action.rb
fitting-4.0.3 lib/fitting/skip/action.rb
fitting-4.0.2 lib/fitting/skip/action.rb
fitting-4.0.1 lib/fitting/skip/action.rb
fitting-4.0.0 lib/fitting/skip/action.rb