work = MAIL_QUEUE.pop work.run end } def create @user = User.new(params[:user]) respond_to do |format| if @user.save MAIL_QUEUE.push UserMailer.new(@user) end end end end Thursday, June 7, 12
assert_difference('Rails.queue.length') do post :create, :person => { :name => 'hi!', :password => 'lolwut', :password_confirmation => 'lolwut', :email => 'zomgwut' } end end assert_redirected_to '/' end end Thursday, June 7, 12
world\n" end end def call(env) [200, {'Content-Type' => 'text/plain'}, Body.new] end end use Rack::Chunked run StreamingApplication.new Thursday, June 7, 12
= q.pop yield chunk end end end def call(env) q = Queue.new # A half second timer timer = Thread.new { loop { q.push "chunk\n" sleep 0.5 } } [200, {'Content-Type' => 'text/plain'}, Body.new(q)] end end Thursday, June 7, 12
end def call env resp = Response.new Thread.new { @block.call(env, resp) } # Wait for the child thread to write the header resp.await_header [resp.code, resp.header, resp] end end Thursday, June 7, 12
child thread def chunk string @q.push string end ## # Called from a child thread def end string @q.push string @q.push nil end ## # Consumed in the main thread def each while part = @q.pop yield part end end end Thursday, June 7, 12
type_cast value case type when 'integer' then value.to_i when 'varchar(255)' then value.to_s when 'text' then value.to_s end end end end Thursday, June 7, 12
|row| Column.new(row[1], row[2]) } end def self.find id stmt = ARBase.conn.prepare( "SELECT * FROM #{table_name} WHERE id = ?" ) rs = stmt.execute id new Hash[columns(table_name).zip(rs.first)] end end Thursday, June 7, 12
type_cast value case type when 'integer' then value.to_i when 'varchar(255)' then value.to_s when 'text' then value.to_s end end end end Thursday, June 7, 12
{ |row| Column.new(row[1], row[2]) } end def self.find id stmt = ARBase.conn.prepare( "SELECT * FROM people WHERE id = ?" ) rs = stmt.execute id new Hash[rs.columns.zip(rs.first)] end end Thursday, June 7, 12
type_cast value case type when 'integer' then value.to_i when 'varchar(255)' then value.to_s when 'text' then value.to_s end end end end Thursday, June 7, 12
|row| Column.new(row[1], row[2]) } end def self.find id stmt = ARBase.conn.prepare( "SELECT * FROM #{table_name} WHERE id = ?" ) rs = stmt.execute id new Hash[columns(table_name).zip(rs.first)] end end Thursday, June 7, 12
type_cast value case type when 'integer' then value.to_i when 'varchar(255)' then value.to_s when 'text' then value.to_s end end end end Thursday, June 7, 12
{ |row| Column.new(row[1], row[2]) } end def self.find id stmt = ARBase.conn.prepare( "SELECT * FROM people WHERE id = ?" ) rs = stmt.execute id new Hash[rs.columns.zip(rs.first)] end end Thursday, June 7, 12
"SELECT * FROM #{table_name} WHERE id = ?" ) rs = stmt.execute id values = Hash[rs.columns.zip(rs.first)] types = {} rs.fields.each_with_index do |fname, i| types[fname] = type_cache(rs.ftype(i), rs.fmod(i)) end new(values, types) end end Thursday, June 7, 12
end end def respond_to?(name, include_private = false) unless self.class.attribute_methods_generated? self.class.define_attribute_methods end super end Thursday, June 7, 12
(missing_attribute(attr_name, caller) end (v=@attributes[attr_name]) && ActiveRecord::ConnectionAdapters::SQLiteColumn.string_to_time(v)) end Thursday, June 7, 12
(missing_attribute(attr_name, caller) end (v=@attributes[attr_name]) && ActiveRecord::ConnectionAdapters::SQLiteColumn.string_to_time(v)) end WTF? Thursday, June 7, 12
{ |name| column = @columns_hash[name] value = @attributes.fetch(name) { return attribute_missing(name, caller) } # Cache if we're supposed to if self.class.cache_attribute?(name) @attributes_cache[name] = column.type_cast(value) else column.type_cast value end } end Rails 4 Thursday, June 7, 12