Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* added audit and error-handler features

* fixes for read-only option
  • Loading branch information...
commit 491f3611754ccb6f57715181b000516beac69ea1 1 parent 52abca2
@mkristian authored
Showing with 332 additions and 41 deletions.
  1. +6 −0 features/audit.feature
  2. +6 −0 features/error-handler.feature
  3. +1 −1  features/generators.feature
  4. +2 −1  ixtlan-generators.gemspec
  5. +23 −0 lib/generators/ixtlan/audit_base.rb
  6. +14 −0 lib/generators/ixtlan/audit_scaffold/audit_scaffold_generator.rb
  7. +9 −26 lib/generators/ixtlan/base.rb
  8. +37 −0 lib/generators/ixtlan/configuration_base.rb
  9. +4 −2 lib/generators/ixtlan/configuration_model/configuration_model_generator.rb
  10. +4 −2 lib/generators/ixtlan/configuration_scaffold/configuration_scaffold_generator.rb
  11. +23 −0 lib/generators/ixtlan/error_dumps_base.rb
  12. +14 −0 lib/generators/ixtlan/error_dumps_scaffold/error_dumps_scaffold_generator.rb
  13. +9 −5 lib/generators/ixtlan/setup/setup_generator.rb
  14. +1 −1  lib/generators/ixtlan/setup/templates/application_layout.html.erb
  15. +1 −1  lib/generators/ixtlan/setup/templates/gitignore
  16. 0  lib/generators/ixtlan/setup/templates/{production.yml.example → passwords.yml.example}
  17. +1 −1  lib/generators/ixtlan/setup/templates/preinitializer.rb
  18. +37 −0 lib/generators/ixtlan/templates/dynamic.rb
  19. +1 −1  lib/generators/rails/scaffold_controller/scaffold_controller/singleton_controller.rb
  20. +101 −0 output.log
  21. +7 −0 templates/audit.template
  22. +7 −0 templates/error-handler.template
  23. +12 −0 templates/files-audit/Rakefile
  24. +12 −0 templates/files-error-handler/Rakefile
