Skip to content

Pluckify allows you to pluck to Hash, OpenStruct or any custom class like presenters.

License

Notifications You must be signed in to change notification settings

rdelandesen/pluckify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pluckify

Pluckify allows you to pluck to Hash, OpenStruct or any custom class like presenters.

Inspired by pluck_to_hash gem (github).

Usage

# Hash (only column name args)
User.limit(10).pluckify(:id, :first_name, 'users.last_name as last_name')
# => [ { id: 1, first_name: 'Romain', last_name: 'de Landesen' } ]

# OpenStruct
Administrator.where(id: 1).pluckify(:id, :first_name, :last_name, OpenStruct)
# => [ <#OpenStruct id=1, first_name="Romain", last_name="de Landesen"> ]

# Custom Presenter
Administrator.pluckify(:id, :first_name, :last_name, AdministratorPresenter)
# => [ #<AdministratorPresenter @model=#<OpenStruct id=1, first_name="Judge", last_name="Dredd">> ]

Installation

Add this line to your application's Gemfile:

gem 'pluckify', github: 'rdelandesen/pluckify'

And then execute:

$ bundle install

License

The gem is available as open source under the terms of the MIT License.

About

Pluckify allows you to pluck to Hash, OpenStruct or any custom class like presenters.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published