Sha256: 582e145c3a823a6ad7fb7d17c7440bf795e4d7fa68f7267a270f34c45055fc26

Contents?: true

Size: 575 Bytes

Versions: 16

Compression:

Stored size: 575 Bytes

Contents

# frozen_string_literal: true

class WCC::Contentful::Link
  attr_reader :id
  attr_reader :link_type
  attr_reader :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

16 entries across 16 versions & 1 rubygems

Version Path
wcc-contentful-1.2.0 lib/wcc/contentful/link.rb
wcc-contentful-1.1.2 lib/wcc/contentful/link.rb
wcc-contentful-1.1.1 lib/wcc/contentful/link.rb
wcc-contentful-1.1.0 lib/wcc/contentful/link.rb
wcc-contentful-1.0.8 lib/wcc/contentful/link.rb
wcc-contentful-1.0.7 lib/wcc/contentful/link.rb
wcc-contentful-1.0.6 lib/wcc/contentful/link.rb
wcc-contentful-1.0.5 lib/wcc/contentful/link.rb
wcc-contentful-1.0.4 lib/wcc/contentful/link.rb
wcc-contentful-1.0.3 lib/wcc/contentful/link.rb
wcc-contentful-1.0.2 lib/wcc/contentful/link.rb
wcc-contentful-1.0.1 lib/wcc/contentful/link.rb
wcc-contentful-1.0.0 lib/wcc/contentful/link.rb
wcc-contentful-1.0.0.pre.rc3 lib/wcc/contentful/link.rb
wcc-contentful-1.0.0.pre.rc2 lib/wcc/contentful/link.rb
wcc-contentful-1.0.0.pre.rc1 lib/wcc/contentful/link.rb