Code Monkey home page Code Monkey logo

representable-expandable's Introduction

Representable Expandable Extension Build Status

This gem is an extension on top of Representable which allows us to by default exclude properties/collections from representables and explicitly include them by setting right option on Representable.

Installation

Add following line to your Gemfile

gem 'representable-expandable'

Usage

You can make a collection Expandable by includeing Representable::Expandable in your Representable and set expandable: true for your expandable properties/colloections. Here is a sample:

module MessageRepresenter
  include Roar::JSON
  include Expandable

  property :id
  property :subject
  property :body, expandable: true
  collection :attachments, extend: AttachmentRepresenter, class: Attachment, expandable: true
end

In the above example attachments are expandable which means by default they won't get rendered in MessageRepresenter. In order to explicitly add them to representer we need to set expand options of representer using to_json method:

message = Message.new(id: 'test', subject: 'test subject', body: 'test body', attachments: ['1', '2'])
message.extend(MessageRepresenter).to_json(expand: ['attachments'])

Note that expand gets an array as input.

##Problems?

Please create a Github issue once you find any issue or had any requests.

##Thanks Special thanks to @joeyAghion

##License

Please see LICENSE for licensing details.

representable-expandable's People

Contributors

ashkan18 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.