zuul 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/lib/generators/zuul/orm_helpers.rb +21 -0
  2. data/lib/generators/zuul/permission_generator.rb +57 -0
  3. data/lib/generators/zuul/permission_role_generator.rb +40 -0
  4. data/lib/generators/zuul/permission_subject_generator.rb +40 -0
  5. data/lib/generators/zuul/role_generator.rb +58 -0
  6. data/lib/generators/zuul/role_subject_generator.rb +40 -0
  7. data/lib/generators/zuul/subject_generator.rb +39 -0
  8. data/lib/generators/zuul/templates/permission.rb +18 -0
  9. data/lib/generators/zuul/templates/permission_existing.rb +25 -0
  10. data/lib/generators/zuul/templates/permission_role.rb +17 -0
  11. data/lib/generators/zuul/templates/permission_role_existing.rb +24 -0
  12. data/lib/generators/zuul/templates/permission_subject.rb +17 -0
  13. data/lib/generators/zuul/templates/permission_subject_existing.rb +24 -0
  14. data/lib/generators/zuul/templates/role.rb +20 -0
  15. data/lib/generators/zuul/templates/role_existing.rb +27 -0
  16. data/lib/generators/zuul/templates/role_subject.rb +17 -0
  17. data/lib/generators/zuul/templates/role_subject_existing.rb +24 -0
  18. data/lib/tasks/zuul.rake +56 -0
  19. data/lib/zuul.rb +14 -5
  20. data/lib/zuul/action_controller.rb +108 -0
  21. data/lib/zuul/action_controller/dsl.rb +384 -0
  22. data/lib/zuul/action_controller/evaluators.rb +60 -0
  23. data/lib/zuul/active_record.rb +338 -0
  24. data/lib/zuul/active_record/context.rb +38 -0
  25. data/lib/zuul/active_record/permission.rb +31 -0
  26. data/lib/zuul/active_record/permission_role.rb +29 -0
  27. data/lib/zuul/active_record/permission_subject.rb +29 -0
  28. data/lib/zuul/active_record/role.rb +117 -0
  29. data/lib/zuul/active_record/role_subject.rb +29 -0
  30. data/lib/zuul/active_record/scope.rb +71 -0
  31. data/lib/zuul/active_record/subject.rb +239 -0
  32. data/lib/zuul/configuration.rb +149 -0
  33. data/lib/zuul/context.rb +53 -0
  34. data/lib/zuul/exceptions.rb +3 -0
  35. data/lib/zuul/exceptions/access_denied.rb +9 -0
  36. data/lib/zuul/exceptions/invalid_context.rb +9 -0
  37. data/lib/zuul/exceptions/undefined_scope.rb +9 -0
  38. data/lib/zuul/railtie.rb +5 -0
  39. data/lib/zuul/version.rb +3 -0
  40. data/lib/zuul_viz.rb +195 -0
  41. data/spec/db/schema.rb +172 -0
  42. data/spec/spec_helper.rb +25 -0
  43. data/spec/support/capture_stdout.rb +12 -0
  44. data/spec/support/models.rb +167 -0
  45. data/spec/zuul/active_record/context_spec.rb +55 -0
  46. data/spec/zuul/active_record/permission_role_spec.rb +84 -0
  47. data/spec/zuul/active_record/permission_spec.rb +174 -0
  48. data/spec/zuul/active_record/permission_subject_spec.rb +84 -0
  49. data/spec/zuul/active_record/role_spec.rb +694 -0
  50. data/spec/zuul/active_record/role_subject_spec.rb +84 -0
  51. data/spec/zuul/active_record/scope_spec.rb +75 -0
  52. data/spec/zuul/active_record/subject_spec.rb +1186 -0
  53. data/spec/zuul/active_record_spec.rb +624 -0
  54. data/spec/zuul/configuration_spec.rb +254 -0
  55. data/spec/zuul/context_spec.rb +128 -0
  56. data/spec/zuul_spec.rb +15 -0
  57. metadata +181 -70
  58. data/.document +0 -5
  59. data/.gitignore +0 -23
  60. data/LICENSE +0 -20
  61. data/README.rdoc +0 -65
  62. data/Rakefile +0 -54
  63. data/VERSION +0 -1
  64. data/lib/zuul/restrict_access.rb +0 -104
  65. data/lib/zuul/valid_roles.rb +0 -37
  66. data/spec/rails_root/app/controllers/application_controller.rb +0 -2
  67. data/spec/rails_root/app/models/user.rb +0 -8
  68. data/spec/rails_root/config/boot.rb +0 -110
  69. data/spec/rails_root/config/database.yml +0 -5
  70. data/spec/rails_root/config/environment.rb +0 -7
  71. data/spec/rails_root/config/environments/test.rb +0 -7
  72. data/spec/rails_root/config/initializers/session_store.rb +0 -15
  73. data/spec/rails_root/config/routes.rb +0 -4
  74. data/spec/rails_root/db/test.sqlite3 +0 -0
  75. data/spec/rails_root/log/test.log +0 -5388
  76. data/spec/rails_root/spec/controllers/require_user_spec.rb +0 -138
  77. data/spec/rails_root/spec/controllers/restrict_access_spec.rb +0 -64
  78. data/spec/rails_root/spec/models/user_spec.rb +0 -37
  79. data/spec/rails_root/spec/spec_helper.rb +0 -34
  80. data/zuul.gemspec +0 -78
