Class: Superlink::Builder

Inherits:
URI::Builder::DSL
  • Object
show all
Defined in:
lib/superlink.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



12
13
14
# File 'lib/superlink.rb', line 12

def model
  @model
end

Class Method Details

.parseObject



38
39
40
# File 'lib/superlink.rb', line 38

def self.parse(...)
  new URI(...)
end

Instance Method Details

#clear_formatObject



23
24
25
26
# File 'lib/superlink.rb', line 23

def clear_format
  @format = nil
  self
end

#format(format) ⇒ Object



18
19
20
21
# File 'lib/superlink.rb', line 18

def format(format)
  @format = format
  self
end

#initialize_copy(original) ⇒ Object



42
43
44
45
# File 'lib/superlink.rb', line 42

def initialize_copy(original)
  super
  @uri = original.uri
end

#join(*segments) ⇒ Object



14
15
16
# File 'lib/superlink.rb', line 14

def join(*segments)
  super(*route(*segments))
end

#uriObject



28
29
30
31
32
33
34
35
36
# File 'lib/superlink.rb', line 28

def uri
  super.clone.tap do |uri|
    uri.path = "#{uri.path}.#{@format}" if @format
    # Check if the route exists in the routes.rb file
    unless Rails.application.routes.recognize_path(uri.path)
      raise ActionController::UrlGenerationError, "No route matches [#{uri.path}]"
    end
  end
end