Module: ActionThrottler::Rake::ClassMethods

Defined in:
lib/tasks/rake_helper.rb

Instance Method Summary collapse

Instance Method Details

#copy_file(orig_path, dest_path, message = "") ⇒ Object

Copies a file

Parameters:

  • orig_path (String)

    original file path, absolute

  • dest_path (String)

    destination file path, relative to ‘Rails.root`

  • message (String) (defaults to: "")

    optional output message



43
44
45
46
47
48
49
50
51
52
# File 'lib/tasks/rake_helper.rb', line 43

def copy_file(orig_path, dest_path, message = "")
  dest_path = "#{Rails.root}/#{dest_path}"
  
  if File.exists?(dest_path)
    puts "'#{dest_path}' already exists, therefore it is skipped."
  else
    FileUtils.cp(orig_path, dest_path)
    puts message unless message.nil?
  end
end

#copy_initializer_file(message = "") ⇒ Object

Copies the initializer file to ‘config/initializers`

Parameters:

  • message (String) (defaults to: "")

    optional output message



28
29
30
31
32
33
34
35
36
# File 'lib/tasks/rake_helper.rb', line 28

def copy_initializer_file(message = "")
  orig_dir  = "#{File.dirname(__FILE__)}/initializer/"
  orig_file = Dir.entries(orig_dir).last
  orig_path = orig_dir + orig_file
  
  dest_path = "config/initializers/#{orig_file}"
  
  copy_file(orig_path, dest_path, message)
end

#copy_migration_file(message = "") ⇒ Object

Copies the migration file to ‘db/migrate`

Parameters:

  • message (String) (defaults to: "")

    optional output message



14
15
16
17
18
19
20
21
22
23
# File 'lib/tasks/rake_helper.rb', line 14

def copy_migration_file(message = "")
  orig_dir  = "#{File.dirname(__FILE__)}/migration/"
  orig_file = Dir.entries(orig_dir).last
  orig_path = orig_dir + orig_file
  
  prefix    = Rails::Generator::Commands::Base.new(nil).send(:next_migration_string)
  dest_path = "db/migrate/#{prefix}_#{orig_file}"
  
  copy_file(orig_path, dest_path, message)
end