Class: WCC::Contentful::Link

Inherits:
Object
  • Object
show all
Defined in:
lib/wcc/contentful/link.rb

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, link_type = nil) ⇒ Link

Returns a new instance of Link.



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/wcc/contentful/link.rb', line 11

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

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/wcc/contentful/link.rb', line 4

def id
  @id
end

Returns the value of attribute link_type.



4
5
6
# File 'lib/wcc/contentful/link.rb', line 4

def link_type
  @link_type
end

#rawObject (readonly) Also known as: to_h

Returns the value of attribute raw.



4
5
6
# File 'lib/wcc/contentful/link.rb', line 4

def raw
  @raw
end