-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Super super basic collection of attributes. Nothing fancy.
- Loading branch information
1 parent
a45b5ee
commit 729a823
Showing
9 changed files
with
67 additions
and
12 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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
# coding: utf-8 | ||
lib = File.expand_path('../lib', __FILE__) | ||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | ||
require 'active_model_serializers/version' | ||
require 'active_model/serializer/version' | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = "active_model_serializers" | ||
spec.version = ActiveModelSerializers::VERSION | ||
spec.version = ActiveModel::Serializer::VERSION | ||
This comment has been minimized.
Sorry, something went wrong. |
||
spec.authors = ["Steve Klabnik"] | ||
spec.email = ["[email protected]"] | ||
spec.summary = %q{Conventions-based JSON generation for Rails.} | ||
|
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 ActiveModel | ||
class Serializer | ||
class << self | ||
attr_accessor :_attributes | ||
end | ||
|
||
def self.inherited(base) | ||
base._attributes = [] | ||
end | ||
|
||
def self.attributes(*attrs) | ||
@_attributes.concat attrs | ||
end | ||
|
||
attr_accessor :object | ||
|
||
def initialize(object) | ||
@object = object | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module ActiveModel | ||
class Serializer | ||
VERSION = "0.9.0" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
require "active_model_serializers/version" | ||
require "active_model" | ||
require "active_model/serializer/version" | ||
|
||
require "active_model/serializer" | ||
|
||
module ActiveModelSerializers | ||
# Your code goes here... | ||
end |
This file was deleted.
Oops, something went wrong.
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,18 @@ | ||
require 'test_helper' | ||
|
||
module ActiveModel | ||
class Serializer | ||
class AttributesTest < Minitest::Test | ||
def setup | ||
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' }) | ||
@profile_serializer = ProfileSerializer.new(@profile) | ||
end | ||
|
||
def test_attributes_definition | ||
assert_equal([:name, :description], | ||
@profile_serializer.class._attributes) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class Model | ||
def initialize(hash={}) | ||
@attributes = hash | ||
end | ||
end | ||
|
||
class Profile < Model | ||
end | ||
|
||
class ProfileSerializer < ActiveModel::Serializer | ||
attributes :name, :description | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
require "bundler/setup" | ||
|
||
require "active_model_serializers" | ||
require 'rails' | ||
require "active_support/json" | ||
require 'minitest/autorun' | ||
|
||
require 'rails' | ||
require "active_model_serializers" | ||
|
||
require 'minitest/autorun' | ||
require 'fixtures/poro' |
@steveklabnik Do you remember why you made these changes? At this point, Given the history of AMS naming with respect to Rails, it would seem
ActiveModelSerializers
to be a safer namespace thanActiveModel::Serializer
, especially since in 0.10 the adapter and serializer work together to render a model serialization.-require 'active_model_serializers/version' +require 'active_model/serializer/version' Gem::Specification.new do |spec| spec.name = "active_model_serializers" - spec.version = ActiveModelSerializers::VERSION + spec.version = ActiveModel::Serializer::VERSION
and in 4a2d985