Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 4d3328f041
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 40 lines (31 sloc) 1.224 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
class RailsMetricsGenerator < Rails::Generators::NamedBase
  class_option :migration, :type => :boolean, :default => true

  class_option :update, :type => :boolean, :default => false,
                        :desc => "Just update public files, do not create a model"

  def self.source_root
    @_metrics_source_root ||= File.dirname(__FILE__)
  end

  def copy_public_files
    directory "../../public", "public", :recursive => true
    exit(0) if options.update?
  end

  def invoke_model
    invoke "model", [name].concat(migration_columns),
      :timestamps => false, :test_framework => false, :migration => options.migration?
  end

  def add_model_config
    inject_into_class "app/models/#{file_name}.rb", class_name, <<-CONTENT
include RailsMetrics::ORM::#{Rails::Generators.options[:rails][:orm].to_s.camelize}
CONTENT
  end

  def add_application_config
    inject_into_class "config/application.rb", "Application", <<-CONTENT
# Set rails metrics store
config.rails_metrics.set_store = lambda { ::#{class_name} }

CONTENT
  end

  protected

  def migration_columns
    %w(name:string duration:integer request_id:integer parent_id:integer payload:text started_at:datetime created_at:datetime)
  end
end
Something went wrong with that request. Please try again.