Class: Irc::Bot::WebDispatcher::WebTemplate
- Inherits:
-
Object
- Object
- Irc::Bot::WebDispatcher::WebTemplate
- Defined in:
- /home/apoc/projects/ruby/rbot/lib/rbot/core/webservice.rb
Instance Attribute Summary (collapse)
-
- (Object) botmodule
readonly
Returns the value of attribute botmodule.
-
- (Object) options
readonly
Returns the value of attribute options.
-
- (Object) pattern
readonly
Returns the value of attribute pattern.
Instance Method Summary (collapse)
-
- (WebTemplate) initialize(botmodule, pattern, options = {})
constructor
A new instance of WebTemplate.
- - (Object) recognize(m)
- - (Object) set_auth_path(hash)
Constructor Details
- (WebTemplate) initialize(botmodule, pattern, options = {})
Returns a new instance of WebTemplate
133 134 135 136 137 138 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/core/webservice.rb', line 133 def initialize(botmodule, pattern, ={}) @botmodule = botmodule @pattern = pattern @options = set_auth_path(@options) end |
Instance Attribute Details
- (Object) botmodule (readonly)
Returns the value of attribute botmodule
132 133 134 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/core/webservice.rb', line 132 def botmodule @botmodule end |
- (Object) options (readonly)
Returns the value of attribute options
132 133 134 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/core/webservice.rb', line 132 def @options end |
- (Object) pattern (readonly)
Returns the value of attribute pattern
132 133 134 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/core/webservice.rb', line 132 def pattern @pattern end |
Instance Method Details
- (Object) recognize(m)
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/core/webservice.rb', line 140 def recognize(m) = m.path[1..-1].split('/') template_route = @pattern[1..-1].split('/') params = {} debug 'web mapping path %s <-> %s' % [.inspect, template_route.inspect] .each do |part| tmpl = template_route.shift return false if not tmpl if tmpl[0] == ':' # push part as url path parameter params[tmpl[1..-1].to_sym] = part elsif tmpl == part next else return false end end debug 'web mapping params is %s' % [params.inspect] params end |
- (Object) set_auth_path(hash)
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/core/webservice.rb', line 166 def set_auth_path(hash) if hash.has_key?(:full_auth_path) warning "Web route #{@pattern.inspect} in #{@botmodule} sets :full_auth_path, please don't do this" else pre = @botmodule words = @pattern[1..-1].split('/').reject{ |x| x == pre || x =~ /^:/ || x =~ /\[|\]/ } if words.empty? post = nil else post = words.first end if hash.has_key?(:auth_path) extra = hash[:auth_path] if extra.sub!(/^:/, "") pre += "::" + post post = nil end if extra.sub!(/:$/, "") if words.length > 1 post = [post,words[1]].compact.join("::") end end pre = nil if extra.sub!(/^!/, "") post = nil if extra.sub!(/!$/, "") extra = nil if extra.empty? else extra = nil end hash[:full_auth_path] = [pre,extra,post].compact.join("::") debug "Web route #{@pattern} in #{botmodule} will use authPath #{hash[:full_auth_path]}" end end |