remove options param from Link class

This commit is contained in:
Kyle Reeves 2018-07-03 15:58:22 -05:00 committed by Shishir Kakaraddi
parent 01477e9c5b
commit af38b30179
2 changed files with 8 additions and 20 deletions

View File

@ -1,29 +1,18 @@
module FastJsonapi
class Link
attr_reader :key, :method, :conditional_proc
attr_reader :key, :method
def initialize(key:, method:, options: {})
def initialize(key:, method:)
@key = key
@method = method
@conditional_proc = options[:if]
end
def serialize(record, serialization_params, output_hash)
if include_link?(record, serialization_params)
output_hash[key] = if method.is_a?(Proc)
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)
output_hash[key] = if method.is_a?(Proc)
method.arity == 1 ? method.call(record) : method.call(record, serialization_params)
else
true
record.public_send(method)
end
end
end
end
end

View File

@ -239,15 +239,14 @@ module FastJsonapi
{}
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?
link_method_name = link_name if link_method_name.nil?
key = run_key_transform(link_name)
self.data_links[key] = Link.new(
key: key,
method: block || link_method_name,
options: options
method: block || link_method_name
)
end