Skip to content

Commit

Permalink
Added generators.
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Feb 15, 2010
1 parent 6c37d39 commit f1d2969
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion MIT-LICENSE
@@ -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 Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the a copy of this software and associated documentation files (the
Expand Down
36 changes: 36 additions & 0 deletions lib/generators/rails_metrics_generator.rb
@@ -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.