Sha256: 3efad3074417a86602b8efece992babc87cf9a212a1688f85e3220439a83583b

Contents?: true

Size: 532 Bytes

Versions: 5

Compression:

Stored size: 532 Bytes

Contents

require "pluck_map/attribute"

module PluckMap
  module Relationships
    class One < Base
    protected

      def build_select
        Arel.sql("(#{scope.select(attributes.to_json_array).to_sql})")
      end

      def build_map
        lambda do |values|
          return nil if values.nil?
          values = JSON.parse(values) if values.is_a?(String)
          attributes.each_with_object({}) do |attribute, hash|
            hash[attribute.name] = attribute.exec(values)
          end
        end
      end

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pluck_map-2.0.0 lib/pluck_map/relationships/one.rb
pluck_map-2.0.0.rc1 lib/pluck_map/relationships/one.rb
pluck_map-1.0.0 lib/pluck_map/relationships/one.rb
pluck_map-1.0.0.rc2 lib/pluck_map/relationships/one.rb
pluck_map-1.0.0.rc1 lib/pluck_map/relationships/one.rb