-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from Strech/list-items-anything
Added Lurker::Json::List of whatever
- Loading branch information
Showing
10 changed files
with
270 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
module Lurker | ||
module Json | ||
class Polymorph < Schema | ||
def merge!(schema) | ||
case parent_schema | ||
when Lurker::Json::Object | ||
parent_schema[Json::PROPERTIES][parent_property] = @parser.typed.parse(schema) | ||
when Lurker::Json::List | ||
if schema.is_a?(Array) | ||
return if schema.empty? | ||
|
||
schema = schema.dup | ||
parent_schema[Json::ITEMS] = @parser.typed.parse(schema.shift) | ||
parent_schema.merge!(schema) | ||
else | ||
parent_schema[Json::ITEMS] = @parser.typed.parse(schema) | ||
end | ||
else | ||
parent_schema[parent_property] = @parser.typed.parse(schema) | ||
end | ||
end | ||
|
||
def replace!(property, schema) | ||
morph = Lurker::Json::Object.new({}, subschema_options) | ||
|
||
case parent_schema | ||
when Lurker::Json::Object | ||
parent_schema[Json::PROPERTIES][parent_property] = morph | ||
parent_schema.replace!(property, schema) | ||
when Lurker::Json::List | ||
parent_schema[Json::ITEMS] = morph | ||
parent_schema.replace!(property, schema) | ||
else | ||
parent_schema[parent_property] = morph | ||
parent_schema.replace!(property, schema) | ||
end | ||
end | ||
|
||
private | ||
|
||
def parse_schema(schema) | ||
@schema = schema | ||
end | ||
|
||
# NOTE : The parser will ref to parent_schema instead | ||
def subschema_options | ||
{uri: parent_schema.uri, | ||
root_schema: parent_schema.root? ? parent_schema : parent_schema.root_schema, | ||
parent_schema: parent_schema, | ||
parent_property: parent_property} | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters