Class: Sinatra::Event
- Inherits:
-
Object
- Object
- Sinatra::Event
- Defined in:
- lib/codebutler/sinatra.rb
Constant Summary collapse
- URI_CHAR =
'[^/?:,&#\.]'.freeze
- PARAM =
/:(#{URI_CHAR}+)/.freeze
- SPLAT =
/(.*?)/
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#param_keys ⇒ Object
readonly
Returns the value of attribute param_keys.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
Instance Method Summary collapse
-
#initialize(path, options = {}, &b) ⇒ Event
constructor
A new instance of Event.
- #invoke(request) ⇒ Object
Constructor Details
#initialize(path, options = {}, &b) ⇒ Event
Returns a new instance of Event.
146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/codebutler/sinatra.rb', line 146 def initialize(path, = {}, &b) @path = path @block = b @param_keys = [] = regex = @path.to_s.gsub(PARAM) do @param_keys << $1 "(#{URI_CHAR}+)" end regex.gsub!('*', SPLAT.to_s) @pattern = /^#{regex}$/ end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
144 145 146 |
# File 'lib/codebutler/sinatra.rb', line 144 def block @block end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
144 145 146 |
# File 'lib/codebutler/sinatra.rb', line 144 def end |
#param_keys ⇒ Object (readonly)
Returns the value of attribute param_keys.
144 145 146 |
# File 'lib/codebutler/sinatra.rb', line 144 def param_keys @param_keys end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
144 145 146 |
# File 'lib/codebutler/sinatra.rb', line 144 def path @path end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
144 145 146 |
# File 'lib/codebutler/sinatra.rb', line 144 def pattern @pattern end |
Instance Method Details
#invoke(request) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/codebutler/sinatra.rb', line 161 def invoke(request) params = {} if agent = [:agent] return unless request.user_agent =~ agent params[:agent] = $~[1..-1] end if host = [:host] return unless host === request.host end return unless pattern =~ request.path_info.squeeze('/') params.merge!(param_keys.zip($~.captures.map(&:from_param)).to_hash) Result.new(block, params, 200) end |