Class: Abid::Application
- Inherits:
-
Rake::Application
- Object
- Rake::Application
- Abid::Application
- Includes:
- TaskManager
- Defined in:
- lib/abid/application.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#worker ⇒ Object
readonly
Returns the value of attribute worker.
Instance Method Summary collapse
-
#abid_options ⇒ Object
:nodoc:.
-
#abidfile ⇒ Object
allows the built-in tasks to load without a abidfile.
- #database ⇒ Object
- #default_config ⇒ Object
- #default_database_config ⇒ Object
- #handle_options ⇒ Object
-
#initialize ⇒ Application
constructor
A new instance of Application.
-
#invoke_task(task_string) ⇒ Object
:nodoc:.
-
#load_rakefile ⇒ Object
load built-in tasks.
- #run ⇒ Object
- #run_with_threads ⇒ Object
- #standard_rake_options ⇒ Object
Methods included from TaskManager
#[], #define_mixin, #define_play, #lookup_play_class, #play_base, record_task_metadata
Constructor Details
#initialize ⇒ Application
Returns a new instance of Application.
8 9 10 11 12 13 14 15 |
# 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 |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/abid/application.rb', line 6 def config @config end |
#worker ⇒ Object (readonly)
Returns the value of attribute worker.
5 6 7 |
# File 'lib/abid/application.rb', line 5 def worker @worker end |
Instance Method Details
#abid_options ⇒ Object
:nodoc:
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/abid/application.rb', line 78 def # :nodoc: ( [ ['--retry-failed-job', 'Retry failed job.', proc { .retry_failed_job = true } ], ['--repair', 'Run the task in repair mode.', proc { .repair = true } ], ['--preview', '-p', 'Run tasks in preview mode.', proc do .preview = true end ], ['--wait-external-task', 'Wait a task finished if it is running in externl process', proc do .wait_external_task_interval = true end ] ] ) end |
#abidfile ⇒ Object
allows the built-in tasks to load without a abidfile
23 24 25 |
# File 'lib/abid/application.rb', line 23 def abidfile File.(File.join(File.dirname(__FILE__), '..', 'Abidfile.rb')) end |
#database ⇒ Object
133 134 135 136 137 138 139 140 141 |
# 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 ⇒ Object
51 52 53 |
# File 'lib/abid/application.rb', line 51 def default_config {} end |
#default_database_config ⇒ Object
55 56 57 58 59 60 61 |
# 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 ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/abid/application.rb', line 105 def .rakelib = %w(rakelib tasks) .trace_output = $stderr OptionParser.new do |opts| opts. = '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:' .each { |args| opts.on(*args) } opts.separator '' opts.separator 'Advanced 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 |
#invoke_task(task_string) ⇒ Object
:nodoc:
46 47 48 49 |
# File 'lib/abid/application.rb', line 46 def invoke_task(task_string) # :nodoc: name, args = parse_task_string(task_string) self[name].async_invoke(*args).wait! end |
#load_rakefile ⇒ Object
load built-in tasks
28 29 30 31 32 33 34 35 |
# File 'lib/abid/application.rb', line 28 def load_rakefile standard_exception_handling do glob(File.('../tasks/*.rake', __FILE__)) do |name| Rake.load_rakefile name end end super end |
#run ⇒ Object
17 18 19 20 |
# File 'lib/abid/application.rb', line 17 def run Abid.application = self super end |
#run_with_threads ⇒ Object
37 38 39 40 41 42 43 44 |
# 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 ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/abid/application.rb', line 63 def 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 |