Module: Assertion::Inflector Private

Extended by:
Transproc::Registry
Defined in:
lib/assertion/inflector.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

TODO:

Extract this module to the external gem ‘transproc-inflector`

The collection of pure functions for converting constants to corresponding path names.

Instance Method Summary collapse

Instance Method Details

#to_path(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



20
21
22
# File 'lib/assertion/inflector.rb', line 20

def to_path(name)
  name.split(%r{\:\:|-|/}).reject(&:empty?).join("/")
end

#to_snake(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



15
16
17
# File 'lib/assertion/inflector.rb', line 15

def to_snake(name)
  name.gsub(/([a-z])([A-Z])/, '\1_\2').gsub(/_+/, "_").downcase
end

#to_snake_path(name) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts the name of the constant to the corresponding path

Examples:

fn = Inflector[:to_snake_path]
fn["::Foo::BarBaz"]
# => "foo/bar_baz"

Parameters:

  • name (String)

    The name of the constant

Returns:

  • (String)

    The path



35
36
37
# File 'lib/assertion/inflector.rb', line 35

def to_snake_path(name)
  to_path(to_snake(name))
end