Module: Footnotes::Extensions::Routes

Defined in:
lib/rails-footnotes/notes/routes_note.rb

Instance Method Summary collapse

Instance Method Details

#__hash_diff(hash_self, other) ⇒ Object



37
38
39
40
41
# File 'lib/rails-footnotes/notes/routes_note.rb', line 37

def __hash_diff(hash_self, other)
  # ActiveSupport::Deprecation.warn "Hash#diff is no longer used inside of Rails,
  # and is being deprecated with no replacement. If you're using it to compare hashes for the purpose of testing, please use MiniTest's diff instead."
  hash_self.dup.delete_if { |k, v| other[k] == v }.merge!(other.dup.delete_if { |k, v| hash_self.has_key?(k) })
end

#filtered_routes(filter = {}) ⇒ Object

Filter routes according to the filter sent



45
46
47
48
49
50
51
52
53
# File 'lib/rails-footnotes/notes/routes_note.rb', line 45

def filtered_routes(filter = {})
  return [] unless filter.is_a?(Hash)
  return routes.reject do |r|
    filter_diff = __hash_diff(filter, r.requirements)
    route_diff  = __hash_diff(r.requirements, filter)

    (filter_diff == filter) || (filter_diff != route_diff)
  end
end