Skip to content

Add type JSON::Builder to json in .to_json #196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions src/clear/extensions/core_ext.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ require "base64"
# Extension of some objects outside of Clear ("Monkey Patching")

struct Char
def to_json(json)
def to_json(json : ::JSON::Builder)
json.string("#{self}")
end
end

struct PG::Interval
def to_json(json)
def to_json(json : ::JSON::Builder)
json.object do
json.field("microseconds") { json.number microseconds }
json.field("days") { json.number days }
Expand All @@ -33,7 +33,7 @@ end

struct PG::Geo::Box
# :nodoc:
def to_json(json)
def to_json(json : ::JSON::Builder)
json.object do
json.field("x1") { json.number x1 }
json.field("x2") { json.number x2 }
Expand All @@ -44,7 +44,7 @@ struct PG::Geo::Box
end

struct PG::Geo::LineSegment
def to_json(json)
def to_json(json : ::JSON::Builder)
json.object do
json.field("x1") { json.number x1 }
json.field("x2") { json.number x2 }
Expand All @@ -55,7 +55,7 @@ struct PG::Geo::LineSegment
end

struct PG::Geo::Point
def to_json(json)
def to_json(json : ::JSON::Builder)
json.object do
json.field("x") { json.number x }
json.field("y") { json.number y }
Expand All @@ -64,7 +64,7 @@ struct PG::Geo::Point
end

struct PG::Geo::Line
def to_json(json)
def to_json(json : ::JSON::Builder)
json.object do
json.field("a") { json.number a }
json.field("b") { json.number b }
Expand All @@ -74,7 +74,7 @@ struct PG::Geo::Line
end

struct PG::Geo::Circle
def to_json(json)
def to_json(json : ::JSON::Builder)
json.object do
json.field("x") { json.number x }
json.field("y") { json.number y }
Expand All @@ -84,12 +84,12 @@ struct PG::Geo::Circle
end

struct PG::Geo::Path
def to_json(json)
def to_json(json : ::JSON::Builder)
json.object do
json.field("points") do
json.array do
points.each do
points.to_json(json)
points.to_json(json : ::JSON::Builder)
end
end
end
Expand All @@ -99,35 +99,35 @@ struct PG::Geo::Path
end

struct PG::Geo::Polygon
def to_json(json)
def to_json(json : ::JSON::Builder)
json.object do
json.array do
points.each do
points.to_json(json)
points.to_json(json : ::JSON::Builder)
end
end
end
end
end

struct Slice(T)
def to_json(json)
def to_json(json : ::JSON::Builder)
s = String::Builder.new
to_s(s)
json.string(Base64.strict_encode(s.to_s))
end
end

struct PG::Numeric
def to_json(json)
def to_json(json : ::JSON::Builder)
s = String::Builder.new
to_s(s)
json.string(s.to_s)
end
end

struct BigDecimal
def to_json(json)
def to_json(json : ::JSON::Builder)
json.string(to_s)
end
end
2 changes: 1 addition & 1 deletion src/clear/extensions/enum/enum.cr
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Clear
@value.to_sql
end

def to_json(json)
def to_json(json : ::JSON::Builder)
json.string(@value)
end

Expand Down
2 changes: 1 addition & 1 deletion src/clear/extensions/uuid/uuid.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
struct UUID
def to_json(json)
def to_json(json : ::JSON::Builder)
json.string(to_s)
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/clear/model/modules/has_columns.cr
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ module Clear::Model::HasColumns
JSON.build{ |json| to_json(json, emit_nulls) }
end

def to_json(json, emit_nulls = false)
def to_json(json : ::JSON::Builder, emit_nulls = false)
json.object do
{% for name, settings in COLUMNS %}
if emit_nulls || @{{settings[:crystal_variable_name]}}_column.defined?
Expand Down