class JsonApiReflectionReceiver
We use this when a serializer has a reflection with a block argument, like this:
has_many :users do include_data false link(:related) { users_company_path(object) } end
The only way to find out what options get set in that block is to run it, so this class does that and records what is there.
Attributes
result_include_data[R]
result_links[R]
serializer[R]
Public Class Methods
new(serializer)
click to toggle source
# File lib/active_model_serializers/adapter/json_api_pg.rb, line 334 def initialize(serializer) @serializer = serializer @result_include_data = true @result_links = {} end
Public Instance Methods
include_data(val)
click to toggle source
# File lib/active_model_serializers/adapter/json_api_pg.rb, line 340 def include_data(val) @result_include_data = val end
link(name, val=nil, &block)
click to toggle source
Users may pass either a string or a block, so we accept both.
# File lib/active_model_serializers/adapter/json_api_pg.rb, line 346 def link(name, val=nil, &block) if not val.nil? @result_links[name] = val else lnk = ActiveModelSerializers::Adapter::JsonApi::Link.new(serializer.new(object), block) # TODO: Super hacky here, and only supports one level of path resources: template = lnk.as_json @result_links[name] = template.split("PARAM").map{|p| "'#{p}'"} # @result_links[name] = "CONCAT(template # @result_links[name] = instance_eval(&block) end end
object()
click to toggle source
# File lib/active_model_serializers/adapter/json_api_pg.rb, line 359 def object # TODO: Could even be a singleton JsonApiObjectProxy.new end