Module: Wright::Util Private

Defined in:
lib/wright/util.rb,
lib/wright/util/user.rb,
lib/wright/util/file.rb,
lib/wright/util/color.rb,
lib/wright/util/file_owner.rb,
lib/wright/util/file_permissions.rb,
lib/wright/util/recursive_autoloader.rb,
lib/wright/util/stolen_from_activesupport.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.

Various utility functions.

Defined Under Namespace

Modules: ActiveSupport, Color, File, RecursiveAutoloader, User Classes: FileOwner, FilePermissions

Class Method Summary collapse

Class Method Details

.bundler_clean_envObject

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.

Runs a code block in a clean bundler environment.

Examples:

Wright::Util.bundler_clean_env { `brew search /^git$/` }# => "git\n"

Returns:

  • (Object)

    the return value of the code block


81
82
83
84
85
86
87
# File 'lib/wright/util.rb', line 81

def self.bundler_clean_env
  if defined?(Bundler)
    Bundler.with_clean_env { yield }
  else
    yield
  end
end

.class_to_resource_name(klass) ⇒ 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 a class constant into its corresponding resource name.

Examples:

Wright::Util.class_to_resource_name(Wright::Resource::Package)# => "package"


Wright::Util.class_to_resource_name(Foo::Bar::BazQux)# => "baz_qux"

Parameters:

  • klass (Class)

    the class constant

Returns:

  • (String)

    the resource name of the given class


19
20
21
# File 'lib/wright/util.rb', line 19

def self.class_to_resource_name(klass)
  ActiveSupport.underscore(klass.name).split('/').last
end

.distroObject (private)

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.


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

def self.distro
  default = 'linux'
  release_file = '/etc/os-release'
  return default unless ::File.exist?(release_file)

  os_release = ::File.read(release_file)
  /^ID_LIKE="?(?<id_like>[^"]*)"?$/ =~ os_release
  /^ID="?(?<id>[^"]*)"?$/ =~ os_release
  return id_like.split(' ').first if id_like
  id || default
end

.filename_to_classname(filename) ⇒ 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 a file path into its corresponding class name.

Examples:

Wright::Util.filename_to_classname('foo/bar/baz.rb')# => "Foo::Bar::Baz"


Wright::Util.filename_to_classname('foo/bar/')# => "Foo::Bar"

Parameters:

  • filename (String)

    the filename

Returns:

  • (String)

    the class name for the given filename


35
36
37
# File 'lib/wright/util.rb', line 35

def self.filename_to_classname(filename)
  ActiveSupport.camelize(filename.chomp('.rb').chomp('/'))
end

.os_familyString

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.

Determines the system's OS family.

Examples:

Wright::Util.os_family# => "debian"
Wright::Util.os_family# => "macosx"

Returns:

  • (String)

    the system's OS family (base distribution for GNU/Linux systems) or 'other' for unknown operating systems


63
64
65
66
67
68
69
70
71
72
73
# File 'lib/wright/util.rb', line 63

def self.os_family
  system_arch = RbConfig::CONFIG['target_os']
  case system_arch
  when /darwin/
    'macosx'
  when /linux/
    distro
  else
    'other'
  end
end