Module: Reek::DocumentationLink

Defined in:
lib/reek/documentation_link.rb

Overview

Generate versioned links to our documentation

Constant Summary collapse

'https://github.com/troessner/reek/blob/v%<version>s/docs/%<item>s.md'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build(subject) ⇒ String

Build link to the documentation about the given subject for the current version of Reek. The subject can be either a smell type like ‘FeatureEnvy’ or a general subject like ‘Rake Task’.

Parameters:

  • subject (String)

Returns:

  • (String)

    the full URL for the relevant documentation



16
17
18
# File 'lib/reek/documentation_link.rb', line 16

def build(subject)
  Kernel.format(HELP_LINK_TEMPLATE, version: Version::STRING, item: name_to_param(subject))
end

.name_to_param(name) ⇒ Object

Convert the given subject name to a form that is acceptable in a URL, by dasherizeing it at the start of capitalized words. Spaces are discared.



22
23
24
# File 'lib/reek/documentation_link.rb', line 22

def name_to_param(name)
  name.split(/([A-Z][a-z][a-z]*)/).map(&:strip).reject(&:empty?).join('-')
end

Instance Method Details

#build(subject) ⇒ String (private)

Build link to the documentation about the given subject for the current version of Reek. The subject can be either a smell type like ‘FeatureEnvy’ or a general subject like ‘Rake Task’.

Parameters:

  • subject (String)

Returns:

  • (String)

    the full URL for the relevant documentation



16
17
18
# File 'lib/reek/documentation_link.rb', line 16

def build(subject)
  Kernel.format(HELP_LINK_TEMPLATE, version: Version::STRING, item: name_to_param(subject))
end

#name_to_param(name) ⇒ Object (private)

Convert the given subject name to a form that is acceptable in a URL, by dasherizeing it at the start of capitalized words. Spaces are discared.



22
23
24
# File 'lib/reek/documentation_link.rb', line 22

def name_to_param(name)
  name.split(/([A-Z][a-z][a-z]*)/).map(&:strip).reject(&:empty?).join('-')
end