Skip to content
master
Switch branches/tags
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
lib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

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

About

Friendly methods intended to make POROs more useful.

Resources

License

Packages

No packages published

Languages