class JSONApi::ObjectSerializerDefinition
Public Class Methods
attributes(*attrs)
click to toggle source
# File lib/json_api/object_serializer_definition.rb, line 24 def attributes(*attrs) @attributes ||= [] @attributes |= attrs end
base_url(url = @base_url)
click to toggle source
# File lib/json_api/object_serializer_definition.rb, line 33 def base_url(url = @base_url) @base_url = url end
has_many(name, **config)
click to toggle source
# File lib/json_api/object_serializer_definition.rb, line 56 def has_many(name, **config) config[:to] = :many relationship(name, config) end
has_one(name, **config)
click to toggle source
# File lib/json_api/object_serializer_definition.rb, line 51 def has_one(name, **config) config[:to] = :one relationship(name, config) end
hashify(object, **options)
click to toggle source
# File lib/json_api/object_serializer_definition.rb, line 11 def hashify(object, **options) options = merge_options(**options) ObjectSerializer.new.hashify(object, **options) end
id_attribute(attr = @id_attribute)
click to toggle source
# File lib/json_api/object_serializer_definition.rb, line 29 def id_attribute(attr = @id_attribute) @id_attribute = attr end
inherited(specialization)
click to toggle source
# File lib/json_api/object_serializer_definition.rb, line 16 def inherited(specialization) specialization.attributes(*attributes) specialization.relationships(*relationships) specialization.id_attribute(id_attribute) specialization.base_url(base_url) specialization.type(type) end
relationship(name, **config)
click to toggle source
# File lib/json_api/object_serializer_definition.rb, line 41 def relationship(name, **config) config[:name] = name relationships(config) end
relationships(*configs)
click to toggle source
# File lib/json_api/object_serializer_definition.rb, line 46 def relationships(*configs) @relationships ||= [] @relationships |= configs end
serialize(object, **options)
click to toggle source
# File lib/json_api/object_serializer_definition.rb, line 6 def serialize(object, **options) options = merge_options(**options) ObjectSerializer.new.serialize(object, **options) end
type(type = @type)
click to toggle source
# File lib/json_api/object_serializer_definition.rb, line 37 def type(type = @type) @type = type end
Private Class Methods
merge_options(**options)
click to toggle source
# File lib/json_api/object_serializer_definition.rb, line 63 def merge_options(**options) options[:id_attribute] ||= id_attribute options[:attributes] ||= attributes options[:relationships] ||= relationships options[:type] ||= type options end