class Abid::Application

Attributes

config[R]
worker[R]

Public Class Methods

new() click to toggle source
Calls superclass method Abid::TaskManager::new
# File lib/abid/application.rb, line 8
def initialize
  super
  @rakefiles = %w(abidfile Abidfile abidfile.rb Abidfile.rb) << abidfile
  @worker = Worker.new(self)

  @config = IniFile.new(content: default_config)
  @config.merge!(IniFile.load('config/abid.conf'))
end

Public Instance Methods

abidfile() click to toggle source

allows the built-in tasks to load without a abidfile

# File lib/abid/application.rb, line 23
def abidfile
  File.expand_path(File.join(File.dirname(__FILE__), '..', 'Abidfile.rb'))
end
database() click to toggle source
# File lib/abid/application.rb, line 133
def database
  return @database if @database
  if config.sections.include?('abid database')
    cfg = config['abid database'].map { |k, v| [k.to_sym, v] }.to_h
  else
    cfg = default_database_config
  end
  @database = Sequel.connect(**cfg)
end
default_config() click to toggle source
# File lib/abid/application.rb, line 51
def default_config
  {}
end
default_database_config() click to toggle source
# File lib/abid/application.rb, line 55
def default_database_config
  {
    adapter: 'sqlite',
    database: File.join(Dir.pwd, 'abid.db'),
    max_connections: 1
  }
end
handle_options() click to toggle source
# File lib/abid/application.rb, line 105
def handle_options
  options.rakelib = %w(rakelib tasks)
  options.trace_output = $stderr

  OptionParser.new do |opts|
    opts.banner = 'See full documentation at https://github.com/ojima-h/abid.'
    opts.separator ''
    opts.separator 'Show available tasks:'
    opts.separator '    bundle exec abid -T'
    opts.separator ''
    opts.separator 'Invoke (or simulate invoking) a task:'
    opts.separator '    bundle exec abid [--dry-run | --preview] TASK'
    opts.separator ''
    opts.separator 'Abid options:'
    abid_options.each { |args| opts.on(*args) }
    opts.separator ''
    opts.separator 'Advanced options:'
    standard_rake_options.each { |args| opts.on(*args) }

    opts.on_tail('-h', '--help', '-H', 'Display this help message.') do
      puts opts
      exit
    end

    opts.environment('RAKEOPT')
  end.parse!
end
load_rakefile() click to toggle source

load built-in tasks

Calls superclass method
# File lib/abid/application.rb, line 28
def load_rakefile
  standard_exception_handling do
    glob(File.expand_path('../tasks/*.rake', __FILE__)) do |name|
      Rake.load_rakefile name
    end
  end
  super
end
run() click to toggle source
Calls superclass method
# File lib/abid/application.rb, line 17
def run
  Abid.application = self
  super
end
run_with_threads() { || ... } click to toggle source
# File lib/abid/application.rb, line 37
def run_with_threads
  yield
rescue Exception => err
  worker.kill
  raise err
else
  worker.shutdown
end
standard_rake_options() click to toggle source
Calls superclass method
# File lib/abid/application.rb, line 63
def standard_rake_options
  super.each do |opt|
    case opt.first
    when '--execute-print'
      # disable short option
      opt.delete_at(1)
    when '--version'
      opt[-1] = lambda do |_value|
        puts "Abid Version: #{Abid::VERSION} (Rake Version: #{RAKEVERSION})"
        exit
      end
    end
  end
end