Skip to content

Commit

Permalink
Switch JSON.dump to Typecast.to_json
Browse files Browse the repository at this point in the history
  • Loading branch information
jnunemaker committed Nov 13, 2023
1 parent e2f7ab3 commit 041840d
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/flipper/adapters/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def set(feature, gate, thing, options = {})
@gate_class.create! do |g|
g.feature_key = feature.key
g.key = gate.key
g.value = json_feature ? JSON.dump(thing.value) : thing.value.to_s
g.value = json_feature ? Typecast.to_json(thing.value) : thing.value.to_s
end
rescue ::ActiveRecord::RecordNotUnique
# assume this happened concurrently with the same thing and its fine
Expand Down
2 changes: 1 addition & 1 deletion lib/flipper/adapters/mongo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def enable(feature, gate, thing)
}
when :json
update feature.key, '$set' => {
gate.key.to_s => JSON.dump(thing.value),
gate.key.to_s => Typecast.to_json(thing.value),
}
else
unsupported_data_type gate.data_type
Expand Down
2 changes: 1 addition & 1 deletion lib/flipper/adapters/pstore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def enable(feature, gate, thing)
when :set
set_add key(feature, gate), thing.value.to_s
when :json
write key(feature, gate), JSON.dump(thing.value)
write key(feature, gate), Typecast.to_json(thing.value)
else
raise "#{gate} is not supported by this adapter yet"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/flipper/adapters/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def enable(feature, gate, thing)
when :set
@client.hset feature_key, to_field(gate, thing), 1
when :json
@client.hset feature_key, gate.key, JSON.dump(thing.value)
@client.hset feature_key, gate.key, Typecast.to_json(thing.value)
else
unsupported_data_type gate.data_type
end
Expand Down
2 changes: 1 addition & 1 deletion lib/flipper/adapters/sequel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def gate_attrs(feature, gate, thing, json: false)
{
feature_key: feature.key.to_s,
key: gate.key.to_s,
value: json ? JSON.dump(thing.value) : thing.value.to_s,
value: json ? Typecast.to_json(thing.value) : thing.value.to_s,
}
end

Expand Down
2 changes: 1 addition & 1 deletion lib/flipper/api/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def halt(response)
def json_response(object, status = 200)
header 'content-type', Api::CONTENT_TYPE
status(status)
body = JSON.dump(object)
body = Typecast.to_json(object)
halt [@code, @headers, [body]]
end

Expand Down
3 changes: 1 addition & 2 deletions lib/flipper/exporters/json/export.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require "flipper/export"
require "flipper/typecast"
require "flipper/serializers/json"

module Flipper
module Exporters
Expand All @@ -19,7 +18,7 @@ def initialize(contents:, version: 1)
# Public: The features hash identical to calling get_all on adapter.
def features
@features ||= begin
features = Serializers::Json.deserialize(contents).fetch("features")
features = Typecast.from_json(contents).fetch("features")
Typecast.features_hash(features)
rescue JSON::ParserError
raise JsonError
Expand Down
2 changes: 1 addition & 1 deletion lib/flipper/exporters/json/v1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def call(adapter)
end
end

json = JSON.dump({
json = Typecast.to_json({
version: VERSION,
features: features,
})
Expand Down
2 changes: 1 addition & 1 deletion lib/flipper/ui/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def json_response(object)
when String
object
else
JSON.dump(object)
Typecast.to_json(object)
end
halt [@code, @headers, [body]]
end
Expand Down

0 comments on commit 041840d

Please sign in to comment.