@@ -0,0 +1,21 @@
1
+ module Zuul
2
+ module Generators
3
+ module OrmHelpers
4
+ def model_exists?
5
+ File.exists?(File.join(destination_root, model_path))
6
+ end
7
+
8
+ def migration_exists?(type, table_name)
9
+ Dir.glob("#{File.join(destination_root, migration_path)}/[0-9]*_*.rb").grep(/\d+_add_zuul_#{type.to_s}_to_#{table_name}.rb$/).first
10
+ end
11
+
12
+ def migration_path
13
+ @migration_path ||= File.join("db", "migrate")
14
+ end
15
+
16
+ def model_path
17
+ @model_path ||= File.join("app", "models", "#{name.underscore}.rb")
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,57 @@
1
+ require 'rails/generators/active_record'
2
+ require 'generators/zuul/orm_helpers'
3
+
4
+ module ActiveRecord
5
+ module Zuul
6
+ module Generators
7
+ class PermissionGenerator < ActiveRecord::Generators::Base
8
+ remove_argument :name, :undefine => true
9
+ argument :name, :type => :string, :default => "Permission"
10
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
11
+ namespace "zuul:permission"
12
+
13
+ include ::Zuul::Generators::OrmHelpers
14
+ source_root File.expand_path("../templates", __FILE__)
15
+
16
+ def copy_zuul_migration
17
+ if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(:permission, table_name))
18
+ migration_template "permission_existing.rb", "db/migrate/add_zuul_permission_to_#{table_name}"
19
+ else
20
+ migration_template "permission.rb", "db/migrate/zuul_permission_create_#{table_name}"
21
+ end
22
+ end
23
+
24
+ def generate_model
25
+ invoke "active_record:model", [name].concat(attributes.map {|attr| "#{attr.name}:#{attr.type}" }), :migration => false unless model_exists? && behavior == :invoke
26
+ end
27
+
28
+ def inject_zuul_content
29
+ content = <<CONTENT
30
+ # Setup authorization for your permission model
31
+ acts_as_authorization_permission
32
+ CONTENT
33
+
34
+ class_path = if namespaced?
35
+ class_name.to_s.split("::")
36
+ else
37
+ [class_name]
38
+ end
39
+
40
+ indent_depth = class_path.size - 1
41
+ content = content.split("\n").map { |line| " " * indent_depth + line } .join("\n") << "\n"
42
+
43
+ inject_into_class(model_path, class_path.last, content) if model_exists?
44
+ end
45
+
46
+ def migration_data
47
+ <<RUBY
48
+ # Authorization permission columns
49
+ t.string :slug
50
+ t.string :context_type
51
+ t.integer :context_id
52
+ RUBY
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,40 @@
1
+ require 'rails/generators/active_record'
2
+ require 'generators/zuul/orm_helpers'
3
+
4
+ module ActiveRecord
5
+ module Zuul
6
+ module Generators
7
+ class PermissionRoleGenerator < ActiveRecord::Generators::Base
8
+ remove_argument :name, :undefine => true
9
+ argument :permission_model, :type => :string, :default => "Permission"
10
+ argument :role_model, :type => :string, :default => "Role"
11
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
12
+ namespace "zuul:permission_role"
13
+
14
+ include ::Zuul::Generators::OrmHelpers
15
+ source_root File.expand_path("../templates", __FILE__)
16
+
17
+ def name
18
+ [permission_model, role_model].sort.map(&:to_s).map(&:camelize).map(&:singularize).join("")
19
+ end
20
+
21
+ def copy_permission_role_migration
22
+ attributes << Rails::Generators::GeneratedAttribute.new("#{permission_model.to_s.underscore.singularize}_id", :integer)
23
+ attributes << Rails::Generators::GeneratedAttribute.new("#{role_model.to_s.underscore.singularize}_id", :integer)
24
+ attributes << Rails::Generators::GeneratedAttribute.new("context_type", :string)
25
+ attributes << Rails::Generators::GeneratedAttribute.new("context_id", :integer)
26
+
27
+ if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(:permission_role, table_name))
28
+ migration_template "permission_role_existing.rb", "db/migrate/add_zuul_permission_role_to_#{table_name}"
29
+ else
30
+ migration_template "permission_role.rb", "db/migrate/zuul_permission_role_create_#{table_name}"
31
+ end
32
+ end
33
+
34
+ def generate_model
35
+ invoke "active_record:model", [name].concat(attributes.map {|attr| "#{attr.name}:#{attr.type}" }), :migration => false unless model_exists? && behavior == :invoke
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,40 @@
1
+ require 'rails/generators/active_record'
2
+ require 'generators/zuul/orm_helpers'
3
+
4
+ module ActiveRecord
5
+ module Zuul
6
+ module Generators
7
+ class PermissionSubjectGenerator < ActiveRecord::Generators::Base
8
+ remove_argument :name, :undefine => true
9
+ argument :permission_model, :type => :string, :default => "Permission"
10
+ argument :subject_model, :type => :string, :default => "User"
11
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
12
+ namespace "zuul:permission_subject"
13
+
14
+ include ::Zuul::Generators::OrmHelpers
15
+ source_root File.expand_path("../templates", __FILE__)
16
+
17
+ def name
18
+ [permission_model, subject_model].sort.map(&:to_s).map(&:camelize).map(&:singularize).join("")
19
+ end
20
+
21
+ def copy_permission_subject_migration
22
+ attributes << Rails::Generators::GeneratedAttribute.new("#{permission_model.to_s.underscore.singularize}_id", :integer)
23
+ attributes << Rails::Generators::GeneratedAttribute.new("#{subject_model.to_s.underscore.singularize}_id", :integer)
24
+ attributes << Rails::Generators::GeneratedAttribute.new("context_type", :string)
25
+ attributes << Rails::Generators::GeneratedAttribute.new("context_id", :integer)
26
+
27
+ if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(:permission_subject, table_name))
28
+ migration_template "permission_subject_existing.rb", "db/migrate/add_zuul_permission_subject_to_#{table_name}"
29
+ else
30
+ migration_template "permission_subject.rb", "db/migrate/zuul_permission_subject_create_#{table_name}"
31
+ end
32
+ end
33
+
34
+ def generate_model
35
+ invoke "active_record:model", [name].concat(attributes.map {|attr| "#{attr.name}:#{attr.type}" }), :migration => false unless model_exists? && behavior == :invoke
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,58 @@
1
+ require 'rails/generators/active_record'
2
+ require 'generators/zuul/orm_helpers'
3
+
4
+ module ActiveRecord
5
+ module Zuul
6
+ module Generators
7
+ class RoleGenerator < ActiveRecord::Generators::Base
8
+ remove_argument :name, :undefine => true
9
+ argument :name, :type => :string, :default => "Role"
10
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
11
+ namespace "zuul:role"
12
+
13
+ include ::Zuul::Generators::OrmHelpers
14
+ source_root File.expand_path("../templates", __FILE__)
15
+
16
+ def copy_role_migration
17
+ if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(:role, table_name))
18
+ migration_template "role_existing.rb", "db/migrate/add_zuul_role_to_#{table_name}"
19
+ else
20
+ migration_template "role.rb", "db/migrate/zuul_role_create_#{table_name}"
21
+ end
22
+ end
23
+
24
+ def generate_model
25
+ invoke "active_record:model", [name].concat(attributes.map {|attr| "#{attr.name}:#{attr.type}" }), :migration => false unless model_exists? && behavior == :invoke
26
+ end
27
+
28
+ def inject_role_content
29
+ content = <<CONTENT
30
+ # Setup authorization for your role model
31
+ acts_as_authorization_role
32
+ CONTENT
33
+
34
+ class_path = if namespaced?
35
+ class_name.to_s.split("::")
36
+ else
37
+ [class_name]
38
+ end
39
+
40
+ indent_depth = class_path.size - 1
41
+ content = content.split("\n").map { |line| " " * indent_depth + line } .join("\n") << "\n"
42
+
43
+ inject_into_class(model_path, class_path.last, content) if model_exists?
44
+ end
45
+
46
+ def migration_data
47
+ <<RUBY
48
+ ## Authorization role columns
49
+ t.string :slug
50
+ t.integer :level
51
+ t.string :context_type
52
+ t.integer :context_id
53
+ RUBY
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,40 @@
1
+ require 'rails/generators/active_record'
2
+ require 'generators/zuul/orm_helpers'
3
+
4
+ module ActiveRecord
5
+ module Zuul
6
+ module Generators
7
+ class RoleSubjectGenerator < ActiveRecord::Generators::Base
8
+ remove_argument :name, :undefine => true
9
+ argument :role_model, :type => :string, :default => "Role"
10
+ argument :subject_model, :type => :string, :default => "User"
11
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
12
+ namespace "zuul:role_subject"
13
+
14
+ include ::Zuul::Generators::OrmHelpers
15
+ source_root File.expand_path("../templates", __FILE__)
16
+
17
+ def name
18
+ [role_model, subject_model].sort.map(&:to_s).map(&:camelize).map(&:singularize).join("")
19
+ end
20
+
21
+ def copy_role_subject_migration
22
+ attributes << Rails::Generators::GeneratedAttribute.new("#{role_model.to_s.underscore.singularize}_id", :integer)
23
+ attributes << Rails::Generators::GeneratedAttribute.new("#{subject_model.to_s.underscore.singularize}_id", :integer)
24
+ attributes << Rails::Generators::GeneratedAttribute.new("context_type", :string)
25
+ attributes << Rails::Generators::GeneratedAttribute.new("context_id", :integer)
26
+
27
+ if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(:role_subject, table_name))
28
+ migration_template "role_subject_existing.rb", "db/migrate/add_zuul_role_subject_to_#{table_name}"
29
+ else
30
+ migration_template "role_subject.rb", "db/migrate/zuul_role_subject_create_#{table_name}"
31
+ end
32
+ end
33
+
34
+ def generate_model
35
+ invoke "active_record:model", [name].concat(attributes.map {|attr| "#{attr.name}:#{attr.type}" }), :migration => false unless model_exists? && behavior == :invoke
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,39 @@
1
+ require 'rails/generators/active_record'
2
+ require 'generators/zuul/orm_helpers'
3
+
4
+ module ActiveRecord
5
+ module Zuul
6
+ module Generators
7
+ class SubjectGenerator < ActiveRecord::Generators::Base
8
+ remove_argument :name, :undefine => true
9
+ argument :name, :type => :string, :default => "User"
10
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
11
+ namespace "zuul:subject"
12
+
13
+ include ::Zuul::Generators::OrmHelpers
14
+
15
+ def generate_model
16
+ invoke "active_record:model", [name].concat(attributes.map {|attr| "#{attr.name}:#{attr.type}" }), :migration => true unless model_exists? && behavior == :invoke
17
+ end
18
+
19
+ def inject_zuul_content
20
+ content = <<CONTENT
21
+ # Setup authorization for your subject model
22
+ acts_as_authorization_subject
23
+ CONTENT
24
+
25
+ class_path = if namespaced?
26
+ class_name.to_s.split("::")
27
+ else
28
+ [class_name]
29
+ end
30
+
31
+ indent_depth = class_path.size - 1
32
+ content = content.split("\n").map { |line| " " * indent_depth + line } .join("\n") << "\n"
33
+
34
+ inject_into_class(model_path, class_path.last, content) if model_exists?
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,18 @@
1
+ class ZuulPermissionCreate<%= table_name.camelize %> < ActiveRecord::Migration
2
+ def change
3
+ create_table(:<%= table_name %>) do |t|
4
+ <%= migration_data -%>
5
+
6
+ <% attributes.each do |attribute| -%>
7
+ t.<%= attribute.type %> :<%= attribute.name %>
8
+ <% end -%>
9
+
10
+ t.timestamps
11
+ end
12
+
13
+ add_index :<%= table_name %>, :slug
14
+ add_index :<%= table_name %>, :context_type
15
+ add_index :<%= table_name %>, :context_id
16
+ add_index :<%= table_name %>, [:slug, :context_type, :context_id], :unique => true
17
+ end
18
+ end
@@ -0,0 +1,25 @@
1
+ class AddZuulPermissionTo<%= table_name.camelize %> < ActiveRecord::Migration
2
+ def self.up
3
+ change_table(:<%= table_name %>) do |t|
4
+ <%= migration_data -%>
5
+
6
+ <% attributes.each do |attribute| -%>
7
+ t.<%= attribute.type %> :<%= attribute.name %>
8
+ <% end -%>
9
+
10
+ # Uncomment below if timestamps were not included in your original model.
11
+ # t.timestamps
12
+ end
13
+
14
+ add_index :<%= table_name %>, :slug
15
+ add_index :<%= table_name %>, :context_type
16
+ add_index :<%= table_name %>, :context_id
17
+ add_index :<%= table_name %>, [:slug, :context_type, :context_id], :unique => true
18
+ end
19
+
20
+ def self.down
21
+ # By default, we don't want to make any assumption about how to roll back a migration when your
22
+ # model already existed. Please edit below which fields you would like to remove in this migration.
23
+ raise ActiveRecord::IrreversibleMigration
24
+ end
25
+ end
@@ -0,0 +1,17 @@
1
+ class ZuulPermissionRoleCreate<%= table_name.camelize %> < ActiveRecord::Migration
2
+ def change
3
+ create_table(:<%= table_name %>) do |t|
4
+ <% attributes.each do |attribute| -%>
5
+ t.<%= attribute.type %> :<%= attribute.name %>
6
+ <% end -%>
7
+
8
+ t.timestamps
9
+ end
10
+
11
+ add_index :<%= table_name %>, :<%= permission_model.to_s.underscore.singularize %>_id
12
+ add_index :<%= table_name %>, :<%= role_model.to_s.underscore.singularize %>_id
13
+ add_index :<%= table_name %>, :context_type
14
+ add_index :<%= table_name %>, :context_id
15
+ add_index :<%= table_name %>, [:<%= permission_model.to_s.underscore.singularize %>_id, :<%= role_model.to_s.underscore.singularize %>_id, :context_type, :context_id], :unique => true, :name => 'index_<%= table_name %>_on_<%= permission_model.to_s.underscore.singularize %>_and_<%= role_model.to_s.underscore.singularize %>_and_context'
16
+ end
17
+ end
@@ -0,0 +1,24 @@
1
+ class AddZuulPermissionRoleTo<%= table_name.camelize %> < ActiveRecord::Migration
2
+ def self.up
3
+ change_table(:<%= table_name %>) do |t|
4
+ <% attributes.each do |attribute| -%>
5
+ t.<%= attribute.type %> :<%= attribute.name %>
6
+ <% end -%>
7
+
8
+ # Uncomment below if timestamps were not included in your original model.
9
+ # t.timestamps
10
+ end
11
+
12
+ add_index :<%= table_name %>, :<%= permission_model.to_s.underscore.singularize %>_id
13
+ add_index :<%= table_name %>, :<%= role_model.to_s.underscore.singularize %>_id
14
+ add_index :<%= table_name %>, :context_type
15
+ add_index :<%= table_name %>, :context_id
16
+ add_index :<%= table_name %>, [:<%= permission_model.to_s.underscore.singularize %>_id, :<%= role_model.to_s.underscore.singularize %>_id, :context_type, :context_id], :unique => true, :name => 'index_<%= table_name %>_on_<%= permission_model.to_s.underscore.singularize %>_and_<%= role_model.to_s.underscore.singularize %>_and_context'
17
+ end
18
+
19
+ def self.down
20
+ # By default, we don't want to make any assumption about how to roll back a migration when your
21
+ # model already existed. Please edit below which fields you would like to remove in this migration.
22
+ raise ActiveRecord::IrreversibleMigration
23
+ end
24
+ end
@@ -0,0 +1,17 @@
1
+ class ZuulPermissionSubjectCreate<%= table_name.camelize %> < ActiveRecord::Migration
2
+ def change
3
+ create_table(:<%= table_name %>) do |t|
4
+ <% attributes.each do |attribute| -%>
5
+ t.<%= attribute.type %> :<%= attribute.name %>
6
+ <% end -%>
7
+
8
+ t.timestamps
9
+ end
10
+
11
+ add_index :<%= table_name %>, :<%= permission_model.to_s.underscore.singularize %>_id
12
+ add_index :<%= table_name %>, :<%= subject_model.to_s.underscore.singularize %>_id
13
+ add_index :<%= table_name %>, :context_type
14
+ add_index :<%= table_name %>, :context_id
15
+ add_index :<%= table_name %>, [:<%= permission_model.to_s.underscore.singularize %>_id, :<%= subject_model.to_s.underscore.singularize %>_id, :context_type, :context_id], :unique => true, :name => 'index_<%= table_name %>_on_<%= permission_model.to_s.underscore.singularize %>_and_<%= subject_model.to_s.underscore.singularize %>_and_context'
16
+ end
17
+ end
@@ -0,0 +1,24 @@
1
+ class AddZuulPermissionSubjectTo<%= table_name.camelize %> < ActiveRecord::Migration
2
+ def self.up
3
+ change_table(:<%= table_name %>) do |t|
4
+ <% attributes.each do |attribute| -%>
5
+ t.<%= attribute.type %> :<%= attribute.name %>
6
+ <% end -%>
7
+
8
+ # Uncomment below if timestamps were not included in your original model.
9
+ # t.timestamps
10
+ end
11
+
12
+ add_index :<%= table_name %>, :<%= permission_model.to_s.underscore.singularize %>_id
13
+ add_index :<%= table_name %>, :<%= subject_model.to_s.underscore.singularize %>_id
14
+ add_index :<%= table_name %>, :context_type
15
+ add_index :<%= table_name %>, :context_id
16
+ add_index :<%= table_name %>, [:<%= permission_model.to_s.underscore.singularize %>_id, :<%= subject_model.to_s.underscore.singularize %>_id, :context_type, :context_id], :unique => true, :name => 'index_<%= table_name %>_on_<%= permission_model.to_s.underscore.singularize %>_and_<%= subject_model.to_s.underscore.singularize %>_and_context'
17
+ end
18
+
19
+ def self.down
20
+ # By default, we don't want to make any assumption about how to roll back a migration when your
21
+ # model already existed. Please edit below which fields you would like to remove in this migration.
22
+ raise ActiveRecord::IrreversibleMigration
23
+ end
24
+ end
@@ -0,0 +1,20 @@
1
+ class ZuulRoleCreate<%= table_name.camelize %> < ActiveRecord::Migration
2
+ def change
3
+ create_table(:<%= table_name %>) do |t|
4
+ <%= migration_data -%>
5
+
6
+ <% attributes.each do |attribute| -%>
7
+ t.<%= attribute.type %> :<%= attribute.name %>
8
+ <% end -%>
9
+
10
+ t.timestamps
11
+ end
12
+
13
+ add_index :<%= table_name %>, :slug
14
+ add_index :<%= table_name %>, :level
15
+ add_index :<%= table_name %>, :context_type
16
+ add_index :<%= table_name %>, :context_id
17
+ add_index :<%= table_name %>, [:slug, :context_type, :context_id], :unique => true
18
+ add_index :<%= table_name %>, [:level, :context_type, :context_id], :unique => true
19
+ end
20
+ end