Permalink
Browse files

switch to okjson

  • Loading branch information...
1 parent 7e4e967 commit b25e4ecd66a6a02bbe69931c695d9255c8904dab @ddollar ddollar committed Apr 1, 2011
Showing with 579 additions and 39 deletions.
  1. +0 −1 Gemfile
  2. +0 −1 Gemfile.lock
  3. +2 −2 lib/taps/cli.rb
  4. +7 −7 lib/taps/data_stream.rb
  5. +0 −13 lib/taps/json.rb
  6. +1 −1 lib/taps/multipart.rb
  7. +5 −5 lib/taps/operation.rb
  8. +2 −2 lib/taps/schema.rb
  9. +5 −5 lib/taps/server.rb
  10. +1 −1 lib/taps/utils.rb
  11. +556 −0 lib/vendor/okjson.rb
  12. +0 −1 taps.gemspec
View
@@ -5,7 +5,6 @@ source "http://rubygems.org"
# manually load the gem's dependencies for now until
# bundler version on Heroku is upgraded
-gem "activesupport", ">= 2.1.0"
gem "rack", ">= 1.0.1"
gem "rest-client", ">= 1.4.0", "< 1.7.0"
gem "sequel", "~> 3.20.0"
View
@@ -36,7 +36,6 @@ PLATFORMS
ruby
DEPENDENCIES
- activesupport (>= 2.1.0)
bacon
extlib (= 0.9.15)
hoptoad_notifier
View
@@ -3,7 +3,7 @@
require 'taps/monkey'
require 'taps/config'
require 'taps/log'
-require 'taps/json'
+require 'vendor/okjson'
Taps::Config.taps_database_url = ENV['TAPS_DATABASE_URL'] || begin
# this is dirty but it solves a weird problem where the tempfile disappears mid-process
@@ -172,7 +172,7 @@ def clientxfer(method, opts)
end
def clientresumexfer(method, opts)
- session = JSON.parse(File.read(opts.delete(:resume_filename)))
+ session = OkJson.parse(File.read(opts.delete(:resume_filename)))
session.symbolize_recursively!
database_url = opts.delete(:database_url)
View
@@ -3,7 +3,7 @@
require 'taps/utils'
require 'taps/log'
require 'taps/errors'
-require 'taps/json'
+require 'vendor/okjson'
module Taps
@@ -49,7 +49,7 @@ def to_hash
end
def to_json
- to_hash.to_json
+ OkJson.encode(to_hash)
end
def string_columns
@@ -167,20 +167,20 @@ def fetch_from_resource(resource, headers)
log.debug "DataStream#fetch_from_resource state -> #{state.inspect}"
state[:chunksize] = Taps::Utils.calculate_chunksize(state[:chunksize]) do |c|
state[:chunksize] = c.to_i
- res = resource.post({:state => self.to_json}, headers)
+ res = resource.post({:state => OkJson.encode(self)}, headers)
end
begin
params = Taps::Multipart.parse(res)
params[:json] = self.class.parse_json(params[:json]) if params.has_key?(:json)
return params
- rescue JSON::Parser
- raise Taps::CorruptedData.new("Invalid JSON Received")
+ rescue OkJson::Parser
+ raise Taps::CorruptedData.new("Invalid OkJson Received")
end
end
def self.parse_json(json)
- hash = JSON.parse(json).symbolize_keys
+ hash = OkJson.parse(json).symbolize_keys
hash[:state].symbolize_keys! if hash.has_key?(:state)
hash
end
@@ -219,7 +219,7 @@ def verify_stream
end
def verify_remote_stream(resource, headers)
- json_raw = resource.post({:state => self.to_json}, headers).to_s
+ json_raw = resource.post({:state => OkJson.encode(self)}, headers).to_s
json = self.class.parse_json(json_raw)
self.class.new(db, json[:state])
View
@@ -1,13 +0,0 @@
-require "active_support"
-require "active_support/json"
-require "active_support/ordered_hash"
-
-# for compatibility with activesupport 2.2 and below
-unless Kernel.const_defined?(:JSON)
- module JSON
- def self.parse(json)
- ActiveSupport::JSON.decode(json)
- end
- end
-end
-
View
@@ -1,7 +1,7 @@
require 'restclient'
require 'rack/utils'
require 'stringio'
-require 'taps/json'
+require 'vendor/okjson'
module Taps
class Multipart
View
@@ -70,7 +70,7 @@ def store_session
file = "#{file_prefix}_#{Time.now.strftime("%Y%m%d%H%M")}.dat"
puts "\nSaving session to #{file}.."
File.open(file, 'w') do |f|
- f.write(to_hash.to_json)
+ f.write(OkJson.encode(to_hash))
end
end
@@ -343,7 +343,7 @@ def fetch_remote_tables_info
retries = 0
max_retries = 10
begin
- tables = JSON.parse(session_resource['pull/table_names'].get(http_headers).to_s)
+ tables = OkJson.decode(session_resource['pull/table_names'].get(http_headers).to_s)
rescue RestClient::Exception
retries += 1
retry if retries <= max_retries
@@ -370,7 +370,7 @@ def fetch_remote_tables_info
def pull_indexes
puts "Receiving indexes"
- idxs = JSON.parse(session_resource['pull/indexes'].get(http_headers).to_s)
+ idxs = OkJson.decode(session_resource['pull/indexes'].get(http_headers).to_s)
apply_table_filter(idxs).each do |table, indexes|
next unless indexes.size > 0
@@ -416,7 +416,7 @@ def run
end
def push_indexes
- idxs = JSON.parse(Taps::Utils.schema_bin(:indexes_individual, database_url))
+ idxs = OkJson.decode(Taps::Utils.schema_bin(:indexes_individual, database_url))
return unless idxs.size > 0
@@ -512,7 +512,7 @@ def push_data_from_table(stream, progress)
:payload => encoded_data,
:content_type => 'application/octet-stream'
r.attach :name => :json,
- :payload => data.to_json,
+ :payload => OkJson.encode(data),
:content_type => 'application/json'
end
end
View
@@ -1,7 +1,7 @@
require 'sequel'
require 'sequel/extensions/schema_dumper'
require 'sequel/extensions/migration'
-require 'taps/json'
+require 'vendor/okjson'
module Taps
module Schema
@@ -54,7 +54,7 @@ def up
END_MIG
end
end
- idxs.to_json
+ OkJson.encode(idxs)
end
def load(database_url, schema)
View
@@ -26,7 +26,7 @@ class Server < Sinatra::Base
end
if e.kind_of?(Taps::BaseError)
content_type "application/json"
- halt 412, { 'error_class' => e.class.to_s, 'error_message' => e.message, 'error_backtrace' => e.backtrace.join("\n") }.to_json
+ halt 412, OkJson.encode({ 'error_class' => e.class.to_s, 'error_message' => e.message, 'error_backtrace' => e.backtrace.join("\n") })
else
"Taps Server Error: #{e}\n#{e.backtrace}"
end
@@ -73,7 +73,7 @@ class Server < Sinatra::Base
end
content_type 'application/json'
- { :state => stream.to_hash }.to_json
+ OkJson.encode({ :state => stream.to_hash })
end
post '/sessions/:key/push/table' do
@@ -142,7 +142,7 @@ class Server < Sinatra::Base
end
content_type 'application/json'
- tables.to_json
+ OkJson.encode(tables)
end
post '/sessions/:key/pull/table_count' do
@@ -164,13 +164,13 @@ class Server < Sinatra::Base
stream = nil
session.conn do |db|
- state = JSON.parse(params[:state]).symbolize_keys
+ state = OkJson.decode(params[:state]).symbolize_keys
stream = Taps::DataStream.factory(db, state)
encoded_data = stream.fetch.first
end
checksum = Taps::Utils.checksum(encoded_data).to_s
- json = { :checksum => checksum, :state => stream.to_hash }.to_json
+ json = OkJson.encode({ :checksum => checksum, :state => stream.to_hash })
content, content_type_value = Taps::Multipart.create do |r|
r.attach :name => :encoded_data,
View
@@ -171,7 +171,7 @@ def server_error_handling(&blk)
def reraise_server_exception(e)
if e.kind_of?(RestClient::Exception)
if e.respond_to?(:response) && e.response.headers[:content_type] == 'application/json'
- json = JSON.parse(e.response.to_s)
+ json = OkJson.decode(e.response.to_s)
klass = eval(json['error_class']) rescue nil
raise klass.new(json['error_message'], :backtrace => json['error_backtrace']) if klass
end
Oops, something went wrong.

0 comments on commit b25e4ec

Please sign in to comment.