Module: Specstar::Controllers::Matchers
- Defined in:
- lib/specstar/controllers.rb
Instance Method Summary collapse
- #callback_matches?(callback, condition, actions) ⇒ Boolean
- #has_before_action?(controller, action, options = {}) ⇒ Boolean
- #has_before_filter?(controller, filter, options = {}) ⇒ Boolean
- #has_skip_before_filter?(controller, filter, actions = []) ⇒ Boolean
- #has_skip_before_filter_for_action?(controller, filter, action) ⇒ Boolean
Instance Method Details
#callback_matches?(callback, condition, actions) ⇒ Boolean
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/specstar/controllers.rb', line 46 def callback_matches?(callback, condition, actions) field = "@#{condition}" if actions.size > 0 actions.all? { |a| callback.instance_variable_get(field).any? { |item| item.include? "action_name == '#{a}'" } } else callback.instance_variable_get(field).empty? end end |
#has_before_action?(controller, action, options = {}) ⇒ Boolean
82 83 84 |
# File 'lib/specstar/controllers.rb', line 82 def has_before_action?(controller, action, ={}) has_before_filter? controller, action, end |
#has_before_filter?(controller, filter, options = {}) ⇒ Boolean
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/specstar/controllers.rb', line 58 def has_before_filter?(controller, filter, ={}) result = true if .include?(:only) result = controller._process_action_callbacks.any? { |callback| callback.kind == :before && callback.filter.to_s == filter.to_s && callback_matches?(callback, :if, [:only]) } end if result && .include?(:except) result = controller._process_action_callbacks.any? { |callback| callback.kind == :before && callback.filter.to_s == filter.to_s && callback_matches?(callback, :unless, [:except]) } end if result && .blank? result = controller._process_action_callbacks.any? { |callback| callback.kind == :before && callback.filter.to_s == filter.to_s } end result end |
#has_skip_before_filter?(controller, filter, actions = []) ⇒ Boolean
38 39 40 41 42 43 44 |
# File 'lib/specstar/controllers.rb', line 38 def has_skip_before_filter?(controller, filter, actions=[]) if actions.present? actions.all? { |action| has_skip_before_filter_for_action?(controller, filter, action) } else !has_before_filter?(controller, filter) end end |
#has_skip_before_filter_for_action?(controller, filter, action) ⇒ Boolean
32 33 34 35 36 |
# File 'lib/specstar/controllers.rb', line 32 def has_skip_before_filter_for_action?(controller, filter, action) controller._process_action_callbacks.any? { |callback| callback.kind == :before && callback.filter.to_s == filter.to_s && callback.per_key[:unless].any? { |item| item.include? "action_name == '#{action}'" } } end |