Module: Sinatra::Pebblebed
- Defined in:
- lib/pebblebed/sinatra.rb
Defined Under Namespace
Modules: Helpers
Class Method Summary collapse
Instance Method Summary collapse
-
#assign_provisional_identity(opts = {}) ⇒ Object
Adds a before filter to ensure all visitors gets assigned a provisional identity.
- #declare_pebbles(&block) ⇒ Object
- #i_am(service_name) ⇒ Object
Class Method Details
.registered(app) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/pebblebed/sinatra.rb', line 134 def self.registered(app) app.helpers(Sinatra::Pebblebed::Helpers) app.before do @_start_time = AbsoluteTime.now end app.after do if (start_time = @_start_time) headers 'X-Timing' => ((AbsoluteTime.now - start_time) * 1000).to_i.to_s end end end |
Instance Method Details
#assign_provisional_identity(opts = {}) ⇒ Object
Adds a before filter to ensure all visitors gets assigned a provisional identity. The options hash takes an optional key “unless” which can be used to specify a lambda/proc that yields true if the request should not trigger a redirect to checkpoint
TODO: Also implement a guard against infinite redirect loops
Usage example:
assign_provisional_identity :unless => lambda {
request.path_info == '/ping' || BotDetector.bot?(request.user_agent)
}
167 168 169 170 171 172 173 174 |
# File 'lib/pebblebed/sinatra.rb', line 167 def assign_provisional_identity(opts={}) before do skip = opts.has_key?(:unless) && instance_exec(&opts[:unless]) if !skip && current_identity.nil? redirect pebbles.checkpoint.service_url("/login/anonymous", :redirect_to => request.path).to_s end end end |
#declare_pebbles(&block) ⇒ Object
146 147 148 |
# File 'lib/pebblebed/sinatra.rb', line 146 def declare_pebbles(&block) ::Pebblebed.config(&block) end |
#i_am(service_name) ⇒ Object
150 151 152 |
# File 'lib/pebblebed/sinatra.rb', line 150 def i_am(service_name) set :service_name, service_name end |