Elixir clone of Grape::Entity
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
config
lib
test
.gitignore
README.md
mix.exs
mix.lock

README.md

Maru.Entity

Elixir copy of grape-entity for serializing objects.

Usage:

defmodule PostEntity do
  use Maru.Entity

  expose :id
  expose :title
  expose :body, as: :content

  expose :disabled, if: fn(post, _options) -> post.is_disabled end
  expose :active, unless: fn(post, _options) -> post.is_disabled end
end

defmodule CommentEntity do
  use Maru.Entity

  expose :body
  expose :post, with: PostEntity, if: fn(comment, _options) -> comment.post != nil end
end

defmodule AuthorEntity do
  use Maru.Entity

  expose :name
  expose :posts, with: PostEntity

  expose :posts_count, [], fn(author, options) ->
    length(author.posts)
  end
end