Sha256: fe5edb96e0c3d67af8a0c2a62766b0651dab1004900fa8f03f8ebd357c84fcb7

Contents?: true

Size: 549 Bytes

Versions: 14

Compression:

Stored size: 549 Bytes

Contents

# frozen_string_literal: true

class WCC::Contentful::Link
  attr_reader :id, :link_type, :raw

  LINK_TYPES = {
    Asset: 'Asset',
    Link: 'Entry'
  }.freeze

  def initialize(model, link_type = nil)
    @id = model.try(:id) || model
    @link_type = link_type
    @link_type ||= model.is_a?(WCC::Contentful::Model::Asset) ? :Asset : :Link
    @raw =
      {
        'sys' => {
          'type' => 'Link',
          'linkType' => LINK_TYPES[@link_type] || link_type,
          'id' => @id
        }
      }
  end

  alias_method :to_h, :raw
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
wcc-contentful-1.6.2 lib/wcc/contentful/link.rb
wcc-contentful-1.6.1 lib/wcc/contentful/link.rb
wcc-contentful-1.6.0 lib/wcc/contentful/link.rb
wcc-contentful-1.5.1 lib/wcc/contentful/link.rb
wcc-contentful-1.5.0 lib/wcc/contentful/link.rb
wcc-contentful-1.5.0.rc1 lib/wcc/contentful/link.rb
wcc-contentful-1.4.0 lib/wcc/contentful/link.rb
wcc-contentful-1.4.0.rc3 lib/wcc/contentful/link.rb
wcc-contentful-1.4.0.rc2 lib/wcc/contentful/link.rb
wcc-contentful-1.3.2 lib/wcc/contentful/link.rb
wcc-contentful-1.4.0.rc1 lib/wcc/contentful/link.rb
wcc-contentful-1.3.1 lib/wcc/contentful/link.rb
wcc-contentful-1.3.0 lib/wcc/contentful/link.rb
wcc-contentful-1.2.1 lib/wcc/contentful/link.rb