Sha256: efde8b5b698e5fb418de949020ba07810ce4e3cfa80e37ede2fd3900cdd8a7bb

Contents?: true

Size: 967 Bytes

Versions: 16

Compression:

Stored size: 967 Bytes

Contents

module JSONAPIonify::Api
  module Resource::Builders
    class AttributesBuilder < FieldsBuilder

      delegate :attributes, to: :resource, prefix: true

      private

      def build_default
        resource_attributes.each_with_object(Objects::Attributes.new) do |attribute, attrs|
          if attribute.supports_read_for_action?(action_name, context) && !attribute.hidden_for_action?(action_name)
            attrs[attribute.name] = attribute.resolve(instance, context, example_id: example_id)
          end
        end
      end

      def build_sparce
        resource_fields.each_with_object(Objects::Attributes.new) do |field, attrs|
          field = field.to_sym
          attribute = resource_attributes.find { |attr| attr.name == field }
          if attribute&.supports_read_for_action?(action_name, context)
            attrs[field] = attribute.resolve(instance, context, example_id: example_id)
          end
        end
      end

    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
jsonapionify-0.12.8 lib/jsonapionify/api/resource/builders/attributes_builder.rb
jsonapionify-0.12.7 lib/jsonapionify/api/resource/builders/attributes_builder.rb
jsonapionify-0.12.5 lib/jsonapionify/api/resource/builders/attributes_builder.rb
jsonapionify-0.12.4 lib/jsonapionify/api/resource/builders/attributes_builder.rb
jsonapionify-0.12.3 lib/jsonapionify/api/resource/builders/attributes_builder.rb
jsonapionify-0.12.2 lib/jsonapionify/api/resource/builders/attributes_builder.rb
jsonapionify-0.12.1 lib/jsonapionify/api/resource/builders/attributes_builder.rb
jsonapionify-0.12.0 lib/jsonapionify/api/resource/builders/attributes_builder.rb
jsonapionify-0.11.11 lib/jsonapionify/api/resource/builders/attributes_builder.rb
jsonapionify-0.11.10 lib/jsonapionify/api/resource/builders/attributes_builder.rb
jsonapionify-0.11.9 lib/jsonapionify/api/resource/builders/attributes_builder.rb
jsonapionify-0.11.8 lib/jsonapionify/api/resource/builders/attributes_builder.rb
jsonapionify-0.11.7 lib/jsonapionify/api/resource/builders/attributes_builder.rb
jsonapionify-0.11.6 lib/jsonapionify/api/resource/builders/attributes_builder.rb
jsonapionify-0.11.5 lib/jsonapionify/api/resource/builders/attributes_builder.rb
jsonapionify-0.11.0 lib/jsonapionify/api/resource/builders/attributes_builder.rb