Class: Pgq::AddGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/pgq/add_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(path) ⇒ Object



9
10
11
# File 'lib/generators/pgq/add_generator.rb', line 9

def self.next_migration_number(path)
  Time.now.utc.strftime("%Y%m%d%H%M%S")
end

Instance Method Details

#add_filesObject



25
26
27
28
29
# File 'lib/generators/pgq/add_generator.rb', line 25

def add_files
  template "pgq_class.rb", "app/workers/pgq_#{file_path}.rb"
  template "spec.rb", "spec/workers/pgq_#{file_path}_spec.rb"
  migration_template "migration.rb", "db/migrate/create_#{file_path}_queue.rb"
end

#add_to_queues_listObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/generators/pgq/add_generator.rb', line 13

def add_to_queues_list
  filename = Rails.root + 'config/queues_list.yml'
  if File.exists?(filename)
    x = YAML.load_file(filename)
    x << name
    File.open(filename, 'w'){|f| f.write(YAML.dump(x))}
  else
    x = [name]
    File.open(filename, 'w'){|f| f.write(YAML.dump(x))}
  end
end