Class: FastJsonapi::Link
- Inherits:
-
Object
- Object
- FastJsonapi::Link
- Defined in:
- lib/fast_jsonapi/link.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
Instance Method Summary collapse
-
#initialize(key:, method:) ⇒ Link
constructor
A new instance of Link.
- #serialize(record, serialization_params, output_hash) ⇒ Object
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
#key ⇒ Object (readonly)
Returns the value of attribute key.
3 4 5 |
# File 'lib/fast_jsonapi/link.rb', line 3 def key @key end |
#method ⇒ Object (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 |