Class: Vigilante::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/vigilante/install/install_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(path) ⇒ Object



85
86
87
88
89
90
91
92
# File 'lib/generators/vigilante/install/install_generator.rb', line 85

def self.next_migration_number(path)
  unless @prev_migration_nr
    @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
  else
    @prev_migration_nr += 1
  end
  @prev_migration_nr.to_s
end

Instance Method Details

#adapt_application_controllerObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/generators/vigilante/install/install_generator.rb', line 15

def adapt_application_controller
#        inject_into_class "app/controllers/application_controller.rb", ApplicationController do <<CODE
  inject_into_file "app/controllers/application_controller.rb", :after => "class ApplicationController < ActionController::Base"  do "\n  protected_by_vigilante\n\n  #----------------------------------\n  # Begin Vigilante glue code\n  #\n  #     note: you can easily rename the functions, the function-names are configured in the\n  #           the @vigilante_config.yml@ configuration file.\n  #\n  #----------------------------------\n\n\n  # retrieves the current context, this is called at the top of the @check_permissions@ function.\n  # This means that inside a nested resource, the nested resources should be retrieved before the\n  # @check_permissions@ is called, e.g. in a @:before_filter@. This is considered good practice anyway.\n  #\n  def current_context\n    # example :\n    # context = @blog || @blogs\n    # context = [context] unless context.nil? || context.is_a?(Array)\n    nil\n  end\n\n\n  # retrieves the id from your chosen context-object. You should rename to something more meaningful\n  # like\n  #\n  #    get_blog_id_from_context_object\n  #\n  # As the extents are stored by id, this is used to check which permissions are valid for you (in this context).\n  #\n  def get_context_id_from_context_object(obj)\n=begin\n    # example\n    logger.debug \"get_asp_id_from_context_object received \\\#{obj.inspect}\"\n    blog_id = if obj.is_a?(Blog)\nobj.id\n    elsif obj.is_a?(Post) || obj.is_a?(Author)\nobj.blog_id\n    else\n0\n    end\n    blog_id.to_s\n=end\n    \"0\"\n  end\n\n  # this is used by the finders, to allow automatic finding of the resources, if needed\n  # You should rename this, for clarity sake, to which parameter you look for (nested resource)\n  # In this case:\n  #    find_blog_by_blog_id\n  #\n  #\n  def find_context_by_context_id\n=begin\n    @blog = Blog.find_by_id(params[:blog_id]) if params[:blog_id].present?\n=end\n  end\n\n  #----------------------------------\n  # End Vigilante glue code\n  #----------------------------------\n\n"
  end
end

#copy_config_fileObject



11
12
13
# File 'lib/generators/vigilante/install/install_generator.rb', line 11

def copy_config_file
  copy_file "vigilante_config.yml", "config/vigilante_config.yml"
end

#copy_migrationsObject



94
95
96
97
98
99
100
# File 'lib/generators/vigilante/install/install_generator.rb', line 94

def copy_migrations
  migration_template "create_permissions.rb",           "db/migrate/create_permissions.rb"
  migration_template "create_abilities.rb",             "db/migrate/create_abilities.rb"
  migration_template "create_ability_permissions.rb",   "db/migrate/create_ability_permissions.rb"
  migration_template "create_authorizations.rb",        "db/migrate/create_authorizations.rb"
  migration_template "create_authorization_extents.rb", "db/migrate/create_authorization_extents.rb"
end