Permalink
Browse files

* added audit and error-handler features

* fixes for read-only option
  • Loading branch information...
1 parent 52abca2 commit 491f3611754ccb6f57715181b000516beac69ea1 @mkristian committed Nov 3, 2011
@@ -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"
@@ -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"
@@ -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"
@@ -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'
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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"
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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 %>
@@ -1,2 +1,2 @@
-production.yml
+passwords.yml
*.example
@@ -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')) || {}
@@ -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 -%>
@@ -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 }
Oops, something went wrong.

0 comments on commit 491f361

Please sign in to comment.