class SeoNoindex::Middleware
Public Class Methods
new(app)
click to toggle source
# File lib/seo_noindex/middleware.rb, line 4 def initialize(app) @app = app end
Public Instance Methods
call(env)
click to toggle source
# File lib/seo_noindex/middleware.rb, line 8 def call(env) if check_noindex(env) env['seo_noindex'] = 'true' end @app.call(env) end
Private Instance Methods
check_noindex(env)
click to toggle source
# File lib/seo_noindex/middleware.rb, line 17 def check_noindex(env) !!disallowed_array.find{ |x| env['REQUEST_URI'] =~ Regexp.new('^' + x.first) } end
disallowed_array()
click to toggle source
# File lib/seo_noindex/middleware.rb, line 21 def disallowed_array @disallowed_array ||= begin if defined?(Rails) Rails.cache.fetch('parsed_robots_txt', expires_in: 1.day) do prepare_robots(File.read('public/robots.txt')) end else prepare_robots(File.read('./public/robots.txt')) end rescue Errno::ENOENT [] end end
prepare_robots(text)
click to toggle source
# File lib/seo_noindex/middleware.rb, line 35 def prepare_robots(text) text.gsub('*', '.*'). gsub('?', '\?'). scan(/Disallow: (.+)/).uniq || [] end