View
6 features/audit.feature
@@ -0,0 +1,6 @@
+Feature: Generators for Ixtlan Audit
+
+ Scenario: a rails application which uses ixtlan-audit gem
+ Given I create new rails application with template "audit.template" and "audit" files
+ And I execute "rake audit"
+ Then the output should contain "Ixtlan::Audit::Manager"
View
6 features/error-handler.feature
@@ -0,0 +1,6 @@
+Feature: Generators for Ixtlan Error Handler
+
+ Scenario: a rails application which uses ixtlan-error-handler gem
+ Given I create new rails application with template "error-handler.template" and "error-handler" files
+ And I execute "rake error_handler"
+ Then the output should contain "Ixtlan::Errors::ErrorDumper"
View
2  features/generators.feature
@@ -3,4 +3,4 @@ Feature: Generators for Ixtlan
Scenario: Create a rails application and adding 'ixtlan-generators' gem will provide the ixtlan generators
Given I create new rails application with template "generators.template"
And I execute "rails generate"
- Then the output should contain "ixtlan:setup" and "ixtlan:configuration_model" and "ixtlan:configuration_scaffold"
+ Then the output should contain "ixtlan:setup" and "ixtlan:configuration_model" and "ixtlan:configuration_scaffold" and "ixtlan:audit_scaffold" and "ixtlan:error_dumps_scaffold"
View
3  ixtlan-generators.gemspec
@@ -1,7 +1,7 @@
# -*- mode: ruby -*-
Gem::Specification.new do |s|
s.name = 'ixtlan-generators'
- s.version = '0.2.0'
+ s.version = '0.1.3'
s.summary = 'rails generator templates for ixtlan gems'
s.description = s.summary
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
s.test_files += Dir['features/*.feature']
s.test_files += Dir['features/step_definitions/*.rb']
s.add_development_dependency 'ixtlan-core', '~> 0.6'
+ s.add_development_dependency 'ixtlan-audit', '~> 0.2.0'
s.add_development_dependency 'rails', '3.0.9'
s.add_development_dependency 'rspec', '2.6.0'
s.add_development_dependency 'cucumber', '0.9.4'
View
23 lib/generators/ixtlan/audit_base.rb
@@ -0,0 +1,23 @@
+require 'generators/ixtlan/base'
+module Ixtlan
+ module Generators
+ class AuditBase < Base
+
+ def create
+ args = []
+ if name
+ args << ARGV.shift
+ else
+ args << "audit"
+ end
+
+ args << 'login:string message:string'
+ args += ARGV
+
+ args << "--read-only --timestamps"
+
+ generate generator_name, *args
+ end
+ end
+ end
+end
View
14 lib/generators/ixtlan/audit_scaffold/audit_scaffold_generator.rb
@@ -0,0 +1,14 @@
+require 'generators/ixtlan/audit_base'
+module Ixtlan
+ module Generators
+ class AuditScaffoldGenerator < AuditBase
+
+ source_root File.expand_path('../../templates', __FILE__)
+
+ protected
+ def generator_name
+ "scaffold"
+ end
+ end
+ end
+end
View
35 lib/generators/ixtlan/base.rb
@@ -5,40 +5,23 @@ class Base < Rails::Generators::Base
argument :name, :type => :string, :required => false
+ class_option :dynamic, :type => :boolean, :default => true
+
protected
def generator_name
raise "please overwrite generator_name"
end
- public
- def create
- args = []
- if name
- args << ARGV.shift
- else
- args << "configuration"
- end
-
- if defined? ::Ixtlan::Errors
- args << "errors_keep_dump:integer"
- args << "errors_dir:string"
- args << "errors_from:string"
- args << "errors_to:string"
- end
+ def application_name
+ @application_name ||= Rails.application.class.to_s.gsub(/::/,'').sub(/Application$/, '')
+ end
- if defined? ::Ixtlan::Sessions
- args << "idle_session_timeout:integer"
- end
+ public
- if defined? ::Ixtlan::Audit
- args << "audit_keep_log:integer"
+ def create_initializer_file
+ if options[:dynamic]
+ template 'dynamic.rb', File.join('config', "initializers", "ixtlan.rb")
end
-
- args += ARGV[0, 10000] || []
-
- args << "--singleton"
-
- generate generator_name, *args
end
end
end
View
37 lib/generators/ixtlan/configuration_base.rb
@@ -0,0 +1,37 @@
+require 'generators/ixtlan/base'
+module Ixtlan
+ module Generators
+ class ConfigurationBase < Base
+
+ def create
+ args = []
+ if name
+ args << ARGV.shift
+ else
+ args << "configuration"
+ end
+
+ if defined? ::Ixtlan::Errors
+ args << "errors_keep_dumps:integer"
+ args << "errors_base_url:string"
+ args << "errors_from_email:string"
+ args << "errors_to_emails:string"
+ end
+
+ if defined? ::Ixtlan::Sessions
+ args << "idle_session_timeout:integer"
+ end
+
+ if defined? ::Ixtlan::Audit
+ args << "audits_keep_logs:integer"
+ end
+
+ args += ARGV
+
+ args << "--singleton --timestamps"
+
+ generate generator_name, *args
+ end
+ end
+ end
+end
View
6 lib/generators/ixtlan/configuration_model/configuration_model_generator.rb
@@ -1,8 +1,10 @@
-require 'generators/ixtlan/base'
+require 'generators/ixtlan/configuration_base'
module Ixtlan
module Generators
- class ConfigurationModelGenerator < Base
+ class ConfigurationModelGenerator < ConfigurationBase
+ source_root File.expand_path('../../templates', __FILE__)
+
protected
def generator_name
"model"
View
6 lib/generators/ixtlan/configuration_scaffold/configuration_scaffold_generator.rb
@@ -1,7 +1,9 @@
-require 'generators/ixtlan/base'
+require 'generators/ixtlan/configuration_base'
module Ixtlan
module Generators
- class ConfigurationScaffoldGenerator < Base
+ class ConfigurationScaffoldGenerator < ConfigurationBase
+
+ source_root File.expand_path('../../templates', __FILE__)
protected
def generator_name
View
23 lib/generators/ixtlan/error_dumps_base.rb
@@ -0,0 +1,23 @@
+require 'generators/ixtlan/base'
+module Ixtlan
+ module Generators
+ class ErrorDumpsBase < Base
+
+ def create
+ args = []
+ if name
+ args << ARGV.shift
+ else
+ args << "error"
+ end
+
+ args << 'message:string request:text response:text session:text parameters:text clazz:string backtrace:text'
+ args += ARGV
+
+ args << "--read-only --timestamps"
+
+ generate generator_name, *args
+ end
+ end
+ end
+end
View
14 lib/generators/ixtlan/error_dumps_scaffold/error_dumps_scaffold_generator.rb
@@ -0,0 +1,14 @@
+require 'generators/ixtlan/error_dumps_base'
+module Ixtlan
+ module Generators
+ class ErrorDumpsScaffoldGenerator < ErrorDumpsBase
+
+ source_root File.expand_path('../../templates', __FILE__)
+
+ protected
+ def generator_name
+ "scaffold"
+ end
+ end
+ end
+end
View
14 lib/generators/ixtlan/setup/setup_generator.rb
@@ -5,16 +5,20 @@ class SetupGenerator < Rails::Generators::Base
source_root File.expand_path('../templates', __FILE__)
+ protected
+
+ def application_name
+ @application_name ||= Rails.application.class.to_s.gsub(/::/,'').sub(/Application$/, '')
+ end
+
+ public
+
def create_preinitializer_files
template 'preinitializer.rb', File.join('config', "preinitializer.rb")
template 'gitignore', File.join('config', ".gitignore")
- template 'production.yml.example', File.join('config', "production.yml.example")
+ template 'passwords.yml.example', File.join('config', "passwords.yml.example")
template 'database.yml.example', File.join('config', "database.yml.example")
end
-
- def create_initializer_file
- template 'initializer.rb', File.join('config', "initializers", "ixtlan.rb")
- end
# TODO make only if template-engine is ERB
def error_templates
View
2  lib/generators/ixtlan/setup/templates/application_layout.html.erb
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
- <title><%= app_const_base %></title>
+ <title><%= application_name %></title>
<%%= stylesheet_link_tag :all %>
<%%= javascript_include_tag :defaults %>
<%%= csrf_meta_tag %>
View
2  lib/generators/ixtlan/setup/templates/gitignore
@@ -1,2 +1,2 @@
-production.yml
+passwords.yml
*.example
View
0  ...ors/ixtlan/setup/templates/production.yml.example → ...tors/ixtlan/setup/templates/passwords.yml.example
File renamed without changes
View
2  lib/generators/ixtlan/setup/templates/preinitializer.rb
@@ -28,4 +28,4 @@ def self.load(file)
end
end
-CONFIG = Ixtlan::Configurator.load(File.join(File.dirname(__FILE__), 'production.yml')) || {}
+CONFIG = Ixtlan::Configurator.load(File.join(File.dirname(__FILE__), 'passwords.yml')) || {}
View
37 lib/generators/ixtlan/templates/dynamic.rb
@@ -0,0 +1,37 @@
+# dynamic configuration through a Configuration singleton model
+
+# configuration model
+# -------------------
+# <%= application_name %>::Application.config.configuration_model = :my_configuration # default :configuration
+<% if defined? Ixtlan::Errors -%>
+
+# notification email on errors and dump directory for the system dump
+# the error dumps will be cleanup after the days to keeps dump expired
+# --------------------------------------------------------------------
+<%= application_name %>::Application.config.configuration_manager.register("error_dumper") do |config|
+ <%= application_name %>::Application.config.error_dumper.base_url = config.errors_base_url
+ <%= application_name %>::Application.config.error_dumper.from_email = config.errors_from_email
+ <%= application_name %>::Application.config.error_dumper.to_emails = config.errors_to_emails
+ <%= application_name %>::Application.config.error_dumper.keep_dumps = config.errors_keep_dumps # days
+end
+<% end -%>
+<% if defined? Ixtlan::Sessions -%>
+
+# idle session timeout configuration (in minutes)
+# -----------------------------------------------
+<%= application_name %>::Application.config.configuration_manager.register("session_idle_timeout") do |config|
+ <%= application_name %>::Application.config.idle_session_timeout = config.idle_session_timeout
+end
+<% end -%>
+<% if defined? Ixtlan::Audit -%>
+
+# audit log manager
+# -----------------
+
+# <%= application_name %>::Application.config.audit_manager.model = :my_audit # default: :audit
+# <%= application_name %>::Application.config.audit_manager.username_method = :username # default: :login
+
+<%= application_name %>::Application.config.configuration_manager.register("audit_manager") do |config|
+ <%= application_name %>::Application.config.audit_manager.keep_logs = config.audits_keep_logs # days
+end
+<% end -%>
View
2  lib/generators/rails/scaffold_controller/scaffold_controller/singleton_controller.rb
@@ -15,7 +15,7 @@ def cleanup_params
def stale?
if @<%= singular_table_name %>.nil?
- @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
+ @<%= singular_table_name %> = <%= class_name %>.instance
respond_to do |format|
format.html { render :action => "edit" }
format.xml { render :xml => nil, :status => :conflict }
View
101 output.log
@@ -0,0 +1,101 @@
+[INFO] Error stacktraces are turned on.
+[INFO] Scanning for projects...
+[INFO]
+[INFO] ------------------------------------------------------------------------
+[INFO] Building rails generator templates for ixtlan gems 0.1.3
+[INFO] ------------------------------------------------------------------------
+[INFO]
+[INFO] --- rails3-maven-plugin:0.28.5-SNAPSHOT:new (default-cli) @ ixtlan-generators ---
+[INFO] use ORM activerecord
+[INFO] system is offline: using jruby rails templates from jar file - might be outdated
+ create
+ create README
+ create Rakefile
+ create config.ru
+ create .gitignore
+ create Gemfile
+ create app
+ create app/controllers/application_controller.rb
+ create app/helpers/application_helper.rb
+ create app/mailers
+ create app/models
+ create app/views/layouts/application.html.erb
+ create config
+ create config/routes.rb
+ create config/application.rb
+ create config/environment.rb
+ create config/environments
+ create config/environments/development.rb
+ create config/environments/production.rb
+ create config/environments/test.rb
+ create config/initializers
+ create config/initializers/backtrace_silencers.rb
+ create config/initializers/inflections.rb
+ create config/initializers/mime_types.rb
+ create config/initializers/secret_token.rb
+ create config/initializers/session_store.rb
+ create config/locales
+ create config/locales/en.yml
+ create config/boot.rb
+ create config/database.yml
+ create db
+ create db/seeds.rb
+ create doc
+ create doc/README_FOR_APP
+ create lib
+ create lib/tasks
+ create lib/tasks/.gitkeep
+ create log
+ create log/server.log
+ create log/production.log
+ create log/development.log
+ create log/test.log
+ create public
+ create public/404.html
+ create public/422.html
+ create public/500.html
+ create public/favicon.ico
+ create public/index.html
+ create public/robots.txt
+ create public/images
+ create public/images/rails.png
+ create public/stylesheets
+ create public/stylesheets/.gitkeep
+ create public/javascripts
+ create public/javascripts/application.js
+ create public/javascripts/controls.js
+ create public/javascripts/dragdrop.js
+ create public/javascripts/effects.js
+ create public/javascripts/prototype.js
+ create public/javascripts/rails.js
+ create script
+ create script/rails
+ create test
+ create test/fixtures
+ create test/functional
+ create test/integration
+ create test/performance/browsing_test.rb
+ create test/test_helper.rb
+ create test/unit
+ create tmp
+ create tmp/sessions
+ create tmp/sockets
+ create tmp/cache
+ create tmp/pids
+ create vendor/plugins
+ create vendor/plugins/.gitkeep
+ apply file:/home/kristian/.m2/repository/de/saumya/mojo/ruby-tools/0.28.5-SNAPSHOT/ruby-tools-0.28.5-SNAPSHOT.jar!/rails-templates/templates.rb
+ apply file:/home/kristian/.m2/repository/de/saumya/mojo/ruby-tools/0.28.5-SNAPSHOT/ruby-tools-0.28.5-SNAPSHOT.jar!/rails-templates/activerecord.rb
+ gsub Gemfile
+ apply /home/kristian/projects/active/ixtlan/ixtlan-generators/templates/error-handler.template
+ gemfile ruby-maven (3.0.3.0.28.5)
+ gemfile ixtlan-generators
+ gemfile ixtlan-error-handler
+ gemfile slf4r
+[INFO] ------------------------------------------------------------------------
+[INFO] BUILD SUCCESS
+[INFO] ------------------------------------------------------------------------
+[INFO] Total time: 8.242s
+[INFO] Finished at: Wed Nov 02 22:09:33 IST 2011
+[INFO] Final Memory: 20M/224M
+[INFO] ------------------------------------------------------------------------
View
7 templates/audit.template
@@ -0,0 +1,7 @@
+#-*- mode: ruby -*-
+
+gem 'ruby-maven', '3.0.3.0.28.5'
+gem 'ixtlan-generators', :path => '../..'
+gem 'ixtlan-audit'#, :path => '../../../ixtlan-audit'
+gem 'slf4r'
+# vim: syntax=Ruby
View
7 templates/error-handler.template
@@ -0,0 +1,7 @@
+#-*- mode: ruby -*-
+
+gem 'ruby-maven', '3.0.3.0.28.5'
+gem 'ixtlan-generators', :path => '../..'
+gem 'ixtlan-error-handler'#, :path => '../../../ixtlan-error-handler'
+gem 'slf4r'
+# vim: syntax=Ruby
View
12 templates/files-audit/Rakefile
@@ -0,0 +1,12 @@
+# Add your own tasks in files placed in lib/tasks ending in .rake,
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+
+require File.expand_path('../config/application', __FILE__)
+require 'rake'
+
+Audit::Application.load_tasks
+
+task :audit do
+ puts Audit::Application.config.audit_manager
+end
+
View
12 templates/files-error-handler/Rakefile
@@ -0,0 +1,12 @@
+# Add your own tasks in files placed in lib/tasks ending in .rake,
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+
+require File.expand_path('../config/application', __FILE__)
+require 'rake'
+
+ErrorHandler::Application.load_tasks
+
+task :error_handler do
+ puts ErrorHandler::Application.config.error_dumper
+end
+
Please sign in to comment.
Something went wrong with that request. Please try again.