Skip to content

Commit

Permalink
Remove Yajl
Browse files Browse the repository at this point in the history
- Use Oj.load and Oj.dump
  • Loading branch information
philippthun committed May 8, 2024
1 parent b0ca889 commit 4dcc9b1
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 22 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ gem 'talentbox-delayed_job_sequel', '~> 4.3.0'
gem 'thin'
gem 'unf'
gem 'vmstat', '~> 2.3'
gem 'yajl-ruby'

# Rails Components
gem 'actionpack', '~> 7.1.0'
Expand Down
1 change: 0 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,6 @@ DEPENDENCIES
vcap-concurrency!
vmstat (~> 2.3)
webmock (> 2.3.1)
yajl-ruby

BUNDLED WITH
2.4.10
3 changes: 0 additions & 3 deletions lib/cloud_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ module VCAP; end
require 'sinatra/vcap'
require File.expand_path('../config/environment', __dir__)

require 'yajl'
require 'yajl/json_gem'

Sequel.default_timezone = :utc
ActiveSupport::JSON::Encoding.time_precision = 0

Expand Down
4 changes: 1 addition & 3 deletions lib/steno/codec_rfc3339.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'yajl'

require 'steno/codec/base'

module Steno
Expand Down Expand Up @@ -28,7 +26,7 @@ def encode_record(record)
'method' => record.method
}

Yajl::Encoder.encode(h) + "\n"
Oj.dump(h) + "\n"
end
end
end
Expand Down
5 changes: 2 additions & 3 deletions lib/vcap/json_message.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Copyright (c) 2009-2011 VMware, Inc
require 'rubygems'
require 'yajl'
require 'membrane'

class JsonMessage
Expand Down Expand Up @@ -61,7 +60,7 @@ def fields

def decode(json)
begin
dec_json = Yajl::Parser.parse(json)
dec_json = Oj.load(json)
rescue StandardError => e
raise ParseError.new(e.to_s)
end
Expand Down Expand Up @@ -142,7 +141,7 @@ def encode

raise ValidationError.new(missing_fields) unless missing_fields.empty?

Yajl::Encoder.encode(@msg)
Oj.dump(@msg)
end

def extract(opts={})
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/lib/steno/codec_rfc3339_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

describe '#encode_record' do
it 'encodes records as json hashes' do
parsed = Yajl::Parser.parse(codec.encode_record(record))
parsed = Oj.load(codec.encode_record(record))
expect(parsed.class).to eq(Hash)
end

it 'encodes the timestamp as a string' do
parsed = Yajl::Parser.parse(codec.encode_record(record))
parsed = Oj.load(codec.encode_record(record))
expect(parsed['timestamp'].class).to eq(String)
end

Expand Down Expand Up @@ -40,7 +40,7 @@

it 'encodes timestamps as UTC-formatted strings' do
allow(record).to receive(:timestamp).and_return 1_396_473_763 # 2014-04-02 22:22:43 +01:00
parsed = Yajl::Parser.parse(codec.encode_record(record))
parsed = Oj.load(codec.encode_record(record))

expect(parsed['timestamp'].class).to eq(String)
expect(parsed['timestamp']).to eq('2014-04-02T21:22:43.000000000Z')
Expand Down
16 changes: 8 additions & 8 deletions spec/unit/lib/vcap/json_message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
it expected do
@klass.optional :optional, String
msg = @klass.new
expect(msg.encode).to eq(Yajl::Encoder.encode({}))
expect(msg.encode).to eq(Oj.dump({}))
end

it 'assumes wildcard when schema is not defined' do
Expand Down Expand Up @@ -172,7 +172,7 @@
it 'encodes uninitialized optional attribute with default value' do
msg = @klass.new
@klass.optional :optional, String, 'default'
expect(msg.encode).to eq(Yajl::Encoder.encode({ 'optional' => 'default' }))
expect(msg.encode).to eq(Oj.dump({ 'optional' => 'default' }))
end

it 'raises validation errors when required fields are missing' do
Expand Down Expand Up @@ -201,7 +201,7 @@
'with_default' => 'default',
'no_default' => 'defined'
}
received = Yajl::Parser.parse(msg.encode)
received = Oj.load(msg.encode)
expect(received).to eq(expected)
end
end
Expand Down Expand Up @@ -230,7 +230,7 @@
@klass.required :required_two, String

expect do
@klass.decode(Yajl::Encoder.encode({}))
@klass.decode(Oj.dump({}))
end.to(raise_error do |error|
expect(error).to be_a(JsonMessage::ValidationError)
expect(error.message.size).to be > 0
Expand All @@ -241,10 +241,10 @@
@klass.required :required, String
@klass.optional :with_default, String, 'default'
@klass.optional :no_default, String
encoded = Yajl::Encoder.encode({
'required' => 'required',
'no_default' => 'defined'
})
encoded = Oj.dump({
'required' => 'required',
'no_default' => 'defined'
})
decoded = @klass.decode(encoded)
expect(decoded.required).to eq('required')
expect(decoded.with_default).to eq('default')
Expand Down

0 comments on commit 4dcc9b1

Please sign in to comment.