Sha256: a92f4da91468fb7b610879911bc859bd0a8fd5df4ee3647e31782f2ddd965f93

Contents?: true

Size: 580 Bytes

Versions: 14

Compression:

Stored size: 580 Bytes

Contents

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

14 entries across 14 versions & 2 rubygems

Version Path
active_model_serializers-0.10.8 lib/active_model/serializer/fieldset.rb
active_model_serializers-0.10.7 lib/active_model/serializer/fieldset.rb
active_model_serializers-0.10.6 lib/active_model/serializer/fieldset.rb
active_model_serializers-0.10.5 lib/active_model/serializer/fieldset.rb
active_model_serializers-0.10.4 lib/active_model/serializer/fieldset.rb
agi_active_model_serializers-0.10.9 lib/active_model/serializer/fieldset.rb
agi_active_model_serializers-0.10.8 lib/active_model/serializer/fieldset.rb
agi_active_model_serializers-0.10.7 lib/active_model/serializer/fieldset.rb
active_model_serializers-0.10.3 lib/active_model/serializer/fieldset.rb
active_model_serializers-0.10.2 lib/active_model/serializer/fieldset.rb
active_model_serializers-0.10.1 lib/active_model/serializer/fieldset.rb
active_model_serializers-0.10.0 lib/active_model/serializer/fieldset.rb
active_model_serializers-0.10.0.rc5 lib/active_model/serializer/fieldset.rb
active_model_serializers-0.10.0.rc4 lib/active_model/serializer/fieldset.rb