module Fasten
Constants
- VERSION
Attributes
logger[RW]
Public Class Methods
cleanup()
click to toggle source
# File lib/fasten.rb, line 29 def cleanup @runner = nil end
default_developer()
click to toggle source
# File lib/fasten/defaults.rb, line 43 def default_developer $stdin.tty? && $stdout.tty? end
default_fasten_dir()
click to toggle source
# File lib/fasten/defaults.rb, line 25 def default_fasten_dir 'fasten' end
default_jobs()
click to toggle source
# File lib/fasten/defaults.rb, line 17 def default_jobs Parallel.physical_processor_count end
default_name()
click to toggle source
# File lib/fasten/defaults.rb, line 5 def default_name File.basename(Dir.getwd) end
default_priority()
click to toggle source
# File lib/fasten/defaults.rb, line 47 def default_priority :dependants end
default_stats()
click to toggle source
# File lib/fasten/defaults.rb, line 9 def default_stats true end
default_summary()
click to toggle source
# File lib/fasten/defaults.rb, line 13 def default_summary false end
default_ui_mode()
click to toggle source
# File lib/fasten/defaults.rb, line 33 def default_ui_mode return @default_ui_mode if defined? @default_ui_mode require 'fasten/ui/curses' @default_ui_mode = $stdin.tty? && $stdout.tty? ? :curses : :console rescue StandardError, LoadError @default_ui_mode = :console end
default_use_threads()
click to toggle source
# File lib/fasten/defaults.rb, line 29 def default_use_threads !OS.posix? end
default_worker_class()
click to toggle source
# File lib/fasten/defaults.rb, line 21 def default_worker_class Worker end
invoke()
click to toggle source
# File lib/fasten.rb, line 111 def invoke opt_parser.parse! @options[:targets] = ARGV.to_a runner @options @load_path = Dir['fasten/*_fasten.rb'] if @load_path.empty? load_fasten @load_path show_help 1 if runner.tasks.empty? runner.perform end
load_fasten(args)
click to toggle source
# File lib/fasten.rb, line 41 def load_fasten(args) args.each do |path| if File.directory? path items = Dir["#{path}/*_fasten.rb"] items.each do |item| puts "Fasten: loading #{item}" load item end elsif File.file? path puts "Fasten: loading #{path}" load path else warn "Fasten: file/folder not found: #{path}" exit 1 end end end
map(list, **options, &block)
click to toggle source
# File lib/fasten.rb, line 21 def map(list, **options, &block) runner(**options).map(list, &block) end
opt_parser()
click to toggle source
# File lib/fasten.rb, line 59 def opt_parser # rubocop:disable Metrics/MethodLength, Metrics/AbcSize return @opt_parser if defined? @opt_parser @options = { developer: false } @load_path = [] @opt_parser = OptionParser.new do |opts| # rubocop:disable Metrics/BlockLength opts.banner = "Usage: #{$PROGRAM_NAME} [options] [targets]" opts.separator '' opts.separator 'Examples:' opts.separator ' fasten # load and run all task from fasten/*_fasten.rb' opts.separator ' fasten -f tasks.rb # load task from ruby script' opts.separator ' fasten -y tasks.yml # load task from yaml file' opts.separator '' opts.separator 'Options:' opts.on '-n NAME', '--name NAME', String, "Change name of this runner (default: #{default_name} from current directory)" do |name| @options[:name] = name end opts.on '-f PATH', '--file PATH', String, 'File or folder with ruby code' do |path| @load_path << path end opts.on '-j JOBS', '--jobs JOBS', Numeric, "Maximum number of tasks to execute in parallel (default: #{default_jobs} on this machine)" do |jobs| @options[:jobs] = jobs end opts.on '-s', '--[no-]summary', TrueClass, 'Display summary at the end of execution' do |boolean| @options[:summary] = boolean end opts.on '--ui=UI', String, "Type of UI: curses, console. (default: #{default_ui_mode} on this machine)" do |ui_mode| @options[:ui_mode] = ui_mode end opts.on '-t', '--threads', "Use threads based jobs for parallel execution#{default_use_threads && ' (default on this machine)' || nil}" do @options[:use_threads] = true end opts.on '-p', '--processes', "Use process based jobs for parallel execution#{!default_use_threads && ' (default on this machine)' || nil}" do @options[:use_threads] = false end opts.on '-v', '--version', 'Display version info' do puts Fasten::VERSION exit 0 end opts.on_tail '-h', '--help', 'Shows this help' do show_help end end end
reconfigure(**options)
click to toggle source
# File lib/fasten.rb, line 33 def reconfigure(**options) runner.reconfigure(**options) end
register(**options, &block)
click to toggle source
# File lib/fasten.rb, line 37 def register(**options, &block) runner(**options).register(&block) end
runner(**options)
click to toggle source
# File lib/fasten.rb, line 25 def runner(**options) @runner ||= Fasten::Runner.new(**options) end
runner_from_yaml(path, **options)
click to toggle source
# File lib/fasten.rb, line 14 def runner_from_yaml(path, **options) runner = Fasten::Runner.new(**options) runner.load_yaml(path) runner end
show_help(exit_code = 0)
click to toggle source
# File lib/fasten.rb, line 106 def show_help(exit_code = 0) puts opt_parser exit exit_code end