Sha256: 8cb047b0fc7a12c78460c529110d63776c085510bd19d0d8667111532295187c

Contents?: true

Size: 986 Bytes

Versions: 16

Compression:

Stored size: 986 Bytes

Contents

class WagonGenerator < Rails::Generators::NamedBase #:nodoc:
  attr_reader :wagon_name

  source_root File.expand_path('../templates', __FILE__)

  def initialize(*args)
    super
    @wagon_name = name
    assign_names!("#{application_name}_#{name}")
  end

  def copy_templates
    self.destination_root = "vendor/wagons/#{wagon_name}"

    # do this whole manual traversal to be able to replace every single file
    # individually in the application.
    all_templates.each do |file|
      if File.basename(file) == '.empty_directory'
        file = File.dirname(file)
        directory(file, File.join(destination_root, file))
      else
        template(file, File.join(destination_root, file.sub(/\.tt$/, '')))
      end
    end
  end

  private

  def all_templates
    source_paths.map do |path|
      Dir[File.join(path, '**', '{*,.[a-z]*}')].
          select { |f| File.file?(f) }.
          map { |f| f.sub(path + File::SEPARATOR, '') }
    end.flatten.uniq.sort
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
wagons-0.8.0 lib/generators/wagon/wagon_generator.rb
wagons-0.7.0 lib/generators/wagon/wagon_generator.rb
wagons-0.6.1 lib/generators/wagon/wagon_generator.rb
wagons-0.6.0 lib/generators/wagon/wagon_generator.rb
wagons-0.5.0 lib/generators/wagon/wagon_generator.rb
wagons-0.4.8 lib/generators/wagon/wagon_generator.rb
wagons-0.4.7 lib/generators/wagon/wagon_generator.rb
wagons-0.4.6 lib/generators/wagon/wagon_generator.rb
wagons-0.4.5 lib/generators/wagon/wagon_generator.rb
wagons-0.4.4 lib/generators/wagon/wagon_generator.rb
wagons-0.4.3 lib/generators/wagon/wagon_generator.rb
wagons-0.4.2 lib/generators/wagon/wagon_generator.rb
wagons-0.4.1 lib/generators/wagon/wagon_generator.rb
wagons-0.4.0 lib/generators/wagon/wagon_generator.rb
wagons-0.3.1 lib/generators/wagon/wagon_generator.rb
wagons-0.3.0 lib/generators/wagon/wagon_generator.rb