ActiveModel::Serializer implementation and Rails hooks
Go to file
bobba surendranath chowdary 252f9c4ae9 Moved the adapter and adapter folder to active_model_serializers folder and changed the module namespace
Changed the namespace in adapters and folder to active_model_serializers from active_model::serializer

Changed namespace of adapters in serializers and other folders

Moved adapter_for_test file to active_model_serializers folder and changed namespace of adapter inside the test file

Require ActiveSupport's string/inflections

We depend on string/inflections to define String#underscore.

Refactor JsonApi adapter to avoid redundant computations.

Update readme.md to link to v0.10.0.rc4

changed namespace of adapter folder testcases

Changed all namespaces of adapter under active_moder_serializers

Namespaced IncludeTree which is from serializer module, so needed to namespace it properly

Fixed wrong namsepacing of fieldset

namespace change in deserializer json_api

Fixed the namespace for collection serializer when used inside adapter, changed namespace for adapter to new namespace which I had forgotten previously

Modified logging test and adapter test cases to make the testcases pass

Changed the yardoc links,as old links are not taking to documentation pages,proper links for 0.10,0.9 and 0.8 in rubydoc

Rubocop errors are fixed by underscore naming unused variables

Moved the require of adapter to serializable resource

Remoeved adapter dependency inside serializer and added warning to Serializer::adapter method

Fixed frament cache test which is calling Serializer.adapter

Changed the name of lookup_adapter_from_config to configured_adapter

Changed the docs which will show the new namespace of adapters

Rubocop fix
2016-02-23 21:49:58 -06:00
docs Moved the adapter and adapter folder to active_model_serializers folder and changed the module namespace 2016-02-23 21:49:58 -06:00
lib Moved the adapter and adapter folder to active_model_serializers folder and changed the module namespace 2016-02-23 21:49:58 -06:00
test Moved the adapter and adapter folder to active_model_serializers folder and changed the module namespace 2016-02-23 21:49:58 -06:00
.gitignore Fix bundler caching in travis & Appveyor 2015-11-24 01:53:45 +00:00
.rubocop_todo.yml Remove warning capture; more trouble than worth 2016-01-11 23:48:40 -06:00
.rubocop.yml Hack Minitest to make it less dependent on at_exit 2016-01-11 23:42:45 -06:00
.simplecov Add .bundle/ to simplecov exclude 2016-01-11 23:42:45 -06:00
.travis.yml Remove warning capture; more trouble than worth 2016-01-11 23:48:40 -06:00
active_model_serializers.gemspec Create assert_response_schema test helper 2016-01-15 00:45:56 -06:00
appveyor.yml Drop Ruby 1.9.3 on AppVeyor 2015-12-23 19:39:15 -02:00
CHANGELOG.md Moved the adapter and adapter folder to active_model_serializers folder and changed the module namespace 2016-02-23 21:49:58 -06:00
CONTRIBUTING.md Add CHANGELOG from 0.9 2015-12-23 09:45:45 -06:00
Gemfile Patch ActionController::TestCase#assigns for Rails5 2015-11-25 21:56:01 -06:00
LICENSE.txt Generate a basic gem 2014-07-05 00:53:48 -04:00
Rakefile Only call railtie when Rails is defined; assume controller loaded 2016-01-15 01:54:07 -06:00
README.md Moved the adapter and adapter folder to active_model_serializers folder and changed the module namespace 2016-02-23 21:49:58 -06:00

ActiveModelSerializers

Build Status (Windows: Build status) Code Quality Test Coverage

Documentation

About

ActiveModelSerializers brings convention over configuration to your JSON generation.

ActiveModelSerializers works through two components: serializers and adapters.

Serializers describe which attributes and relationships should be serialized.

Adapters describe how attributes and relationships should be serialized.

SerializableResource co-ordinates the resource, Adapter and Serializer to produce the resource serialization. The serialization has the #as_json, #to_json and #serializable_hash methods used by the Rails JSON Renderer. (SerializableResource actually delegates these methods to the adapter.)

By default ActiveModelSerializers will use the Attributes Adapter. But we strongly advise you to use JsonApi Adapter, which follows 1.0 of the format specified in jsonapi.org/format. Check how to change the adapter in the sections below.

RELEASE CANDIDATE, PLEASE READ

This is the master branch of ActiveModelSerializers.

It will become the 0.10.0 release when it's ready. Currently this is a release candidate.

0.10.x is not backward compatible with 0.9.x nor 0.8.x.

0.10.x will be based on the 0.8.0 code, but with a more flexible architecture. We'd love your help. Learn how you can help here.

It is generally safe and recommended to use the master branch.

For more information, see the post 'The future of AMS'.

Installation

Add this line to your application's Gemfile:

gem 'active_model_serializers'

And then execute:

$ bundle

Getting Started

See Getting Started for the nuts and bolts.

More information is available in the Guides and High-level behavior.

Getting Help

If you find a bug, please report an Issue and see our contributing guide.

If you have a question, please post to Stack Overflow.

If you'd like to chat, we have a community slack.

Thanks!

High-level behavior

Given a serializable model:

# either
class SomeResource < ActiveRecord::Base
  # columns: title, body
end
# or
class SomeResource < ActiveModelSerializers::Model
  attr_accessor :title, :body
end

And initialized as:

resource = SomeResource.new(title: 'ActiveModelSerializers', body: 'Convention over configuration')

Given a serializer for the serializable model:

class SomeSerializer < ActiveModel::Serializer
  attribute :title, key: :name
  attributes :body
end

The model can be serialized as:

options = {}
serialization = SerializableResource.new(resource, options)
serialization.to_json
serialization.as_json

SerializableResource delegates to the adapter, which it builds as:

adapter_options = {}
adapter = Adapter.create(serializer, adapter_options)
adapter.to_json
adapter.as_json
adapter.serializable_hash

The adapter formats the serializer's attributes and associations (a.k.a. includes):

serializer_options = {}
serializer = SomeSerializer.new(resource, serializer_options)
serializer.attributes
serializer.associations

See ARCHITECTURE.md for more information.

Contributing

See CONTRIBUTING.md