Merge pull request #1213 from AutoCloud/type_setting

Add Serializer 'type' directive to control type field, for
 use by the JsonApi adapter
This commit is contained in:
Benjamin Fleischer
2015-10-01 22:59:17 -05:00
3 changed files with 28 additions and 10 deletions

View File

@@ -46,6 +46,10 @@ module ActiveModel
super
end
def self.type(type)
self._type = type
end
def self.attributes(*attrs)
attrs = attrs.first if attrs.first.class == Array
@@ -122,6 +126,7 @@ module ActiveModel
end
attr_accessor :object, :root, :meta, :meta_key, :scope
class_attribute :_type, instance_writer: false
def initialize(object, options = {})
self.object = object

View File

@@ -71,6 +71,7 @@ module ActiveModel
end
def resource_identifier_type_for(serializer)
return serializer._type if serializer._type
if ActiveModel::Serializer.config.jsonapi_resource_type == :singular
serializer.object.class.model_name.singular
else