Sha256: 052890a2bb86870db049bda49a0e4923308d8debcac0da8be4886e5df34e2b80

Contents?: true

Size: 611 Bytes

Versions: 3

Compression:

Stored size: 611 Bytes

Contents

# frozen_string_literal: true

module ActiveModel
  class Serializer
    class Fieldset
      def initialize(fields)
        @raw_fields = fields || {}
      end

      def fields
        @fields ||= parsed_fields
      end

      def fields_for(type)
        fields[type.singularize.to_sym] || fields[type.pluralize.to_sym]
      end

      protected

      attr_reader :raw_fields

      private

      def parsed_fields
        if raw_fields.is_a?(Hash)
          raw_fields.each_with_object({}) { |(k, v), h| h[k.to_sym] = v.map(&:to_sym) }
        else
          {}
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
active_model_serializers-0.10.10 lib/active_model/serializer/fieldset.rb
active_model_serializers_custom-0.10.90 lib/active_model/serializer/fieldset.rb
active_model_serializers-0.10.9 lib/active_model/serializer/fieldset.rb