class Tolaria::HelpLink

Class representing a configured Tolaria help link.

Attributes

markdown_file[R]

The file path to the Markdown file

slug[R]

Part part of the link at `/admin/help/:slug` when rendering a Markdown file

title[R]

The title of the link

Public Class Methods

new(title:, slug:nil, markdown_file:nil, link_to:nil) click to toggle source

Create a new HelpLink with the passed settings. You must provide `title`, the title of the link. To configure automatic rendering of a Markdown file, provide a string `slug` and the path to a `markdown_file`. A route to view the file will be constructed for you at `/admin/help/:slug`. To link to an arbitrary path or URI, provide it as `link_to`.

# File lib/tolaria/help_links.rb, line 38
def initialize(title:, slug:nil, markdown_file:nil, link_to:nil)
  @title = title.to_s.freeze
  @slug = slug.to_s.freeze
  @markdown_file = markdown_file.to_s.freeze
  @link_to = link_to.to_s.freeze
  validate!
end

Public Instance Methods

markdown_type?() click to toggle source

True if this HelpLink is a Markdown file.

# File lib/tolaria/help_links.rb, line 52
def markdown_type?
  markdown_file.present?
end
to_param() click to toggle source

Quack like an ActiveRecord::Base model, returns slug.

# File lib/tolaria/help_links.rb, line 57
def to_param
  slug
end
validate!() click to toggle source

Raises RuntimeError if this HelpLink is incorrectly configured.

# File lib/tolaria/help_links.rb, line 62
def validate!

  if title.blank?
    raise RuntimeError, "HelpLinks must provide a string title"
  end

  file_configured = (slug.present? && markdown_file.present?)
  link_configured = link_to.present?

  unless file_configured || link_configured
    raise RuntimeError, "Incomplete HelpLink config. You must provide link_to, or both slug and markdown_file."
  end

  if file_configured && link_configured
    raise RuntimeError, "Ambiguous HelpLink config. You must provide link_to, or both slug and markdown_file, but not all three."
  end

end