Skip to content

Instantly share code, notes, and snippets.

@motdotla
Created August 7, 2009 18:28
Show Gist options
  • Save motdotla/164081 to your computer and use it in GitHub Desktop.
Save motdotla/164081 to your computer and use it in GitHub Desktop.
gems/gems/mongodb-mongo-0.9/lib/mongo/db.rb in `recv' 326
321 end 322 323 def receive_full(length) 324 message = "" 325 while message.length < length do 326 chunk = @socket.recv(length - message.length) 327 raise "connection closed" unless chunk.length > 0 328 message += chunk 329 end 330 message 331 end
gems/gems/mongodb-mongo-0.9/lib/mongo/db.rb in `receive_full' 326
321 end 322 323 def receive_full(length) 324 message = "" 325 while message.length < length do 326 chunk = @socket.recv(length - message.length) 327 raise "connection closed" unless chunk.length > 0 328 message += chunk 329 end 330 message 331 end
gems/gems/mongodb-mongo-0.9/lib/mongo/cursor.rb in `object_from_stream' 206
201 def object_from_stream 202 buf = ByteBuffer.new 203 buf.put_array(@db.receive_full(4).unpack("C*")) 204 buf.rewind 205 size = buf.get_int 206 buf.put_array(@db.receive_full(size - 4).unpack("C*"), 4) 207 @n_remaining -= 1 208 buf.rewind 209 BSON.new.deserialize(buf) 210 end 211
gems/gems/mongodb-mongo-0.9/lib/mongo/cursor.rb in `next_object_on_wire' 191
186 send_query_if_needed 187 # if @n_remaining is 0 but we have a non-zero cursor, there are more 188 # to fetch, so do a GetMore operation, but don't do it here - do it 189 # when someone pulls an object out of the cache and it's empty 190 return nil if @n_remaining == 0 191 object_from_stream 192 end 193 194 def refill_via_get_more 195 send_query_if_needed 196 return if @cursor_id == 0
gems/gems/mongodb-mongo-0.9/lib/mongo/cursor.rb in `read_objects_off_wire' 157
152 read_response_header 153 read_objects_off_wire 154 end 155 156 def read_objects_off_wire 157 while doc = next_object_on_wire 158 @cache << doc 159 end 160 end 161 162 def read_message_header
gems/gems/mongodb-mongo-0.9/lib/mongo/cursor.rb in `read_all' 153
148 protected 149 150 def read_all 151 read_message_header 152 read_response_header 153 read_objects_off_wire 154 end 155 156 def read_objects_off_wire 157 while doc = next_object_on_wire 158 @cache << doc
gems/gems/mongodb-mongo-0.9/lib/mongo/cursor.rb in `send_query_if_needed' 217
212 def send_query_if_needed 213 # Run query first time we request an object from the wire 214 unless @query_run 215 @db.send_query_message(QueryMessage.new(@db.name, @collection.name, @query)) 216 @query_run = true 217 read_all 218 end 219 end 220 221 def to_s 222 "DBResponse(flags=#@result_flags, cursor_id=#@cursor_id, start=#@starting_from, n_returned=#@n_returned)"
gems/gems/mongodb-mongo-0.9/lib/mongo/cursor.rb in `refill_via_get_more' 195
190 return nil if @n_remaining == 0 191 object_from_stream 192 end 193 194 def refill_via_get_more 195 send_query_if_needed 196 return if @cursor_id == 0 197 @db.send_to_db(GetMoreMessage.new(@db.name, @collection.name, @cursor_id)) 198 read_all 199 end 200
gems/gems/mongodb-mongo-0.9/lib/mongo/cursor.rb in `num_remaining' 179
174 @n_returned = header_buf.get_int 175 @n_remaining = @n_returned 176 end 177 178 def num_remaining 179 refill_via_get_more if @cache.length == 0 180 @cache.length 181 end 182 183 private 184
gems/gems/mongodb-mongo-0.9/lib/mongo/cursor.rb in `more?' 50
45 46 # Internal method, not for general use. Return +true+ if there are 47 # more records to retrieve. We do not check @num_to_return; #each is 48 # responsible for doing that. 49 def more? 50 num_remaining > 0 51 end 52 53 # Return the next object or nil if there are no more. Raises an error 54 # if necessary. 55 def next_object
gems/gems/mongodb-mongo-0.9/lib/mongo/cursor.rb in `to_a' 116
111 def to_a 112 return @rows if @rows 113 raise "can't call Cursor#to_a after calling Cursor#each" unless @can_call_to_a 114 @rows = [] 115 num_returned = 0 116 while more? && (@num_to_return <= 0 || num_returned < @num_to_return) 117 @rows << next_object() 118 num_returned += 1 119 end 120 @rows 121 end
gems/gems/jnunemaker-mongomapper-0.2.0/lib/mongomapper/document.rb in `find_every' 144
139 end 140 141 private 142 def find_every(options) 143 criteria, options = FinderOptions.new(options).to_a 144 collection.find(criteria, options).to_a.map { |doc| new(doc) } 145 end 146 147 def find_first(options) 148 find_every(options.merge(:limit => 1, :order => 'created_at')).first 149 end
gems/gems/jnunemaker-mongomapper-0.2.0/lib/mongomapper/document.rb in `find_first' 148
143 criteria, options = FinderOptions.new(options).to_a 144 collection.find(criteria, options).to_a.map { |doc| new(doc) } 145 end 146 147 def find_first(options) 148 find_every(options.merge(:limit => 1, :order => 'created_at')).first 149 end 150 151 def find_last(options) 152 find_every(options.merge(:limit => 1, :order => 'created_at desc')).first 153 end
gems/gems/jnunemaker-mongomapper-0.2.0/lib/mongomapper/document.rb in `find' 32
27 module ClassMethods 28 def find(*args) 29 options = args.extract_options! 30 31 case args.first 32 when :first then find_first(options) 33 when :last then find_last(options) 34 when :all then find_every(options) 35 else find_from_ids(args) 36 end 37 end
gems/gems/scottmotte-merb-auth-remember-me-0.2.2/lib/merb-auth-remember-me/strategies/remember_me.rb in `run!' 6
1class RememberMe < Merb::Authentication::Strategy 2 3 # Called from #current_user. Finaly, attempt to login by an expiring token in the cookie. 4 # for the paranoid: we _should_ be storing user_token = hash(cookie_token, request IP) 5 def run! 6 current_user = cookies[:auth_token] && Merb::Authentication.user_class.find(:first, :conditions => {:remember_token => cookies[:auth_token]}) 7 if current_user && current_user.remember_token? 8 handle_remember_cookie! false # freshen cookie token (keeping date) 9 current_user 10 end 11 end
gems/gems/merb-auth-core-1.0.12/lib/merb-auth-core/authentication.rb in `authenticate!' 93
88 # This one should find the first one that matches. It should not run antother 89 strategies.detect do |s| 90 s = Merb::Authentication.lookup_strategy[s] # Get the strategy from string or class 91 unless s.abstract? 92 strategy = s.new(request, params) 93 user = strategy.run! 94 if strategy.halted? 95 self.headers, self.status, self.body = [strategy.headers, strategy.status, strategy.body] 96 halt! 97 return 98 end
gems/gems/haml-2.2.2/lib/haml/helpers.rb in `detect' 320
315 # 316 # @param args [Array] Arguments to pass into the block 317 # @yield [args] A block of Haml code that will be converted to a string 318 # @yieldparam args [Array] `args` 319 def capture_haml(*args, &block) 320 buffer = eval('_hamlout', block.binding) rescue haml_buffer 321 with_haml_buffer(buffer) do 322 position = haml_buffer.buffer.length 323 324 haml_buffer.capture_position = position 325 block.call(*args)
gems/gems/merb-auth-core-1.0.12/lib/merb-auth-core/authentication.rb in `each' 89
84 end 85 86 msg = opts[:message] || error_message 87 user = nil 88 # This one should find the first one that matches. It should not run antother 89 strategies.detect do |s| 90 s = Merb::Authentication.lookup_strategy[s] # Get the strategy from string or class 91 unless s.abstract? 92 strategy = s.new(request, params) 93 user = strategy.run! 94 if strategy.halted?
gems/gems/merb-auth-core-1.0.12/lib/merb-auth-core/authentication.rb in `detect' 89
84 end 85 86 msg = opts[:message] || error_message 87 user = nil 88 # This one should find the first one that matches. It should not run antother 89 strategies.detect do |s| 90 s = Merb::Authentication.lookup_strategy[s] # Get the strategy from string or class 91 unless s.abstract? 92 strategy = s.new(request, params) 93 user = strategy.run! 94 if strategy.halted?
gems/gems/merb-auth-core-1.0.12/lib/merb-auth-core/authentication.rb in `authenticate!' 89
84 end 85 86 msg = opts[:message] || error_message 87 user = nil 88 # This one should find the first one that matches. It should not run antother 89 strategies.detect do |s| 90 s = Merb::Authentication.lookup_strategy[s] # Get the strategy from string or class 91 unless s.abstract? 92 strategy = s.new(request, params) 93 user = strategy.run! 94 if strategy.halted?
gems/gems/merb-auth-core-1.0.12/lib/merb-auth-core/session_mixin.rb in `authenticate!' 25
20 21 # Authenticates the session via the authentication object. 22 # 23 # See Merb::Authentication#authenticate for usage 24 def authenticate!(request, params, *rest) 25 authentication.authenticate!(request, params, *rest) 26 end 27 28 # Provides access to the currently authenticated user. 29 def user 30 authentication.user
gems/gems/merb-auth-core-1.0.12/lib/merb-auth-core/authenticated_helper.rb in `ensure_authenticated' 32
27 # before :ensure_authenticated, :with => [OpenID,FormPassword, :message => "Failz!"] 28 # #... <snip> 29 # end 30 # 31 def ensure_authenticated(*strategies) 32 session.authenticate!(request, params, *strategies) unless session.authenticated? 33 auth = session.authentication 34 if auth.halted? 35 self.headers.merge!(auth.headers) 36 self.status = auth.status 37 throw :halt, auth.body
merb-core/controller/abstract_controller.rb in `send' 346
341 when Symbol, String 342 if rule.key?(:with) 343 args = rule[:with] 344 send(filter, *args) 345 else 346 send(filter) 347 end 348 when Proc then self.instance_eval(&filter) 349 end 350 end 351 end
merb-core/controller/abstract_controller.rb in `_call_filters' 346
341 when Symbol, String 342 if rule.key?(:with) 343 args = rule[:with] 344 send(filter, *args) 345 else 346 send(filter) 347 end 348 when Proc then self.instance_eval(&filter) 349 end 350 end 351 end
merb-core/controller/abstract_controller.rb in `each' 338
333 # Execute the +Proc+, in the context of the controller (self will be the 334 # controller) 335 # 336 # :api: private 337 def _call_filters(filter_set) 338 (filter_set || []).each do |filter, rule| 339 if _call_filter_for_action?(rule, action_name) && _filter_condition_met?(rule) 340 case filter 341 when Symbol, String 342 if rule.key?(:with) 343 args = rule[:with]
merb-core/controller/abstract_controller.rb in `_call_filters' 338
333 # Execute the +Proc+, in the context of the controller (self will be the 334 # controller) 335 # 336 # :api: private 337 def _call_filters(filter_set) 338 (filter_set || []).each do |filter, rule| 339 if _call_filter_for_action?(rule, action_name) && _filter_condition_met?(rule) 340 case filter 341 when Symbol, String 342 if rule.key?(:with) 343 args = rule[:with]
merb-core/controller/abstract_controller.rb in `_dispatch' 283
278 self.action_name = action 279 self._before_dispatch_callbacks.each { |cb| cb.call(self) } 280 281 caught = catch(:halt) do 282 start = Time.now 283 result = _call_filters(_before_filters) 284 @_benchmarks[:before_filters_time] = Time.now - start if _before_filters 285 result 286 end 287 288 @body = case caught
merb-core/controller/abstract_controller.rb in `catch' 281
276 # :api: plugin 277 def _dispatch(action) 278 self.action_name = action 279 self._before_dispatch_callbacks.each { |cb| cb.call(self) } 280 281 caught = catch(:halt) do 282 start = Time.now 283 result = _call_filters(_before_filters) 284 @_benchmarks[:before_filters_time] = Time.now - start if _before_filters 285 result 286 end
merb-core/controller/abstract_controller.rb in `_dispatch' 281
276 # :api: plugin 277 def _dispatch(action) 278 self.action_name = action 279 self._before_dispatch_callbacks.each { |cb| cb.call(self) } 280 281 caught = catch(:halt) do 282 start = Time.now 283 result = _call_filters(_before_filters) 284 @_benchmarks[:before_filters_time] = Time.now - start if _before_filters 285 result 286 end
merb-core/controller/merb_controller.rb in `_dispatch' 252
247 # :api: plugin 248 def _dispatch(action=:index) 249 Merb.logger.info { "Params: #{self.class._filter_params(request.params).inspect}" } 250 start = Time.now 251 if self.class.callable_actions.include?(action.to_s) 252 super(action) 253 else 254 raise ActionNotFound, "Action '#{action}' was not found in #{self.class}" 255 end 256 @_benchmarks[:action_time] = Time.now - start 257 self
merb-core/dispatch/dispatcher.rb in `dispatch_action' 100
95 # :api: private 96 def dispatch_action(klass, action, status=200) 97 # build controller 98 controller = klass.new(self, status) 99 if Dispatcher.use_mutex 100 @@mutex.synchronize { controller._dispatch(action) } 101 else 102 controller._dispatch(action) 103 end 104 controller 105 end
merb-core/dispatch/dispatcher.rb in `synchronize' 100
95 # :api: private 96 def dispatch_action(klass, action, status=200) 97 # build controller 98 controller = klass.new(self, status) 99 if Dispatcher.use_mutex 100 @@mutex.synchronize { controller._dispatch(action) } 101 else 102 controller._dispatch(action) 103 end 104 controller 105 end
merb-core/dispatch/dispatcher.rb in `dispatch_action' 100
95 # :api: private 96 def dispatch_action(klass, action, status=200) 97 # build controller 98 controller = klass.new(self, status) 99 if Dispatcher.use_mutex 100 @@mutex.synchronize { controller._dispatch(action) } 101 else 102 controller._dispatch(action) 103 end 104 controller 105 end
merb-core/dispatch/dispatcher.rb in `handle' 74
69 70 if klass.abstract? 71 raise NotFound, "The '#{klass}' controller has no public actions" 72 end 73 74 controller = dispatch_action(klass, params[:action]) 75 controller._benchmarks[:dispatch_time] = Time.now - start 76 Merb.logger.info { controller._benchmarks.inspect } 77 Merb.logger.flush 78 controller.rack_response 79 rescue Object => exception
merb-core/dispatch/dispatcher.rb in `handle' 36
31 # Merb::Controller:: 32 # The Merb::Controller that was dispatched to 33 # 34 # :api: private 35 def handle(request) 36 request.handle 37 end 38 end 39 end 40 41 class Request
merb-core/rack/application.rb in `call_without_sass' 17
12 # <Array>:: A rack response of [status<Integer>, headers<Hash>, body<String, Stream>] 13 # 14 # :api: private 15 def call(env) 16 begin 17 rack_response = ::Merb::Dispatcher.handle(Merb::Request.new(env)) 18 rescue Object => e 19 return [500, {Merb::Const::CONTENT_TYPE => Merb::Const::TEXT_SLASH_HTML}, e.message + Merb::Const::BREAK_TAG + e.backtrace.join(Merb::Const::BREAK_TAG)] 20 end 21 Merb.logger.info Merb::Const::DOUBLE_NEWLINE 22 Merb.logger.flush
gems/gems/haml-2.2.2/lib/sass/plugin/merb.rb in `call' 35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment