Class: Graphiti::Util::Link

Inherits:
Object show all
Defined in:
lib/graphiti/util/link.rb

Instance Method Summary collapse

Constructor Details

#initialize(sideload, model) ⇒ Link

Returns a new instance of Link.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/graphiti/util/link.rb', line 4

def initialize(sideload, model)
  @sideload = sideload
  @model = model
  @linkable = true

  if @sideload.type == :polymorphic_belongs_to
    if (type = @model.send(@sideload.grouper.field_name))
      @sideload = @sideload.children.values.find { |c|
        c.group_name == type.to_sym
      }
      @polymorphic_sideload_not_found = true unless @sideload
    else
      @linkable = false
    end
  end
end

Instance Method Details

#generateObject



21
22
23
24
25
# File 'lib/graphiti/util/link.rb', line 21

def generate
  if linkable?
    on_demand_links(raw_url)
  end
end