Permalink
Browse files

Added generators.

  • Loading branch information...
1 parent 6c37d39 commit f1d2969bf8926482c87215fbfc7388661faf8aa9 @josevalim josevalim committed Feb 15, 2010
Showing with 37 additions and 1 deletion.
  1. +1 −1 MIT-LICENSE
  2. +36 −0 lib/generators/rails_metrics_generator.rb
View
@@ -1,4 +1,4 @@
-Copyright 2009 Plataforma Tecnologia. http://blog.plataformatec.com.br
+Copyright 2010 Engine Yard. http://www.engineyard.com
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
@@ -0,0 +1,36 @@
+class RailsMetricsGenerator < Rails::Generators::NamedBase
+ class_option :migration, :type => :boolean, :default => true
+
+ def self.source_root
+ @_metrics_source_root ||= File.dirname(__FILE__)
+ 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
+
+ def copy_public_files
+ directory "../../public", "public", :recursive => true
+ 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

0 comments on commit f1d2969

Please sign in to comment.