Sha256: 17f757f09c333bf1b2b07cbb5731c1edaef2b5e3447dcb96cc1195ab0b09d4a1

Contents?: true

Size: 917 Bytes

Versions: 6

Compression:

Stored size: 917 Bytes

Contents

module {{namespace_module}}
  module {{resource_module}}
    module Show
      class Normalizer
        include Shogun::Normalizer
        include {{resource_module}}

        METADATA = %w|id fields|
        LIST_DELIMITER = /\s*,\s*/
        DEFAULT_FIELDS = %w|id created_at updated_at destroyed_at href|
        AUTOMATIC_FIELDS = %w|id href|

        def initialize(raw:)
          @id = raw["id"]
          @fields = raw["fields"]
        end

        def id
          @id
        end

        def fields
          case
          when @fields.is_a?(String) && @fields.match(LIST_DELIMITER)
            @fields.split(LIST_DELIMITER) + AUTOMATIC_FIELDS
          when @fields.is_a?(Array)
            @fields + AUTOMATIC_FIELDS
          when @fields.is_a?(String)
            [@fields.strip] + AUTOMATIC_FIELDS
          else
            DEFAULT_FIELDS
          end.uniq
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
shogun-6.4.2 scaffold/generate/resource/show/normalizer.rb
shogun-6.4.1 scaffold/generate/resource/show/normalizer.rb
shogun-6.4.0 scaffold/generate/resource/show/normalizer.rb
shogun-6.3.0 scaffold/generate/resource/show/normalizer.rb
shogun-6.2.3 scaffold/generate/resource/show/normalizer.rb
shogun-6.2.2 scaffold/generate/resource/show/normalizer.rb