Class: Fitting::Skip::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/fitting/skip/action.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, method, path, code) ⇒ Action

Returns a new instance of Action.



6
7
8
9
10
11
# File 'lib/fitting/skip/action.rb', line 6

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

Instance Attribute Details

#codeObject

Returns the value of attribute code.



4
5
6
# File 'lib/fitting/skip/action.rb', line 4

def code
  @code
end

#hostObject

Returns the value of attribute host.



4
5
6
# File 'lib/fitting/skip/action.rb', line 4

def host
  @host
end

#methodObject

Returns the value of attribute method.



4
5
6
# File 'lib/fitting/skip/action.rb', line 4

def method
  @method
end

#pathObject

Returns the value of attribute path.



4
5
6
# File 'lib/fitting/skip/action.rb', line 4

def path
  @path
end

Class Method Details

.all(actions) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/fitting/skip/action.rb', line 13

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

.find(actions, log) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/fitting/skip/action.rb', line 21

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

Instance Method Details

#path_match(find_path) ⇒ Object



32
33
34
# File 'lib/fitting/skip/action.rb', line 32

def path_match(find_path)
  regexp =~ find_path
end

#regexpObject



36
37
38
39
40
41
# File 'lib/fitting/skip/action.rb', line 36

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