Class: Betterdocs::Dsl::Result::Link

Inherits:
Betterdocs::Dsl::Representer show all
Extended by:
Tins::DSLAccessor
Includes:
Common, Naming
Defined in:
lib/betterdocs/dsl/result/link.rb

Instance Attribute Summary

Attributes included from Naming

#options

Attributes inherited from Betterdocs::Dsl::Representer

#name, #representer

Instance Method Summary collapse

Methods included from Naming

#below_path, #full_name, #initialize, #nesting_name, #path, #public_name

Methods included from Common

#set_context

Methods inherited from Betterdocs::Dsl::Representer

#assign?, #initialize

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Betterdocs::Dsl::Common

Instance Method Details

#add_to_collector(collector) ⇒ Object



35
36
37
# File 'lib/betterdocs/dsl/result/link.rb', line 35

def add_to_collector(collector)
  collector.links[name] = self
end

#assign(result, object) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/betterdocs/dsl/result/link.rb', line 24

def assign(result, object)
  assign?(object) or return
  link = {
    'rel'  => name.to_s,
    'href' => object.instance_eval(&url).to_s,
  }
  templated and link['templated'] = true
  result['links'].push(link)
  self
end

#url(&block) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/betterdocs/dsl/result/link.rb', line 14

def url(&block)
  if block
    @url = block
  elsif @url
    @url
  else
    raise ArgumentError, 'link requires an URL'
  end
end