Sha256: b52a7e829bf4242e9f04f512e942baec0dff9b96c148a9a0dc3e837e2b412ca5
Contents?: true
Size: 1.32 KB
Versions: 6
Compression:
Stored size: 1.32 KB
Contents
module {{namespace_module}} module Accounts module List class Normalizer include Shogun::Normalizer include Accounts METADATA = %w|limit filters includes fields| LIST_DELIMITER = /\s*,\s*/ DEFAULT_FIELD = "id" AUTOMATIC_FIELDS = %w|id href meta links linked| def initialize(raw:) @limit = raw["limit"] @filters = raw["filter"] @includes = raw["include"] @fields = raw["fields"] end def limit Integer(@limit) rescue 10 end def filters if @filters.is_a?(Hash) @filters else Hash.new end end def includes case @includes when String @includes.split(LIST_DELIMITER) when Array @includes else Array.new end end def fields case when @fields.is_a?(Array) @fields + AUTOMATIC_FIELDS when @fields.is_a?(String) && @fields.match(LIST_DELIMITER) @fields.split(LIST_DELIMITER) + AUTOMATIC_FIELDS when @fields.is_a?(String) [@fields.strip] + AUTOMATIC_FIELDS else [DEFAULT_FIELD] end.uniq end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems