Skip to content

s-osa/oneshot_task_generator

Repository files navigation

Build Status Gem Version

OneshotTaskGenerator

Simple rake task generator for oneshot tasks.

$ bin/rails generate oneshot FooBar
      create  lib/tasks/oneshot/20180205_foo_bar.rake

Then, skeleton file for oneshot rake task will be generated.

# Skeleton for this file was generated by `bin/rails generate oneshot FooBar`
# For copy and paste: `bin/rake oneshot:foo_bar_20180205`
namespace :oneshot do
  desc ''
  task foo_bar_20180205: :environment do
  end
end

Installation

Add this line to your application's Gemfile:

gem 'oneshot_task_generator', group: :development

And then execute:

$ bundle

Customization

Task Body

# config/initializers/oneshot_task_generator.rb
OneshotGenerator.configure do |config|
  config.body = <<-BODY
ActiveRecord::Base.transaction do
  # Write transactional code here
end
  BODY
end
# Skeleton for this file was generated by `bin/rails generate oneshot FooBar`
# For copy and paste: `bin/rake oneshot:foo_bar_20180208`
namespace :oneshot do
  desc ''
  task foo_bar_20180208: :environment do
    ActiveRecord::Base.transaction do
      # Write transactional code here
    end
  end
end

Arguments

# config/initializers/oneshot_task_generator.rb
OneshotGenerator.configure do |config|
  config.arguments = ['task', 'args']
end
# Skeleton for this file was generated by `bin/rails generate oneshot FooBar`
# For copy and paste: `bin/rake oneshot:foo_bar_20180208`
namespace :oneshot do
  desc ''
  task foo_bar_20180208: :environment do |task, args|
  end
end

Directory

# config/initializers/oneshot_task_generator.rb
OneshotGenerator.configure do |config|
  config.directory = 'your/favorite/directory' # Default: lib/tasks/oneshot
end

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/s-osa/oneshot_task_generator.

About

Oneshot task generator for Rails

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •