Project

poro_plus

0.01
No commit activity in last 3 years
No release in over 3 years
Simple methods to make POROs more fun.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
>= 0
 Project Readme

PoroPlus

Friendly methods intended to make POROs more useful. Also useful for creating bounded context / domain models (for example, in services) as first-class objects with custom getters and handy JSON serialization!

Installation

Add this line to your application's Gemfile:

gem 'poro_plus'

And then execute:

$ bundle

Or install it yourself as:

$ gem install poro_plus

Usage

Simply include PoroPlus into your Ruby class:

class MyThing
  include PoroPlus
  attr_reader :foo, :bar, :tres
end

Then you can:

> thing_1 = MyThing.new(:foo => 'Raven', :bar => 'Writing Desk', :tres => nil)
=> #<MyThing:0x007ff4866ea398 @foo="Raven", @bar="Writing Desk", @tres=nil>

> thing_1.to_hash
=> {:foo=>"Raven", :bar=>"Writing Desk", :tres=>nil}

> thing_1.to_json(:skip_nils => true)
 => "{\"foo\":\"Raven\",\"bar\":\"Writing Desk\"}"

If you want the JSON to include methods that return values:

class MyThing
  include PoroPlus
  attr_reader :foo, :bar, :tres

  def tres
    "tres leches con #{self.bar}"
  end

end

Then, passing a nil to create a placeholder for that JSON attribute, you can:

> thing_2 = MyThing.new(:foo => 'Taco', :bar => 'cinnammon', :tres => nil) # nil placeholder
=> #<MyThing:0x007ff4866ea398 @foo="Taco", @bar="cinnammon", @tres=nil>

> thing_2.to_json(:skip_nils => true)
 => "{\"foo\":\"Taco\",\"bar\":\"cinnammon\",\"tres\":\"tres leches con cinnammon\"}"

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request