Class: Mariner::Url

Inherits:
Object
  • Object
show all
Defined in:
lib/mariner/url.rb

Overview

Public: Represents a Url configuration.

Examples:

Mariner.configure do
  a_group do
    root_path "A Link" # <= This ends up being a Url instance.
  end
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, title, options = {}) ⇒ Url

Public: Create a new Url

name - The method name that corresponds to a Rails route helper title - The text that should be rendered to represent a url. options - Any link options that should be present. Used by the

renderer (default: {})


24
25
26
# File 'lib/mariner/url.rb', line 24

def initialize(name, title, options={})
  @name, @title, @options = name, title, options
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



15
16
17
# File 'lib/mariner/url.rb', line 15

def name
  @name
end

#optionsObject

Returns the value of attribute options.



15
16
17
# File 'lib/mariner/url.rb', line 15

def options
  @options
end

#titleObject

Returns the value of attribute title.



15
16
17
# File 'lib/mariner/url.rb', line 15

def title
  @title
end

Instance Method Details

#hrefObject

Public: Calls the Rails route helper method to get its href.



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/mariner/url.rb', line 39

def href
  begin
    # The link's name should be the method name
    # for a rails route helper. We're including the route
    # helpers in an initializer, so this will only fail if
    # the route is undefined.
    #
    send(name)
  rescue NoMethodError => e
    raise ::Mariner::Errors::InvalidUrlHelperMethod.new(name)
  end
end

#render(rendering_strategy = Mariner.rendering_strategies[:default]) ⇒ Object

Public: Renders itself through a rendering strategy.

rendering_strategy - The rendering strategy to use. Must respond to

#render (default: UnorderedListRenderer.new)


33
34
35
# File 'lib/mariner/url.rb', line 33

def render(rendering_strategy=Mariner.rendering_strategies[:default])
  rendering_strategy.factory(:item, self).render
end