From e83ae80759fb4bf250480fe49af75130530be775 Mon Sep 17 00:00:00 2001 From: "Brian J. Cardiff" Date: Wed, 23 May 2018 22:22:48 +0200 Subject: [PATCH] Upgrade to Crystal 0.25.0 JSON::Any API --- src/liquid/filters/compact.cr | 4 ++-- src/liquid/filters/first.cr | 4 ++-- src/liquid/filters/last.cr | 4 ++-- src/liquid/filters/map.cr | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/liquid/filters/compact.cr b/src/liquid/filters/compact.cr index 035245f..d83cd23 100644 --- a/src/liquid/filters/compact.cr +++ b/src/liquid/filters/compact.cr @@ -7,7 +7,7 @@ module Liquid::Filters def self.filter(data : Any, args : Array(Any)? = nil) : Any if (d = data.as_a?) - result = d.compact_map{ |d| d } + result = d.reject &.raw.nil? JSON.parse(result.to_json) else data @@ -16,4 +16,4 @@ module Liquid::Filters end FilterRegister.register "compact", Compact -end \ No newline at end of file +end diff --git a/src/liquid/filters/first.cr b/src/liquid/filters/first.cr index 07b8da7..df5580d 100644 --- a/src/liquid/filters/first.cr +++ b/src/liquid/filters/first.cr @@ -6,7 +6,7 @@ module Liquid::Filters def self.filter(data : Any, args : Array(Any)? = nil) : Any if (d = data.as_a?) && !d.empty? - Any.new d.first + d.first else data end @@ -14,4 +14,4 @@ module Liquid::Filters end FilterRegister.register "first", First -end \ No newline at end of file +end diff --git a/src/liquid/filters/last.cr b/src/liquid/filters/last.cr index e2d06e0..ac7c0e2 100644 --- a/src/liquid/filters/last.cr +++ b/src/liquid/filters/last.cr @@ -6,7 +6,7 @@ module Liquid::Filters def self.filter(data : Any, args : Array(Any)? = nil) : Any if (d = data.as_a?) && !d.empty? - Any.new d.last + d.last else data end @@ -14,4 +14,4 @@ module Liquid::Filters end FilterRegister.register "last", Last -end \ No newline at end of file +end diff --git a/src/liquid/filters/map.cr b/src/liquid/filters/map.cr index 376a6ad..cddb53c 100644 --- a/src/liquid/filters/map.cr +++ b/src/liquid/filters/map.cr @@ -13,7 +13,7 @@ module Liquid::Filters # raise error if user doesn't provide a string argument raise FilterArgumentException.new "map filter expects argument to be a string" unless args.first.raw.is_a?(String) - + if (raw = data.raw) && raw.is_a?(Array) && (first = args.first?) result = raw.compact_map { |r| self.responds_to(r, first.as_s) } if result.empty? @@ -22,14 +22,14 @@ module Liquid::Filters JSON.parse(result.to_json) end elsif (raw = data.raw) && raw.is_a?(Hash) && (first = args.first?) - Any.new raw[first.as_s]? + raw[first.as_s] else data end end def self.responds_to(data, key) - if data.is_a?(Hash) + if data = data.as_h? data[key]? else nil @@ -38,4 +38,4 @@ module Liquid::Filters end FilterRegister.register "map", Map -end \ No newline at end of file +end