-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use proper serialization and default to AMS when available.
- Loading branch information
Showing
5 changed files
with
79 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Robin | ||
module Rails | ||
class DefaultSerializer | ||
attr_reader :resource | ||
attr_reader :options | ||
|
||
def initialize(resource, options={}) | ||
@resource = resource | ||
@options = options | ||
end | ||
|
||
def as_json | ||
resource.as_json(options) | ||
end | ||
|
||
def to_json | ||
resource.to_json(options) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require 'active_model_serializers' | ||
|
||
class AmsModel < ActiveRecord::Base | ||
include Robin::Rails | ||
end | ||
|
||
class AmsModelSerializer < ActiveModel::Serializer | ||
attributes :name, :age, :boom | ||
|
||
def boom | ||
"BOOM!" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters