require 'rails/generators/active_record'
require 'dunlop/generators'
class Dunlop::Install::SourceFilesGenerator < Rails::Generators::Base
  include Rails::Generators::Migration
  include Dunlop::Generators::GeneratorHelpers
  source_root File.expand_path('../templates', __FILE__)

  def setup_source_files_with_other_name
    copy_file "rspec/source_files_factory.rb", "spec/factories/source_files.rb"
    copy_file "models/source_file.rb", "app/models/source_file.rb"

    FileUtils.mkdir_p Rails.root.join("storage")
    inject_into_file "config/environments/development.rb", after: "class Application < Rails::Application\n" do <<-RUBY
    config.file_storage_path = Rails.root.join('storage') # source file storage
    config.working_path = '/tmp' # source file processing directory

    RUBY
    end

    FileUtils.mkdir_p Rails.root.join("tmp/storage")
    inject_into_file "config/environments/test.rb", after: "class Application < Rails::Application\n" do <<-RUBY
    config.file_storage_path = Rails.root.join('tmp/storage') # source file storage
    config.working_path = '/tmp' # source file processing directory

    RUBY
    end

    inject_into_file "config/environments/production.rb", after: "class Application < Rails::Application\n" do <<-RUBY
    config.file_storage_path = File.readlink(Rails.root.join('storage')) # source file storage
    config.working_path = '/tmp' # source file processing directory

    RUBY
    end

    migration_template "migrations/create_source_files.rb", "db/migrate/create_source_files.rb"
    directory "locales", "config/locales"
  end
end
