Module: PoiseService::Utils

Extended by:
Utils
Included in:
Utils
Defined in:
lib/poise_service/utils.rb

Overview

Utility methods for PoiseService.

Since:

  • 1.0.0

Constant Summary collapse

COMMON_SEGMENTS =

Common segments to ignore

Since:

  • 1.0.0

%w{var www current etc}.inject({}) {|memo, seg| memo[seg] = true; memo }

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse_service_name(path) ⇒ String

Parse the service name from a path. Look at the last component of the path, ignoring some common names.

Examples:

attribute(:service_name, kind_of: String, default: lazy { PoiseService::Utils.parse_service_name(path) })

Parameters:

  • path (String)

    Path to parse.

Returns:

  • (String)

Since:

  • 1.0.0



39
40
41
42
43
# File 'lib/poise_service/utils.rb', line 39

def parse_service_name(path)
  parts = Pathname.new(path).each_filename.to_a.reverse!
  # Find the last segment not in common segments, fall back to the last segment.
  parts.find {|seg| !COMMON_SEGMENTS[seg] } || parts.first
end

Instance Method Details

#parse_service_name(path) ⇒ String

Parse the service name from a path. Look at the last component of the path, ignoring some common names.

Examples:

attribute(:service_name, kind_of: String, default: lazy { PoiseService::Utils.parse_service_name(path) })

Parameters:

  • path (String)

    Path to parse.

Returns:

  • (String)

Since:

  • 1.0.0



39
40
41
42
43
# File 'lib/poise_service/utils.rb', line 39

def parse_service_name(path)
  parts = Pathname.new(path).each_filename.to_a.reverse!
  # Find the last segment not in common segments, fall back to the last segment.
  parts.find {|seg| !COMMON_SEGMENTS[seg] } || parts.first
end