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,15 +1,13 @@
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 else
@ -17,13 +15,4 @@ module FastJsonapi
end end
end end
end end
def include_link?(record, serialization_params)
if conditional_proc.present?
conditional_proc.call(record, serialization_params)
else
true
end
end
end
end end

View File

@ -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