module Cult
This extends Terminal::Table to do plain tab-separated columns if Rainbow is disabled, which roughly translates to isatty?
A lot of times, we want a sequential array of objects, but it'd still be really convenient to refer to things by their name. This is particularly painful in the console, where, e.g., nodes can only be referred to by index, and you end up calling `find` a lot.
NamedArray
is an array, but overloads [] to also work with a String
, Symbol, Regexp, or a few other things. e.g., nodes. It works by finding the first item who responds from `named_array_identifier` with the matching key.
By default named_array_identifier returns name, but this can be overridden.
Cult.paramap
runs a block in forked-off parallel processes. There are very little restrictions on what can be done in the block, but:
1. The value returned or any exceptions raised need to be Marshal-able. 2. The blocks actually need to resume execution, so things like `exec` cause problems.
The result of paramap is an array corresponding with each value ran through the block. There are a few exception strategies:
-
:raise The first job to throw an exception halts all further work and the exception is passed up
-
:collect All jobs are allowed to complete, any exceptions encounted are tagged on the results in an `exception` method, which returns an array each element will either be 'nil' for no exception, or the Exception object the job raised.
These are refinements we enable in a user-facing context, e.g., the console or template files.
Constants
- VERSION
Attributes
Public Class Methods
# File lib/cult.rb, line 41 def concurrency defined?(@concurrency) ? @concurrency : :max end
# File lib/cult.rb, line 32 def concurrency=(v) unless v == :max || (v.is_a?(Integer) && v >= 0) fail CLI::CLIError, "concurrency must be a positive integer or :max" end v = 1 if v == 0 @concurrency = v end
# File lib/cult.rb, line 46 def env_flag(s, default = false) case (v = ENV[s]) when /^0|false|no|n$/i false when /^1|true|yes|y$/i true when nil default else fail CLI::CLIError, "Invalid value for boolean #{s}: #{v}" end end
# File lib/cult.rb, line 27 def singletons? defined?(@singletons) ? @singletons : env_flag('CULT_SINGLETONS', true) end
Public Instance Methods
# File lib/cult/paramap.rb, line 223 def paramap(enum, quiet: false, concurrent: nil, exception: :raise, &block) rebind = quiet ? { stdout: nil, stderr: nil } : {} Paramap.new(enum, rebind: rebind, concurrent: concurrent, exception_strategy: exception, &block).run end