remove options param from Link class
This commit is contained in:
parent
01477e9c5b
commit
af38b30179
@ -1,28 +1,17 @@
|
|||||||
module FastJsonapi
|
module FastJsonapi
|
||||||
class Link
|
class Link
|
||||||
attr_reader :key, :method, :conditional_proc
|
attr_reader :key, :method
|
||||||
|
|
||||||
def initialize(key:, method:, options: {})
|
def initialize(key:, method:)
|
||||||
@key = key
|
@key = key
|
||||||
@method = method
|
@method = method
|
||||||
@conditional_proc = options[:if]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def serialize(record, serialization_params, output_hash)
|
def serialize(record, serialization_params, output_hash)
|
||||||
if include_link?(record, serialization_params)
|
output_hash[key] = if method.is_a?(Proc)
|
||||||
output_hash[key] = if method.is_a?(Proc)
|
method.arity == 1 ? method.call(record) : method.call(record, serialization_params)
|
||||||
method.arity == 1 ? method.call(record) : method.call(record, serialization_params)
|
|
||||||
else
|
|
||||||
record.public_send(method)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def include_link?(record, serialization_params)
|
|
||||||
if conditional_proc.present?
|
|
||||||
conditional_proc.call(record, serialization_params)
|
|
||||||
else
|
else
|
||||||
true
|
record.public_send(method)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -239,15 +239,14 @@ module FastJsonapi
|
|||||||
{}
|
{}
|
||||||
end
|
end
|
||||||
|
|
||||||
def link(link_name, link_method_name = nil, options = {}, &block)
|
def link(link_name, link_method_name = nil, &block)
|
||||||
self.data_links = {} if self.data_links.nil?
|
self.data_links = {} if self.data_links.nil?
|
||||||
link_method_name = link_name if link_method_name.nil?
|
link_method_name = link_name if link_method_name.nil?
|
||||||
key = run_key_transform(link_name)
|
key = run_key_transform(link_name)
|
||||||
|
|
||||||
self.data_links[key] = Link.new(
|
self.data_links[key] = Link.new(
|
||||||
key: key,
|
key: key,
|
||||||
method: block || link_method_name,
|
method: block || link_method_name
|
||||||
options: options
|
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user