Class: Contentful::Management::Link

Inherits:
Object
  • Object
show all
Includes:
Resource, Resource::SystemProperties
Defined in:
lib/contentful/management/link.rb

Overview

Instance Attribute Summary

Attributes included from Resource::SystemProperties

#sys

Attributes included from Resource

#client, #properties, #raw_object, #request

Instance Method Summary collapse

Methods included from Resource

#array?, #default_locale, #destroy, #environment_id, #fields, #nested_locale_fields?, #resource?, #save, #sys, #update

Instance Method Details

#resolve(space_id = nil, environment_id = nil) ⇒ Object

Queries contentful for the Resource the Link is referring to

Parameters:

  • space_id (String) (defaults to: nil)
  • environment_id (String) (defaults to: nil)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/contentful/management/link.rb', line 16

def resolve(space_id = nil, environment_id = nil)
  return client.spaces.find(id) if link_type == 'Space'

  method = Contentful::Management::Support.base_path_for(link_type).to_sym

  if space_id && environment_id.nil?
    return client.public_send(
      method,
      space_id
    ).find(id)
  elsif space_id && environment_id
    return client.public_send(
      method,
      space_id,
      environment_id
    ).find(id)
  end

  client.public_send(method).find(id)
end