Skip to content

Repository files navigation

Halibut Gitter chat

Gem VersionBuild StatusCoverage StatusDependency StatusCode ClimateInline docs

Halibut is a tiny gem that makes it easier to deal with the HAL format.

In providing tools to build, (de)serialize, and manipulate HAL resources, Halibut has the following goals:

  • Provide Ruby abstractions
  • Clean, small API
  • Easily composable, for use in other libraries

Installation

Add this line to your application's Gemfile:

gem 'halibut'

And then execute:

$ bundle

Or install it yourself as:

$ gem install halibut

Usage

There are three ways to get a resource with halibut: manual, Builder, and JSON.

Manual

require'halibut'# manually creating a resourceorder=Halibut::Core::Resource.new"/orders/123"order.set_property"total",30.00order.set_property"currency","USD"order.set_property"status","shipped"payment=Halibut::Core::Resource.new"/orders/123/payment"payment.set_property"method","credit"payment.set_property"amount","30.00"payment.set_property"auth_code","ABZ127"resource=Halibut::Core::Resource.new"/orders"resource.add_link"find","/orders{?id}",templated: trueresource.add_link"next","/orders/1","name"=>'hotdog'resource.add_link"next","/orders/9"resource.set_property"currentlyProcessing",14resource.set_property"shippedToday",20resource.embed_resource"payment",paymentresource.add_embed_resource"orders",order

Halibut::Builder

require'halibut/builder'builder=Halibut::Builder.new'/orders'doproperty'currentlyProcessing',14property'shippedToday',20namespace'th','http://things-db.com/{rel}'link'find','/orders{?id}',templated: truelink'next','/orders/1',name: 'hotdog'link'next','/orders/9'link'th:manufacturer','/manufacturer/1'link'th:manufacturer','/manufacturer/2'link'th:manufacturer','/manufacturer/3'end# alternativelybuilder=Halibut::Builder.new'/orders'doproperty'currentlyProcessing',14property'shippedToday',20namespace'th','http://things-db.com/{rel}'link'find','/orderes{?id}',templated: truerelation'next'dolink'/orders/1',name: 'hotdog'link'/orders/9'endrelation'th:manufacturer'dolink'/manufacturers/1'link'/manufacturers/2'link'/manufacturers/3'endendresource=builder.resource

JSON

require'halibut/adapter/json'# converting to JSONHalibut::Adapter::JSON.dumpresource# creating a resource from JSONresource=Halibut::Adapter::JSON.load'resource.json'

Contributing

  1. Fork it
    1. git submodule update --init
    2. bundle install, optionally pass --without-development and use your own tools
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

About

tools to handle the HAL specification

Resources

Stars

16 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages