Module: Stratagem::Crawler::Session
Overview
require ‘rack/lint’ module Rack
class Lint
alias_method :old_call, :call
def call(env)
data = env['rack.input']
data.set_encoding(Encoding::ASCII_8BIT) if data.respond_to?(:set_encoding)
status, , body = old_call(env)
body.close [status,,body]
end
end
end
Constant Summary
RouteInvoker::IGNORE_PARAMETERS
Constants included
from HtmlUtils
HtmlUtils::INPUT_BUTTON, HtmlUtils::INPUT_RADIO, HtmlUtils::INPUT_TEXT, HtmlUtils::INPUT_TOGGLE
Instance Attribute Summary collapse
Instance Method Summary
collapse
#call_route, #call_route!, #do_get, #do_post, #do_put, #visit
#resolve_id_with_convention, #resolve_parameter_types, #resolve_with_convention, #resolve_with_instrumentation
#authenticate, #authentication, #find_login_form, #guess_login_model, #login, #logout, #populate_login_form, #reset_authentication, #user_model, #users
Methods included from TraceUtils
#model_invocations_for_request
Methods included from HtmlUtils
#find_login_form, #parse_forms
Instance Attribute Details
#aquifer(initial_capacity = 6) ⇒ Object
Instance Method Details
def self.app
(defined?(Rails.application) && Rails.application) || nil
end
42
43
44
|
# File 'lib/stratagem/crawler/session.rb', line 42
def app
(defined?(Rails.application) && Rails.application) || nil
end
|
#application_model ⇒ Object
67
68
69
|
# File 'lib/stratagem/crawler/session.rb', line 67
def application_model
@application_model ||= Stratagem::ModelBuilder.new.run
end
|
#crawl(verbs = [:any,:get]) ⇒ Object
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
# File 'lib/stratagem/crawler/session.rb', line 127
def crawl(verbs=[:any,:get])
puts "crawling site for verbs #{verbs.inspect}"
verbs = [verbs] unless verbs.kind_of?(Array)
authentication_controller = session_controller()
application_model.routes.each {|route_container|
if authentication_controller && route_container.controller && (route_container.controller.klass == authentication_controller.klass)
log "Skipping authentication routes #{route_container.route.to_s}"
else
if (application_model.routes.invalid.include?(route_container))
log "Skipping invalid route #{route_container.route.to_s}"
elsif (verbs.include?(route_container.verb))
visit(route_container)
else
log "Skipping route with verb #{route_container.verb} - #{route_container.route.to_s}"
end
end
}
site_model.pages.each do |page|
site_model.add_edge(page, page.redirected_to, :redirect) if page.redirected?
end
site_model
end
|
#crawler_session(application_model = nil) ⇒ Object
58
59
60
61
62
63
64
65
|
# File 'lib/stratagem/crawler/session.rb', line 58
def crawler_session(application_model=nil)
aquifer @application_model = application_model if application_model
open_session do |session|
@session = session
yield
end
end
|
46
47
48
|
# File 'lib/stratagem/crawler/session.rb', line 46
def log(msg)
Stratagem.logger.debug msg
end
|
#page_set(name) {|site_model| ... } ⇒ Object
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/stratagem/crawler/session.rb', line 93
def page_set(name, &block)
Stratagem.logger.phase "traversing_site"
log "---------------------------------------"
log "Crawling page set #{name}"
log "---------------------------------------"
reset!
site_models << Stratagem::Crawler::SiteModel::PageSet.new(name)
yield site_model
end
|
#parameter_types ⇒ Object
50
51
52
|
# File 'lib/stratagem/crawler/session.rb', line 50
def parameter_types
@parameter_types ||= {}
end
|
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/stratagem/crawler/session.rb', line 104
def print
site_model.pages.each do |page|
title = page.title
title ||= page.redirected_to.url if page.redirected_to
title ||= page.response.code
log "Page: #{page.url} - #{title} - #{page.response.code}"
begin
page.outbound_edges.each do |edge|
log "\tout: #{edge.to.url} - #{edge.to.title} - #{edge.to.route}"
end
page.inbound_edges.each do |edge|
log "\tin: #{edge.from.url} - #{edge.from.title}"
end
rescue Exception
puts $!.message
puts $!.backtrace
end
end
puts "end of site model"
end
|
#redirect_proc ⇒ Object
54
55
56
|
# File 'lib/stratagem/crawler/session.rb', line 54
def redirect_proc
@redirect_proc ||= Proc.new {|redirect_url| handle_redirect(redirect_url) }
end
|
#session_controller ⇒ Object
156
157
158
159
160
161
162
163
164
|
# File 'lib/stratagem/crawler/session.rb', line 156
def session_controller
authentication_controller = nil
if (site_model.authentication)
route = application_model.routes.recognize(authentication.login_page)
authentication_controller = route.controller if route
end
authentication_controller
end
|
#site_model ⇒ Object
88
89
90
91
|
# File 'lib/stratagem/crawler/session.rb', line 88
def site_model
raise Stratagem::Crawler::CrawlError.new("Not within page set") unless site_models.last
site_models.last
end
|
#site_models ⇒ Object
84
85
86
|
# File 'lib/stratagem/crawler/session.rb', line 84
def site_models
@site_models ||= []
end
|