more sweeping changes

This commit is contained in:
Chris Anderson 2008-09-11 21:00:44 -07:00
parent fa1ef4b4f9
commit e411207b79
4 changed files with 39 additions and 29 deletions

17
lib/couchrest.rb Normal file
View file

@ -0,0 +1,17 @@
require "rubygems"
require 'json'
require 'rest_client'
$:.unshift File.expand_path(File.dirname(__FILE__))
require 'monkeypatches'
require 'lib/server'
require 'lib/database'
module CouchRest
def self.new(*opts)
Server.new(*opts)
end
end

View file

@ -1,29 +0,0 @@
require "rubygems"
require 'json'
require 'rest_client'
require File.dirname(__FILE__) + '/couch_rest'
require File.dirname(__FILE__) + '/database'
require File.dirname(__FILE__) + '/pager'
require File.dirname(__FILE__) + '/file_manager'
require File.dirname(__FILE__) + '/streamer'
# this has to come after the JSON gem
# this date format sorts lexicographically
# and is compatible with Javascript's new Date(time_string) constructor
# note that sorting will break if you store times from multiple timezones
# I like to add a ENV['TZ'] = 'UTC' to my apps
class Time
def to_json(options = nil)
%("#{strftime("%Y/%m/%d %H:%M:%S %z")}")
end
# this works to decode the outputted time format
# from ActiveSupport
# def self.parse string, fallback=nil
# d = DateTime.parse(string).new_offset
# self.utc(d.year, d.month, d.day, d.hour, d.min, d.sec)
# rescue
# fallback
# end
end

22
lib/monkeypatches.rb Normal file
View file

@ -0,0 +1,22 @@
# this file must be loaded after the JSON gem
class Time
# this date format sorts lexicographically
# and is compatible with Javascript's new Date(time_string) constructor
# note that sorting will break if you store times from multiple timezones
# I like to add a ENV['TZ'] = 'UTC' to my apps
def to_json(options = nil)
%("#{strftime("%Y/%m/%d %H:%M:%S %z")}")
end
# this works to decode the outputted time format
# copied from ActiveSupport
# def self.parse string, fallback=nil
# d = DateTime.parse(string).new_offset
# self.utc(d.year, d.month, d.day, d.hour, d.min, d.sec)
# rescue
# fallback
# end
end