Sha256: 07c09e60f1995a9840468ec8290178c0521bd5afdaab06f528ef65730684c2c2

Contents?: true

Size: 544 Bytes

Versions: 9

Compression:

Stored size: 544 Bytes

Contents

module PluckMap
  module HashPresenter

    def to_h(query)
      define_to_h!
      to_h(query)
    end

    private def define_to_h!
      ruby = <<-RUBY
      def to_h(query)
        pluck(query) do |results|
          results.map { |values| values = Array(values); { #{attributes.map { |attribute| "#{attribute.name.inspect} => #{attribute.to_ruby}" }.join(", ")} } }
        end
      end
      RUBY
      # puts "\e[34m#{ruby}\e[0m" # <-- helps debugging PluckMapPresenter
      class_eval ruby, __FILE__, __LINE__ - 7
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
pluck_map-1.0.0 lib/pluck_map/presenters/to_h.rb
pluck_map-1.0.0.rc2 lib/pluck_map/presenters/to_h.rb
pluck_map-0.6.2 lib/pluck_map/presenters/to_h.rb
pluck_map-1.0.0.rc1 lib/pluck_map/presenters/to_h.rb
pluck_map-0.6.1 lib/pluck_map/presenters/to_h.rb
pluck_map-0.6.0 lib/pluck_map/presenters/to_h.rb
pluck_map-0.5.0 lib/pluck_map/presenters/to_h.rb
pluck_map-0.4.1 lib/pluck_map/presenters/to_h.rb
pluck_map-0.4.0 lib/pluck_map/presenters/to_h.rb