class Tennpipes::Generators::App

Responsible for applications within a Tennpipes project. Creates and mounts the application and gives the user related information.

Public Class Methods

banner() click to toggle source
source_root() click to toggle source
# File lib/tennpipes-init/generators/app.rb, line 12
def self.source_root; File.expand_path(File.dirname(__FILE__)); end

Public Instance Methods

create_app() click to toggle source

Copies over the Tennpipes base admin application.

# File lib/tennpipes-init/generators/app.rb, line 32
def create_app
  self.destination_root = options[:root]
  underscore_name = name.gsub(/\W/, '_')
  @app_folder = underscore_name.underscore
  @app_name   = underscore_name.camelize
  if in_app_root?
    @project_name = options[:namespace].underscore.camelize
    @project_name = fetch_project_name(@app_folder) if @project_name.empty?

    if options[:destroy]
      self.behavior = :revoke
    else
      unless options[:force]
        say "#{@app_name} already exists."
        say "Please, change the name."
        return
      end
    end if already_exists?(@app_name, @project_name)

    lowercase_app_folder = @app_folder.downcase
    app_skeleton(lowercase_app_folder, options[:tiny])
    empty_directory destination_root("public/#{lowercase_app_folder}")

    mount_command = "\nTennpipes.mount('#{@project_name}::#{@app_name}', :app_file => Tennpipes.root('#{lowercase_app_folder}/app.rb')).to('/#{lowercase_app_folder}')\n"
    if File.read(destination_root('config/apps.rb')).match(/^Tennpipes.mount.*\.to\('\/'\)$/)
      inject_into_file destination_root('config/apps.rb'), mount_command, :before => /^Tennpipes.mount.*\.to\('\/'\)$/
    else
      append_file destination_root('config/apps.rb'), mount_command
    end

    return if self.behavior == :revoke
    say
    say '=' * 65, :green
    say "Your #{@app_name} application has been installed."
    say '=' * 65, :green
    say "This application has been mounted to /#{@app_name.downcase}"
    say "You can configure a different path by editing 'config/apps.rb'"
  else
    say 'You are not at the root of a Tennpipes application! (config/boot.rb not found)'
  end
end