Sha256: 2d001f9424be5a7129b2c91c0e9c1466506ffa2ac39a1493adec7d31cc70c877

Contents?: true

Size: 821 Bytes

Versions: 1

Compression:

Stored size: 821 Bytes

Contents

require "pluck_map/attribute"

module PluckMap
  module Relationships
    class Base < Attribute
      attr_reader :attributes, :scope

      def initialize(attribute_name, scope, block, options)
        @scope = scope
        @attributes = AttributeBuilder.build(model: scope.klass, &block)
        @scope = @scope.instance_exec(&options[:scope_block]) if options[:scope_block]
        options = options.slice(:as).merge(
          select: build_select,
          map: build_map)

        super(attribute_name, scope.klass, options)
      end

      def will_map?
        attributes.any?(&:will_map?)
      end

      def nested?
        true
      end

    protected

      def build_select
        raise NotImplementedError
      end

      def build_map
        raise NotImplementedError
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pluck_map-1.0.0.rc1 lib/pluck_map/relationships/base.rb