ixtlan-generators 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +64 -0
- data/features/generators.feature +6 -0
- data/features/step_definitions/simple_steps.rb +1 -0
- data/lib/generators/ixtlan/base.rb~ +44 -0
- data/lib/generators/ixtlan/base_configuration.rb~ +40 -0
- data/lib/generators/ixtlan/configuration_base.rb~ +44 -0
- data/lib/generators/ixtlan/configuration_model/configuration_generator.rb~ +40 -0
- data/lib/generators/ixtlan/configuration_model/configuration_model_generator.rb~ +10 -0
- data/lib/generators/ixtlan/configuration_model/setup_controller.rb~ +5 -0
- data/lib/generators/ixtlan/configuration_model/setup_generator.rb~ +15 -0
- data/lib/generators/ixtlan/configuration_scaffold/configuration_generator.rb~ +40 -0
- data/lib/generators/ixtlan/configuration_scaffold/configuration_model_generator.rb~ +40 -0
- data/lib/generators/ixtlan/configuration_scaffold/configuration_scaffold_generator.rb~ +13 -0
- data/lib/generators/ixtlan/configuration_scaffold/setup_controller.rb~ +5 -0
- data/lib/generators/ixtlan/configuration_scaffold/setup_generator.rb~ +15 -0
- data/lib/generators/ixtlan/setup/setup_controller.rb~ +5 -0
- data/lib/generators/ixtlan/setup/setup_generator.rb~ +25 -0
- data/lib/generators/ixtlan/setup/templates/error.html.erb~ +1 -0
- data/lib/generators/ixtlan/setup/templates/error_with_session.html.erb~ +1 -0
- data/lib/generators/ixtlan/setup/templates/initializer.rb~ +54 -0
- data/lib/generators/model/model_generator.rb~ +12 -0
- data/lib/generators/rails/active_record/active_record_generator.rb +42 -34
- data/lib/generators/rails/active_record/active_record_generator.rb~ +43 -0
- data/lib/generators/rails/active_record/active_record_generatorr.rb~ +51 -0
- data/lib/generators/rails/active_record/model/model.rb +32 -1
- data/lib/generators/rails/active_record/model/model.rb~ +16 -0
- data/lib/generators/rails/erb/erb_generator.rb~ +32 -0
- data/lib/generators/rails/erb/scaffold/_form.html.erb~ +25 -0
- data/lib/generators/rails/erb/scaffold/index.html.erb~ +47 -0
- data/lib/generators/rails/erb_generator.rb~ +32 -0
- data/lib/generators/rails/scaffold_controller/scaffold_controller/controller.rb +47 -35
- data/lib/generators/rails/scaffold_controller/scaffold_controller/controller.rb~ +148 -0
- data/lib/generators/rails/scaffold_controller/scaffold_controller/singleton_controller.rb +43 -7
- data/lib/generators/rails/scaffold_controller/scaffold_controller/singleton_controller.rb~ +60 -0
- data/lib/generators/scaffold/scaffold_generator.rb~ +31 -0
- data/lib/generators/scaffold_controller/scaffold_controller_generator.rb +3 -0
- data/lib/generators/scaffold_controller/scaffold_controller_generator.rb-~ +48 -0
- data/lib/generators/scaffold_controller/scaffold_controller_generator.rb~ +46 -0
- data/lib/ixtlan/railtie.rb~ +81 -0
- data/lib/ixtlan-generators.rb~ +3 -0
- metadata +43 -10
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# Ixtlan #
|
2
|
+
|
3
|
+
this gem adds more security related headers to the response for a rails3 application. mainly inspired by
|
4
|
+
[google-gets-a-1-for-browser-security](http://www.barracudalabs.com/wordpress/index.php/2011/07/21/google-gets-a-1-for-browser-security-3/)
|
5
|
+
and
|
6
|
+
[HttpCaching](http://code.google.com/p/doctype/wiki/ArticleHttpCaching).
|
7
|
+
and
|
8
|
+
[Clickjacking](http://www.owasp.org/index.php/Clickjacking)
|
9
|
+
|
10
|
+
the extra headers are
|
11
|
+
|
12
|
+
* x-frame headers
|
13
|
+
* x-content-type headers
|
14
|
+
* x-xss-protection headers
|
15
|
+
* caching headers
|
16
|
+
|
17
|
+
the main idea is to set the default as strict as possible and the application might relax the setup here and there.
|
18
|
+
|
19
|
+
## rails configuration ##
|
20
|
+
|
21
|
+
in _config/application.rb_ or in one of the _config/environments/*rb_ files or in an initializer. all three x-headers can be configured here, for example
|
22
|
+
|
23
|
+
config.x_content_type_headers = :nosniff
|
24
|
+
|
25
|
+
## controller configuration ##
|
26
|
+
|
27
|
+
just add in your controller something like
|
28
|
+
|
29
|
+
x_xss_protection :block
|
30
|
+
|
31
|
+
## option for each *render*, *send\_file*, *send\_data* methods
|
32
|
+
|
33
|
+
an example for an inline render
|
34
|
+
|
35
|
+
render :inline => 'behappy', :x_frame_headers => :deny
|
36
|
+
|
37
|
+
## possible values ##
|
38
|
+
|
39
|
+
* x\_frame\_headers : `:deny, :sameorigin, :off` default `:deny`
|
40
|
+
|
41
|
+
* x\_content\_type\_headers : `:nosniff, :off` default `:nosniff`
|
42
|
+
|
43
|
+
* x\_xss\_protection\_headers : `:block, :disabled, :off` default `:block`
|
44
|
+
|
45
|
+
## cache headers
|
46
|
+
|
47
|
+
the cache headers needs to have a **current\_user**, i.e. the current\_user method of the controller needs to return a non-nil value. further the the method needs to `:get` and the response status an "ok" status,
|
48
|
+
|
49
|
+
then you can use the controller configuration or the options with *render*, *send\_file* and *send\_data*.
|
50
|
+
|
51
|
+
## possible values ##
|
52
|
+
|
53
|
+
* `:private` : which tells not to cache or store any data except the browser memory: [no caching](http://code.google.com/p/doctype/wiki/ArticleHttpCaching#No_caching)
|
54
|
+
|
55
|
+
* `:protected` : no caching but the browser: [Only the end user's browser is allowed to cache](http://code.google.com/p/doctype/wiki/ArticleHttpCaching#Only_the_end_user%27s_browser_is_allowed_to_cache)
|
56
|
+
|
57
|
+
* `:public` : caching is allowed: [Both browser and proxy allowed to cache](http://code.google.com/p/doctype/wiki/ArticleHttpCaching#Both_browser_and_proxy_allowed_to_cache)
|
58
|
+
|
59
|
+
* `:my_headers` : custom header method like
|
60
|
+
|
61
|
+
> def my_headers
|
62
|
+
no_store = false
|
63
|
+
no_caching(no_store)
|
64
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
Feature: Generators for Ixtlan
|
2
|
+
|
3
|
+
Scenario: Create a rails application and adding 'ixtlan-generators' gem will provide the ixtlan generators
|
4
|
+
Given I create new rails application with template "generators.template"
|
5
|
+
And I execute "rails generate"
|
6
|
+
Then the output should contain "ixtlan:setup" and "ixtlan:configuration_model" and "ixtlan:configuration_scaffold"
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'maven/cucumber_steps'
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'rails/generators/named_base'
|
2
|
+
module Ixtlan
|
3
|
+
module Generators
|
4
|
+
class Base < Rails::Generators::Base
|
5
|
+
|
6
|
+
argument :name, :type => :string, :required => false
|
7
|
+
|
8
|
+
protected
|
9
|
+
def generator_name
|
10
|
+
raise "please overwrite generator_name"
|
11
|
+
end
|
12
|
+
|
13
|
+
public
|
14
|
+
def create
|
15
|
+
args = []
|
16
|
+
if name
|
17
|
+
args << ARGV.shift
|
18
|
+
else
|
19
|
+
args << "configuration"
|
20
|
+
end
|
21
|
+
|
22
|
+
if defined? ::Ixtlan::Errors
|
23
|
+
args << "errors_dir:string"
|
24
|
+
args << "errors_from:string"
|
25
|
+
args << "errors_to:string"
|
26
|
+
end
|
27
|
+
|
28
|
+
if defined? ::Ixtlan::Sessions
|
29
|
+
args << "idle_session_timeout:integer"
|
30
|
+
end
|
31
|
+
|
32
|
+
if defined? ::Ixtlan::Audit
|
33
|
+
args << "audit_keep_log:integer"
|
34
|
+
end
|
35
|
+
|
36
|
+
args << "--singleton"
|
37
|
+
|
38
|
+
args += ARGV[0, 10000] || []
|
39
|
+
|
40
|
+
generate generator_name, *args
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'rails/generators/named_base'
|
2
|
+
module Ixtlan
|
3
|
+
class ConfigurationModelGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
source_root File.expand_path('../../templates', __FILE__)
|
6
|
+
|
7
|
+
argument :name, :type => :string, :required => false
|
8
|
+
|
9
|
+
def create
|
10
|
+
args = []
|
11
|
+
if name
|
12
|
+
args << ARGV.shift
|
13
|
+
else
|
14
|
+
args << "configuration"
|
15
|
+
end
|
16
|
+
|
17
|
+
if defined? Ixtlan::Errors
|
18
|
+
args << "errors_dir:string"
|
19
|
+
args << "errors_from:string"
|
20
|
+
args << "errors_to:string"
|
21
|
+
end
|
22
|
+
|
23
|
+
if defined? Ixtlan::Sessions
|
24
|
+
args << "idle_session_timeout:integer"
|
25
|
+
end
|
26
|
+
|
27
|
+
if defined? Ixtlan::Audit
|
28
|
+
args << "audit_keep_log:integer"
|
29
|
+
end
|
30
|
+
|
31
|
+
args += ARGV[0, 10000] || []
|
32
|
+
|
33
|
+
generate "model", *args
|
34
|
+
|
35
|
+
log "\n"
|
36
|
+
log "please make sure '#{args[0]}' becomes a singleton resource"
|
37
|
+
log "\n"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'rails/generators/named_base'
|
2
|
+
module Ixtlan
|
3
|
+
class ConfigurationBase < Rails::Generators::Base
|
4
|
+
|
5
|
+
argument :name, :type => :string, :required => false
|
6
|
+
|
7
|
+
protected
|
8
|
+
def generator_name
|
9
|
+
raise "please overwrite generator_name"
|
10
|
+
end
|
11
|
+
|
12
|
+
public
|
13
|
+
def create
|
14
|
+
args = []
|
15
|
+
if name
|
16
|
+
args << ARGV.shift
|
17
|
+
else
|
18
|
+
args << "configuration"
|
19
|
+
end
|
20
|
+
|
21
|
+
if defined? ::Ixtlan::Errors
|
22
|
+
args << "errors_dir:string"
|
23
|
+
args << "errors_from:string"
|
24
|
+
args << "errors_to:string"
|
25
|
+
end
|
26
|
+
|
27
|
+
if defined? ::Ixtlan::Sessions
|
28
|
+
args << "idle_session_timeout:integer"
|
29
|
+
end
|
30
|
+
|
31
|
+
if defined? ::Ixtlan::Audit
|
32
|
+
args << "audit_keep_log:integer"
|
33
|
+
end
|
34
|
+
|
35
|
+
args += ARGV[0, 10000] || []
|
36
|
+
|
37
|
+
generate generator_name, *args
|
38
|
+
|
39
|
+
log "\n"
|
40
|
+
log "please make sure '#{args[0]}' becomes a singleton resource"
|
41
|
+
log "\n"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'rails/generators/named_base'
|
2
|
+
module Ixtlan
|
3
|
+
class ConfigurationGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
source_root File.expand_path('../../templates', __FILE__)
|
6
|
+
|
7
|
+
argument :name, :type => :string, :required => false
|
8
|
+
|
9
|
+
def create
|
10
|
+
args = []
|
11
|
+
if name
|
12
|
+
args << ARGV.shift
|
13
|
+
else
|
14
|
+
args << "configuration"
|
15
|
+
end
|
16
|
+
|
17
|
+
if defined? Ixtlan::Errors
|
18
|
+
args << "errors_dir:string"
|
19
|
+
args << "errors_from:string"
|
20
|
+
args << "errors_to:string"
|
21
|
+
end
|
22
|
+
|
23
|
+
if defined? Ixtlan::Sessions
|
24
|
+
args << "idle_session_timeout:integer"
|
25
|
+
end
|
26
|
+
|
27
|
+
if defined? Ixtlan::Audit
|
28
|
+
args << "audit_keep_log:integer"
|
29
|
+
end
|
30
|
+
|
31
|
+
args += ARGV[0, 10000] || []
|
32
|
+
|
33
|
+
generate "scaffold", *args
|
34
|
+
|
35
|
+
log "\n"
|
36
|
+
log "please make sure '#{args[0]}' becomes a singleton resource"
|
37
|
+
log "\n"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rails/generators/named_base'
|
2
|
+
module Ixtlan
|
3
|
+
class SetupGenerator < Rails::Generators::NamedBase
|
4
|
+
|
5
|
+
|
6
|
+
def create_preinitializer_file
|
7
|
+
template 'preinitializer.rb', File.join('config', "preinitializer.rb")
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_initializer_file
|
11
|
+
template 'initializer.rb', File.join('config', "initializers", "ixtlan.rb")
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'rails/generators/named_base'
|
2
|
+
module Ixtlan
|
3
|
+
class ConfigurationGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
source_root File.expand_path('../../templates', __FILE__)
|
6
|
+
|
7
|
+
argument :name, :type => :string, :required => false
|
8
|
+
|
9
|
+
def create
|
10
|
+
args = []
|
11
|
+
if name
|
12
|
+
args << ARGV.shift
|
13
|
+
else
|
14
|
+
args << "configuration"
|
15
|
+
end
|
16
|
+
|
17
|
+
if defined? Ixtlan::Errors
|
18
|
+
args << "errors_dir:string"
|
19
|
+
args << "errors_from:string"
|
20
|
+
args << "errors_to:string"
|
21
|
+
end
|
22
|
+
|
23
|
+
if defined? Ixtlan::Sessions
|
24
|
+
args << "idle_session_timeout:integer"
|
25
|
+
end
|
26
|
+
|
27
|
+
if defined? Ixtlan::Audit
|
28
|
+
args << "audit_keep_log:integer"
|
29
|
+
end
|
30
|
+
|
31
|
+
args += ARGV[0, 10000] || []
|
32
|
+
|
33
|
+
generate "scaffold", *args
|
34
|
+
|
35
|
+
log "\n"
|
36
|
+
log "please make sure '#{args[0]}' becomes a singleton resource"
|
37
|
+
log "\n"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'rails/generators/named_base'
|
2
|
+
module Ixtlan
|
3
|
+
class ConfigurationModelGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
source_root File.expand_path('../../templates', __FILE__)
|
6
|
+
|
7
|
+
argument :name, :type => :string, :required => false
|
8
|
+
|
9
|
+
def create
|
10
|
+
args = []
|
11
|
+
if name
|
12
|
+
args << ARGV.shift
|
13
|
+
else
|
14
|
+
args << "configuration"
|
15
|
+
end
|
16
|
+
|
17
|
+
if defined? Ixtlan::Errors
|
18
|
+
args << "errors_dir:string"
|
19
|
+
args << "errors_from:string"
|
20
|
+
args << "errors_to:string"
|
21
|
+
end
|
22
|
+
|
23
|
+
if defined? Ixtlan::Sessions
|
24
|
+
args << "idle_session_timeout:integer"
|
25
|
+
end
|
26
|
+
|
27
|
+
if defined? Ixtlan::Audit
|
28
|
+
args << "audit_keep_log:integer"
|
29
|
+
end
|
30
|
+
|
31
|
+
args += ARGV[0, 10000] || []
|
32
|
+
|
33
|
+
generate "model", *args
|
34
|
+
|
35
|
+
log "\n"
|
36
|
+
log "please make sure '#{args[0]}' becomes a singleton resource"
|
37
|
+
log "\n"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rails/generators/named_base'
|
2
|
+
module Ixtlan
|
3
|
+
class SetupGenerator < Rails::Generators::NamedBase
|
4
|
+
|
5
|
+
|
6
|
+
def create_preinitializer_file
|
7
|
+
template 'preinitializer.rb', File.join('config', "preinitializer.rb")
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_initializer_file
|
11
|
+
template 'initializer.rb', File.join('config', "initializers", "ixtlan.rb")
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
module Ixtlan
|
3
|
+
module Generators
|
4
|
+
class SetupGenerator < Rails::Generators::Base
|
5
|
+
|
6
|
+
def create_preinitializer_files
|
7
|
+
template 'preinitializer.rb', File.join('config', "preinitializer.rb")
|
8
|
+
template 'gitignore', File.join('config', ".gitignore")
|
9
|
+
template 'production.yml.example', File.join('config', "production.yml.example")
|
10
|
+
template 'database.yml.example', File.join('config', "database.yml.example")
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_initializer_file
|
14
|
+
template 'initializer.rb', File.join('config', "initializers", "ixtlan.rb")
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_application_layout_file
|
18
|
+
if defined? Ixtlan::Sessions
|
19
|
+
layout = File.join('app', 'views', 'layouts', 'application.html.erb')
|
20
|
+
template 'application_layout.html.erb', layout
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<h1><%= @notice %></h1>
|
@@ -0,0 +1 @@
|
|
1
|
+
<h1><%= @notice %></h1>
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# dynamic configuration through a Configuration singleton model
|
2
|
+
|
3
|
+
# configuration model
|
4
|
+
# -------------------
|
5
|
+
# CONFIGURATION = Configuration
|
6
|
+
# config.configuration_model = CONFIGURATION
|
7
|
+
<% if defined? DataMapper -%>
|
8
|
+
# config_instance = CONFIGURATION.get(1) || CONFIGURATION.new
|
9
|
+
<% else -%>
|
10
|
+
# config_instance = CONFIGURATION.find(1) || CONFIGURATION.new
|
11
|
+
<%end -%>
|
12
|
+
|
13
|
+
# notification email on errors and dump directory for the system dump
|
14
|
+
# -------------------------------------------------------------------
|
15
|
+
# config_instance.register("error_dumper") do |config|
|
16
|
+
# Rails.configuration.error_dumper.errors_dir = config.errors_dir
|
17
|
+
# Rails.configuration.error_dumper.notifications = config.errors_from, config.errors_to
|
18
|
+
# end
|
19
|
+
|
20
|
+
# idle session timeout configuration (in minutes)
|
21
|
+
# -----------------------------------------------
|
22
|
+
# config_instance.register("idle_session_timeout") do |config|
|
23
|
+
# Rails.configuration.idle_session_timeout = config.idle_session_timeout
|
24
|
+
# end
|
25
|
+
|
26
|
+
# audit log manager
|
27
|
+
# -----------------
|
28
|
+
|
29
|
+
# config.audit_manager.model = MyAudit # default: Audit
|
30
|
+
# config.audit_manager.username_method = :username # default: :login
|
31
|
+
|
32
|
+
# config_instance.register("audit_manager") do |config|
|
33
|
+
# Rails.configuration.audit_manager.keep_log = config.keep_log # days
|
34
|
+
# end
|
35
|
+
|
36
|
+
# --------------------
|
37
|
+
# static configuration
|
38
|
+
# --------------------
|
39
|
+
|
40
|
+
# error dumper
|
41
|
+
# ------------
|
42
|
+
# notification email on errors and dump directory for the system dump
|
43
|
+
# config.error_dumper.errors_dir = Rails.root + "/errors" # default: logs/errors
|
44
|
+
# config.error_dumper.notifications = "no-reply@example.com", "developer1@example.com,developer2@example.com" # default: none - i.e. no email notifications
|
45
|
+
|
46
|
+
# idle session timeout configuration
|
47
|
+
# ----------------------------------
|
48
|
+
# config.idle_session_timeout = 30 #minutes
|
49
|
+
|
50
|
+
# audit log manager
|
51
|
+
# -----------------
|
52
|
+
# config.audit_manager.model = MyAudit # default: Audit
|
53
|
+
# config.audit_manager.username_method = :username # default: :login
|
54
|
+
# config.audit_manager.keep_log = 30 # days
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module RRails
|
2
|
+
module Generators
|
3
|
+
class ModelGenerator < NamedBase #metagenerator
|
4
|
+
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
5
|
+
hook_for :orm, :required => true
|
6
|
+
|
7
|
+
if defined? Resty
|
8
|
+
hook_for :resty, :type => :boolean, :default => true
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -1,40 +1,48 @@
|
|
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
|
-
|
1
|
+
# just definde the class if it comes from the rails model generator
|
2
|
+
if defined?(Rails::Generators::ModelGenerator) && defined?(ActiveRecord)
|
3
|
+
require 'rails/generators/active_record/model/model_generator'
|
4
|
+
|
5
|
+
module ActiveRecord
|
6
|
+
module Generators
|
7
|
+
class ModelGenerator < Base
|
8
|
+
include ::Ixtlan::Generators::Singleton
|
9
|
+
|
10
|
+
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
11
|
+
|
12
|
+
check_class_collision
|
13
|
+
|
14
|
+
class_option :migration, :type => :boolean
|
15
|
+
class_option :timestamps, :type => :boolean
|
16
|
+
class_option :modified_by, :type => :boolean, :default => false
|
17
|
+
class_option :singleton, :type => :boolean, :default => false
|
18
|
+
class_option :parent, :type => :string, :desc => "The parent class for the generated model"
|
19
|
+
|
20
|
+
def create_migration_file
|
21
|
+
return unless options[:migration] && options[:parent].nil?
|
22
|
+
migration_template "migration.rb", "db/migrate/create_#{table_name}.rb"
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_model_file
|
26
|
+
template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
|
27
|
+
end
|
28
|
+
|
29
|
+
def create_module_file
|
30
|
+
return if class_path.empty?
|
31
|
+
template 'module.rb', File.join('app/models', "#{class_path.join('/')}.rb") if behavior == :invoke
|
32
|
+
end
|
33
|
+
|
34
|
+
hook_for :test_framework
|
35
|
+
|
36
|
+
protected
|
37
|
+
|
34
38
|
def parent_class_name
|
35
39
|
options[:parent] || "ActiveRecord::Base"
|
36
40
|
end
|
37
|
-
|
41
|
+
|
42
|
+
end
|
38
43
|
end
|
39
44
|
end
|
45
|
+
|
46
|
+
else
|
47
|
+
raise LoadError.new "ignore this file #{__FILE__.sub(/.rb$/, '')}"
|
40
48
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
if defined? ActiveRecord && !defined? Rake
|
2
|
+
require 'rails/generators/active_record'
|
3
|
+
|
4
|
+
module ActiveRecord
|
5
|
+
module Generators
|
6
|
+
class ModelGenerator < Base
|
7
|
+
include ::Ixtlan::Generators::Singleton
|
8
|
+
|
9
|
+
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
10
|
+
|
11
|
+
check_class_collision
|
12
|
+
|
13
|
+
class_option :migration, :type => :boolean
|
14
|
+
class_option :timestamps, :type => :boolean
|
15
|
+
class_option :parent, :type => :string, :desc => "The parent class for the generated model"
|
16
|
+
|
17
|
+
def create_migration_file
|
18
|
+
return unless options[:migration] && options[:parent].nil?
|
19
|
+
migration_template "migration.rb", "db/migrate/create_#{table_name}.rb"
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_model_file
|
23
|
+
template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_module_file
|
27
|
+
return if class_path.empty?
|
28
|
+
template 'module.rb', File.join('app/models', "#{class_path.join('/')}.rb") if behavior == :invoke
|
29
|
+
end
|
30
|
+
|
31
|
+
hook_for :test_framework
|
32
|
+
|
33
|
+
protected
|
34
|
+
|
35
|
+
def parent_class_name
|
36
|
+
options[:parent] || "ActiveRecord::Base"
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|