Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.
/ active_hal Public archive

Provides ActiveModel support for JSON-HAL.

License

Notifications You must be signed in to change notification settings

gregbeech/active_hal

Repository files navigation

ActiveHal

This library lets you write ActiveModel classes for JSON-HAL, e.g. the following model...

class Order
  include ActiveHal::Model

  hal_attr :id, :total_price

  belongs_to :restaurant
  belongs_to :user, class_name: 'Customer'
  belongs_to :address, rel: 'https://example.org/rels/address'
  has_many :items, class_name: 'OrderItem', rel: 'https://example.org/rels/order-items'
end

...could be used to represent the following JSON-HAL.

{
  "_links": {
    "curies": [{
      "name": "eg",
      "href": "https://example.org/rels/{rel}",
      "templated": true
    }],
    "self": {
      "href": "https://example.org/orders/108"
    },
    "restaurant": {
      "href": "https://example.org/restaurants/72"
    },
    "user": {
      "href": "https://example.org/users/38"
    },
    "eg:address": {
      "href": "https://example.org/addresses/82"
    },
    "eg:order-item": [{
      "href": "https://example.org/order-items/382"
    }, {
      "href": "https://example.org/order-items/383"
    }]
  },
  "id": 108,
  "total_price": 12.99
}

You can then just use them like normal objects, and any attributes and relations will be loaded automatically.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/gregbeech/active_hal. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

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

About

Provides ActiveModel support for JSON-HAL.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published