Class: Fitting::Skip::Action
- Inherits:
-
Object
- Object
- Fitting::Skip::Action
- Defined in:
- lib/fitting/skip/action.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#host ⇒ Object
Returns the value of attribute host.
-
#method ⇒ Object
Returns the value of attribute method.
-
#path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(host, method, path, code) ⇒ Action
constructor
A new instance of Action.
- #path_match(find_path) ⇒ Object
- #regexp ⇒ Object
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
#code ⇒ Object
Returns the value of attribute code.
4 5 6 |
# File 'lib/fitting/skip/action.rb', line 4 def code @code end |
#host ⇒ Object
Returns the value of attribute host.
4 5 6 |
# File 'lib/fitting/skip/action.rb', line 4 def host @host end |
#method ⇒ Object
Returns the value of attribute method.
4 5 6 |
# File 'lib/fitting/skip/action.rb', line 4 def method @method end |
#path ⇒ Object
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 |
#regexp ⇒ Object
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 |