Class: FastJsonapi::Link

Inherits:
Object
  • Object
show all
Defined in:
lib/fast_jsonapi/link.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key:, method:) ⇒ Link

Returns a new instance of Link.



5
6
7
8
# File 'lib/fast_jsonapi/link.rb', line 5

def initialize(key:, method:)
  @key = key
  @method = method
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



3
4
5
# File 'lib/fast_jsonapi/link.rb', line 3

def key
  @key
end

#methodObject (readonly)

Returns the value of attribute method.



3
4
5
# File 'lib/fast_jsonapi/link.rb', line 3

def method
  @method
end

Instance Method Details

#serialize(record, serialization_params, output_hash) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/fast_jsonapi/link.rb', line 10

def serialize(record, serialization_params, output_hash)
  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