Module: Hanami::Utils

Defined in:
lib/hanami/utils.rb,
lib/hanami/utils/io.rb,
lib/hanami/utils/hash.rb,
lib/hanami/utils/json.rb,
lib/hanami/utils/blank.rb,
lib/hanami/utils/class.rb,
lib/hanami/utils/files.rb,
lib/hanami/utils/kernel.rb,
lib/hanami/utils/string.rb,
lib/hanami/utils/version.rb,
lib/hanami/utils/callbacks.rb,
lib/hanami/utils/file_list.rb,
lib/hanami/utils/load_paths.rb,
lib/hanami/utils/deprecation.rb,
lib/hanami/utils/path_prefix.rb,
lib/hanami/utils/shell_color.rb,
lib/hanami/utils/query_string.rb,
lib/hanami/utils/class_attribute.rb,
lib/hanami/utils/class_attribute/attributes.rb

Overview

Ruby core extentions and Hanami utilities

Since:

  • 0.1.0

Defined Under Namespace

Modules: Callbacks, ClassAttribute, FileList, Files, Hash, Json, Kernel, QueryString, ShellColor, String Classes: Blank, Class, Deprecation, IO, LoadPaths, PathPrefix

Constant Summary collapse

HANAMI_JRUBY =

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

Since:

  • 0.3.1

API:

  • private

"java"
HANAMI_RUBINIUS =

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

Since:

  • 0.3.1

API:

  • private

"rbx"
VERSION =

The current hanami-utils version.

Since:

  • 0.1.0

API:

  • public

"2.3.0"

Class Method Summary collapse

Class Method Details

.for_each_file_in(directory, &blk) ⇒ 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.

Recursively scans through the given directory and yields the given block for each Ruby source file.

If the directory is relative, it implies it’s the path from current directory. If the directory is absolute, it uses as it is.

It respects file separator of the current operating system. A pattern like "path/to/files" will work both on *NIX and Windows machines.

Since:

  • 1.0.0

Parameters:

  • the directory

  • the block to yield

API:

  • private



73
74
75
76
77
78
79
# File 'lib/hanami/utils.rb', line 73

def self.for_each_file_in(directory, &blk)
  directory = directory.to_s.gsub(%r{(/|\\)}, File::SEPARATOR)
  directory = Pathname.new(Dir.pwd).join(directory).to_s
  directory = File.join(directory, "**", "*.rb") unless directory =~ /(\*\*)/

  FileList[directory].each(&blk)
end

.jruby?TrueClass, FalseClass

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.

Checks if the current VM is JRuby

Since:

  • 0.3.1

Returns:

  • info whether the VM is JRuby or not

API:

  • private



30
31
32
# File 'lib/hanami/utils.rb', line 30

def self.jruby?
  RUBY_PLATFORM == HANAMI_JRUBY
end

.require!(directory) ⇒ Object

Recursively requires Ruby files under the given directory.

If the directory is relative, it implies it’s the path from current directory. If the directory is absolute, it uses as it is.

It respects file separator of the current operating system. A pattern like "path/to/files" will work both on *NIX and Windows machines.

Since:

  • 0.9.0

Parameters:

  • the directory



55
56
57
# File 'lib/hanami/utils.rb', line 55

def self.require!(directory)
  for_each_file_in(directory) { |file| require_relative(file) }
end

.rubinius?TrueClass, FalseClass

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.

Checks if the current VM is Rubinius

Since:

  • 0.3.1

Returns:

  • info whether the VM is Rubinius or not

API:

  • private



40
41
42
# File 'lib/hanami/utils.rb', line 40

def self.rubinius?
  RUBY_ENGINE == HANAMI_RUBINIUS
end