Skip to content

Commit

Permalink
change: changed task names instead of filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
Shigeyuki-fukuda committed May 31, 2020
1 parent b4ef854 commit 497d34a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/generators/oneshot/oneshot_generator.rb
Expand Up @@ -10,7 +10,7 @@ class OneshotGenerator < Rails::Generators::NamedBase
def setup
@current = Time.current
@timestamp = @current.strftime('%Y%m%d')
@task_name = "#{name.underscore}_#{timestamp}"
@task_name = "#{timestamp}_#{name.underscore}"
@configuration = self.class.configuration
end

Expand Down
2 changes: 1 addition & 1 deletion lib/generators/oneshot/templates/oneshot.rake.erb
Expand Up @@ -4,7 +4,7 @@
<%= "# For copy and paste: `bin/rake oneshot:#{task_name}`" %>
namespace :oneshot do
desc ''
task <%= task_name %>: :environment do<%= configuration.arguments && " |#{configuration.arguments.join(", ")}|" %>
task <%= "'#{task_name}'" %>: :environment do<%= configuration.arguments && " |#{configuration.arguments.join(", ")}|" %>
<%- if configuration.body -%>
<%= configuration.body.indent(4) %>
<%- end -%>
Expand Down
4 changes: 2 additions & 2 deletions spec/generators/oneshot/oneshot_generator_spec.rb
Expand Up @@ -34,7 +34,7 @@

it 'generate a file with specific file name' do
file_name = File.basename(Dir.glob("tmp/lib/tasks/oneshot/*").first)
expect(file_name).to match(/foo_bar_\d{8}.rake/)
expect(file_name).to match(/\d{8}_foo_bar.rake/)
end

it 'is valid as ruby' do
Expand Down Expand Up @@ -97,7 +97,7 @@
it 'inserts the arguments' do
file_name = Dir.glob("tmp/lib/tasks/oneshot/*").first
generated_text = File.read(file_name)
expect(generated_text).to match(/^ task foo_bar_\d{8}: :environment do \|task, args\|$/)
expect(generated_text).to match(/^ task '\d{8}_foo_bar': :environment do \|task, args\|$/)
end

it 'is valid as ruby' do
Expand Down

0 comments on commit 497d34a

Please sign in to comment.