Project

to_poro

0.0
No commit activity in last 3 years
No release in over 3 years
Simple module allowing fetching data as Ruby objects.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.15
~> 10.0
~> 3.0
 Project Readme

ToPoro

Simple module which can be included into ActiveRecord::Relation - it allows to fetch data as ruby Structs instead of ActiveRecord classes. Fetching data this way is a bit faster and wrapping data into Structs allows to use query results like any other Ruby objects.

Installation

When running Rails: add this line to your application's Gemfile:

gem 'to_poro'

and include ToPoro module into ActiveRecord::Relation class. One way of doing it is by adding a config/to_poro_initializer.rb:

class ActiveRecord::Relation
  include ToPoro
end

Usage

For example when fetching Event data and only id and price is needed:

 Event.all.to_poro(:id, :date)
 => [
 #<struct  id=1, date=Tue, 07 Jun 2016>,
 #<struct  id=2, date=Wed, 08 Jun 2016>,
 ...
 ]
 Event.where(deleted: false).to_poro(:id, :date)
 => [
 #<struct  id=1, date=Tue, 07 Jun 2016>,
 #<struct  id=2, date=Wed, 08 Jun 2016>,
 ...
 ]
 Event.where(deleted: false).limit(2).to_poro(:id, :date)
 => [
 #<struct  id=1, date=Tue, 07 Jun 2016>,
 #<struct  id=2, date=Wed, 08 Jun 2016>
 ]

License

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