Module: JSONAPI::Serializable::Resource::InstanceMethods

Defined in:
lib/jsonapi/serializable/resource/conditional_fields.rb

Instance Method Summary collapse

Instance Method Details

#_conditionally_included?(condition_blocks, field) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


115
116
117
118
# File 'lib/jsonapi/serializable/resource/conditional_fields.rb', line 115

def _conditionally_included?(condition_blocks, field)
  condition = condition_blocks[field]
  condition.nil? || instance_exec(&condition)
end

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



108
109
110
111
112
# File 'lib/jsonapi/serializable/resource/conditional_fields.rb', line 108

def link_blocks
  super.select do |k, _|
    _conditionally_included?(self.class.link_condition_blocks, k)
  end
end

#requested_attributes(fields) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



94
95
96
97
98
# File 'lib/jsonapi/serializable/resource/conditional_fields.rb', line 94

def requested_attributes(fields)
  super.select do |k, _|
    _conditionally_included?(self.class.field_condition_blocks, k)
  end
end

#requested_relationships(fields) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



101
102
103
104
105
# File 'lib/jsonapi/serializable/resource/conditional_fields.rb', line 101

def requested_relationships(fields)
  super.select do |k, _|
    _conditionally_included?(self.class.field_condition_blocks, k)
  end
end