mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Add DSL for urls
This commit is contained in:
@@ -9,11 +9,13 @@ module ActiveModel
|
||||
class << self
|
||||
attr_accessor :_attributes
|
||||
attr_accessor :_associations
|
||||
attr_accessor :_urls
|
||||
end
|
||||
|
||||
def self.inherited(base)
|
||||
base._attributes = []
|
||||
base._associations = {}
|
||||
base._urls = []
|
||||
end
|
||||
|
||||
def self.attributes(*attrs)
|
||||
@@ -62,6 +64,14 @@ module ActiveModel
|
||||
end
|
||||
end
|
||||
|
||||
def self.url(attr)
|
||||
@_urls.push attr
|
||||
end
|
||||
|
||||
def self.urls(*attrs)
|
||||
@_urls.concat attrs
|
||||
end
|
||||
|
||||
def self.serializer_for(resource)
|
||||
if resource.respond_to?(:to_ary)
|
||||
config.array_serializer
|
||||
|
||||
Reference in New Issue
Block a user