governor 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +24 -0
  4. data/Gemfile.lock +123 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.markdown +28 -0
  7. data/Rakefile +50 -0
  8. data/VERSION +1 -0
  9. data/app/controllers/governor/articles_controller.rb +94 -0
  10. data/app/helpers/governor_helper.rb +26 -0
  11. data/app/views/governor/articles/_article.html.erb +11 -0
  12. data/app/views/governor/articles/_form.html.erb +28 -0
  13. data/app/views/governor/articles/edit.html.erb +6 -0
  14. data/app/views/governor/articles/index.html.erb +4 -0
  15. data/app/views/governor/articles/new.html.erb +5 -0
  16. data/app/views/governor/articles/show.html.erb +10 -0
  17. data/config/locales/en.yml +6 -0
  18. data/governor.gemspec +198 -0
  19. data/lib/generators/USAGE +8 -0
  20. data/lib/generators/governor/create_articles_generator.rb +40 -0
  21. data/lib/generators/governor/install_generator.rb +9 -0
  22. data/lib/generators/governor/migrate_generator.rb +25 -0
  23. data/lib/generators/governor/templates/governor.rb +22 -0
  24. data/lib/generators/governor/templates/migrations/create_articles.rb +15 -0
  25. data/lib/generators/governor/templates/models/article.rb +3 -0
  26. data/lib/governor.rb +32 -0
  27. data/lib/governor/article.rb +26 -0
  28. data/lib/governor/controllers/helpers.rb +58 -0
  29. data/lib/governor/formatters.rb +43 -0
  30. data/lib/governor/mapping.rb +32 -0
  31. data/lib/governor/plugin.rb +13 -0
  32. data/lib/governor/plugin_manager.rb +20 -0
  33. data/lib/governor/rails.rb +7 -0
  34. data/lib/governor/rails/routes.rb +12 -0
  35. data/lib/tasks/.gitkeep +0 -0
  36. data/script/rails +6 -0
  37. data/spec/controllers/governor/articles_controller_spec.rb +64 -0
  38. data/spec/governor/article_spec.rb +28 -0
  39. data/spec/governor/plugin_manager_spec.rb +11 -0
  40. data/spec/governor_spec.rb +40 -0
  41. data/spec/rails_app/.gitignore +4 -0
  42. data/spec/rails_app/Gemfile +38 -0
  43. data/spec/rails_app/Gemfile.lock +91 -0
  44. data/spec/rails_app/README +256 -0
  45. data/spec/rails_app/Rakefile +7 -0
  46. data/spec/rails_app/app/controllers/application_controller.rb +3 -0
  47. data/spec/rails_app/app/controllers/home_controller.rb +2 -0
  48. data/spec/rails_app/app/helpers/application_helper.rb +2 -0
  49. data/spec/rails_app/app/helpers/home_helper.rb +2 -0
  50. data/spec/rails_app/app/models/article.rb +5 -0
  51. data/spec/rails_app/app/models/user.rb +9 -0
  52. data/spec/rails_app/app/views/home/index.html.erb +0 -0
  53. data/spec/rails_app/app/views/layouts/application.html.erb +14 -0
  54. data/spec/rails_app/config.ru +4 -0
  55. data/spec/rails_app/config/application.rb +42 -0
  56. data/spec/rails_app/config/boot.rb +14 -0
  57. data/spec/rails_app/config/database.yml +19 -0
  58. data/spec/rails_app/config/environment.rb +5 -0
  59. data/spec/rails_app/config/environments/development.rb +26 -0
  60. data/spec/rails_app/config/environments/production.rb +49 -0
  61. data/spec/rails_app/config/environments/test.rb +35 -0
  62. data/spec/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  63. data/spec/rails_app/config/initializers/devise.rb +142 -0
  64. data/spec/rails_app/config/initializers/governor.rb +1 -0
  65. data/spec/rails_app/config/initializers/inflections.rb +10 -0
  66. data/spec/rails_app/config/initializers/mime_types.rb +5 -0
  67. data/spec/rails_app/config/initializers/secret_token.rb +7 -0
  68. data/spec/rails_app/config/initializers/session_store.rb +8 -0
  69. data/spec/rails_app/config/locales/devise.en.yml +39 -0
  70. data/spec/rails_app/config/locales/en.yml +5 -0
  71. data/spec/rails_app/config/routes.rb +64 -0
  72. data/spec/rails_app/db/migrate/20110329032256_devise_create_users.rb +26 -0
  73. data/spec/rails_app/db/migrate/20110330020108_governor_create_articles.rb +15 -0
  74. data/spec/rails_app/db/schema.rb +45 -0
  75. data/spec/rails_app/db/seeds.rb +7 -0
  76. data/spec/rails_app/lib/tasks/.gitkeep +0 -0
  77. data/spec/rails_app/public/404.html +26 -0
  78. data/spec/rails_app/public/422.html +26 -0
  79. data/spec/rails_app/public/500.html +26 -0
  80. data/spec/rails_app/public/favicon.ico +0 -0
  81. data/spec/rails_app/public/images/rails.png +0 -0
  82. data/spec/rails_app/public/javascripts/application.js +2 -0
  83. data/spec/rails_app/public/javascripts/controls.js +965 -0
  84. data/spec/rails_app/public/javascripts/dragdrop.js +974 -0
  85. data/spec/rails_app/public/javascripts/effects.js +1123 -0
  86. data/spec/rails_app/public/javascripts/prototype.js +6001 -0
  87. data/spec/rails_app/public/javascripts/rails.js +191 -0
  88. data/spec/rails_app/public/robots.txt +5 -0
  89. data/spec/rails_app/public/stylesheets/.gitkeep +0 -0
  90. data/spec/rails_app/script/rails +6 -0
  91. data/spec/rails_app/spec/factories.rb +11 -0
  92. data/spec/rails_app/vendor/plugins/.gitkeep +0 -0
  93. data/spec/spec_helper.rb +21 -0
  94. metadata +367 -0
@@ -0,0 +1,10 @@
1
+ <div id="blog">
2
+ <div class="articles">
3
+ <%= render resource %>
4
+ </div>
5
+ <%= render_plugin_partial('after_article_on_article_page', :locals => {:article => resource}) %>
6
+ </div>
7
+ <%= link_to 'Back', resources_url %>
8
+ <% if governor_authorized?(:edit, resource) %>
9
+ | <%= link_to 'Edit', edit_resource_url(resource) %>
10
+ <% end %>
@@ -0,0 +1,6 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: "Hello world"
6
+ unauthorized_edit: "You're not allowed to edit this %{resource_type}."
@@ -0,0 +1,198 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{governor}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Liam Morley"]
12
+ s.date = %q{2011-04-02}
13
+ s.description = %q{Because Blogojevich would be too tough to remember. It's a pluggable blogging system for Rails 3.}
14
+ s.email = %q{liam@carpeliam.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.markdown"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.markdown",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "app/controllers/governor/articles_controller.rb",
29
+ "app/helpers/governor_helper.rb",
30
+ "app/views/governor/articles/_article.html.erb",
31
+ "app/views/governor/articles/_form.html.erb",
32
+ "app/views/governor/articles/edit.html.erb",
33
+ "app/views/governor/articles/index.html.erb",
34
+ "app/views/governor/articles/new.html.erb",
35
+ "app/views/governor/articles/show.html.erb",
36
+ "config/locales/en.yml",
37
+ "governor.gemspec",
38
+ "lib/generators/USAGE",
39
+ "lib/generators/governor/create_articles_generator.rb",
40
+ "lib/generators/governor/install_generator.rb",
41
+ "lib/generators/governor/migrate_generator.rb",
42
+ "lib/generators/governor/templates/governor.rb",
43
+ "lib/generators/governor/templates/migrations/create_articles.rb",
44
+ "lib/generators/governor/templates/models/article.rb",
45
+ "lib/governor.rb",
46
+ "lib/governor/article.rb",
47
+ "lib/governor/controllers/helpers.rb",
48
+ "lib/governor/formatters.rb",
49
+ "lib/governor/mapping.rb",
50
+ "lib/governor/plugin.rb",
51
+ "lib/governor/plugin_manager.rb",
52
+ "lib/governor/rails.rb",
53
+ "lib/governor/rails/routes.rb",
54
+ "lib/tasks/.gitkeep",
55
+ "script/rails",
56
+ "spec/controllers/governor/articles_controller_spec.rb",
57
+ "spec/governor/article_spec.rb",
58
+ "spec/governor/plugin_manager_spec.rb",
59
+ "spec/governor_spec.rb",
60
+ "spec/rails_app/.gitignore",
61
+ "spec/rails_app/Gemfile",
62
+ "spec/rails_app/Gemfile.lock",
63
+ "spec/rails_app/README",
64
+ "spec/rails_app/Rakefile",
65
+ "spec/rails_app/app/controllers/application_controller.rb",
66
+ "spec/rails_app/app/controllers/home_controller.rb",
67
+ "spec/rails_app/app/helpers/application_helper.rb",
68
+ "spec/rails_app/app/helpers/home_helper.rb",
69
+ "spec/rails_app/app/models/article.rb",
70
+ "spec/rails_app/app/models/user.rb",
71
+ "spec/rails_app/app/views/home/index.html.erb",
72
+ "spec/rails_app/app/views/layouts/application.html.erb",
73
+ "spec/rails_app/config.ru",
74
+ "spec/rails_app/config/application.rb",
75
+ "spec/rails_app/config/boot.rb",
76
+ "spec/rails_app/config/database.yml",
77
+ "spec/rails_app/config/environment.rb",
78
+ "spec/rails_app/config/environments/development.rb",
79
+ "spec/rails_app/config/environments/production.rb",
80
+ "spec/rails_app/config/environments/test.rb",
81
+ "spec/rails_app/config/initializers/backtrace_silencers.rb",
82
+ "spec/rails_app/config/initializers/devise.rb",
83
+ "spec/rails_app/config/initializers/governor.rb",
84
+ "spec/rails_app/config/initializers/inflections.rb",
85
+ "spec/rails_app/config/initializers/mime_types.rb",
86
+ "spec/rails_app/config/initializers/secret_token.rb",
87
+ "spec/rails_app/config/initializers/session_store.rb",
88
+ "spec/rails_app/config/locales/devise.en.yml",
89
+ "spec/rails_app/config/locales/en.yml",
90
+ "spec/rails_app/config/routes.rb",
91
+ "spec/rails_app/db/migrate/20110329032256_devise_create_users.rb",
92
+ "spec/rails_app/db/migrate/20110330020108_governor_create_articles.rb",
93
+ "spec/rails_app/db/schema.rb",
94
+ "spec/rails_app/db/seeds.rb",
95
+ "spec/rails_app/lib/tasks/.gitkeep",
96
+ "spec/rails_app/public/404.html",
97
+ "spec/rails_app/public/422.html",
98
+ "spec/rails_app/public/500.html",
99
+ "spec/rails_app/public/favicon.ico",
100
+ "spec/rails_app/public/images/rails.png",
101
+ "spec/rails_app/public/javascripts/application.js",
102
+ "spec/rails_app/public/javascripts/controls.js",
103
+ "spec/rails_app/public/javascripts/dragdrop.js",
104
+ "spec/rails_app/public/javascripts/effects.js",
105
+ "spec/rails_app/public/javascripts/prototype.js",
106
+ "spec/rails_app/public/javascripts/rails.js",
107
+ "spec/rails_app/public/robots.txt",
108
+ "spec/rails_app/public/stylesheets/.gitkeep",
109
+ "spec/rails_app/script/rails",
110
+ "spec/rails_app/spec/factories.rb",
111
+ "spec/rails_app/vendor/plugins/.gitkeep",
112
+ "spec/spec_helper.rb"
113
+ ]
114
+ s.homepage = %q{http://github.com/carpeliam/governor}
115
+ s.licenses = ["MIT"]
116
+ s.require_paths = ["lib"]
117
+ s.rubygems_version = %q{1.3.7}
118
+ s.summary = %q{A pluggable blogging system for Rails 3.}
119
+ s.test_files = [
120
+ "spec/controllers/governor/articles_controller_spec.rb",
121
+ "spec/governor/article_spec.rb",
122
+ "spec/governor/plugin_manager_spec.rb",
123
+ "spec/governor_spec.rb",
124
+ "spec/rails_app/app/controllers/application_controller.rb",
125
+ "spec/rails_app/app/controllers/home_controller.rb",
126
+ "spec/rails_app/app/helpers/application_helper.rb",
127
+ "spec/rails_app/app/helpers/home_helper.rb",
128
+ "spec/rails_app/app/models/article.rb",
129
+ "spec/rails_app/app/models/user.rb",
130
+ "spec/rails_app/config/application.rb",
131
+ "spec/rails_app/config/boot.rb",
132
+ "spec/rails_app/config/environment.rb",
133
+ "spec/rails_app/config/environments/development.rb",
134
+ "spec/rails_app/config/environments/production.rb",
135
+ "spec/rails_app/config/environments/test.rb",
136
+ "spec/rails_app/config/initializers/backtrace_silencers.rb",
137
+ "spec/rails_app/config/initializers/devise.rb",
138
+ "spec/rails_app/config/initializers/governor.rb",
139
+ "spec/rails_app/config/initializers/inflections.rb",
140
+ "spec/rails_app/config/initializers/mime_types.rb",
141
+ "spec/rails_app/config/initializers/secret_token.rb",
142
+ "spec/rails_app/config/initializers/session_store.rb",
143
+ "spec/rails_app/config/routes.rb",
144
+ "spec/rails_app/db/migrate/20110329032256_devise_create_users.rb",
145
+ "spec/rails_app/db/migrate/20110330020108_governor_create_articles.rb",
146
+ "spec/rails_app/db/schema.rb",
147
+ "spec/rails_app/db/seeds.rb",
148
+ "spec/rails_app/spec/factories.rb",
149
+ "spec/spec_helper.rb"
150
+ ]
151
+
152
+ if s.respond_to? :specification_version then
153
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
154
+ s.specification_version = 3
155
+
156
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
157
+ s.add_runtime_dependency(%q<rails>, ["~> 3.0.5"])
158
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
159
+ s.add_development_dependency(%q<sqlite3>, [">= 0"])
160
+ s.add_development_dependency(%q<rspec-rails>, [">= 0"])
161
+ s.add_development_dependency(%q<mocha>, [">= 0"])
162
+ s.add_development_dependency(%q<factory_girl>, ["~> 2.0.0.beta"])
163
+ s.add_development_dependency(%q<factory_girl_rails>, ["~> 1.1.beta"])
164
+ s.add_development_dependency(%q<activerecord-nulldb-adapter>, [">= 0"])
165
+ s.add_development_dependency(%q<will_paginate>, ["~> 3.0.beta"])
166
+ s.add_development_dependency(%q<devise>, [">= 0"])
167
+ s.add_development_dependency(%q<governor>, [">= 0"])
168
+ s.add_development_dependency(%q<dynamic_form>, [">= 0"])
169
+ else
170
+ s.add_dependency(%q<rails>, ["~> 3.0.5"])
171
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
172
+ s.add_dependency(%q<sqlite3>, [">= 0"])
173
+ s.add_dependency(%q<rspec-rails>, [">= 0"])
174
+ s.add_dependency(%q<mocha>, [">= 0"])
175
+ s.add_dependency(%q<factory_girl>, ["~> 2.0.0.beta"])
176
+ s.add_dependency(%q<factory_girl_rails>, ["~> 1.1.beta"])
177
+ s.add_dependency(%q<activerecord-nulldb-adapter>, [">= 0"])
178
+ s.add_dependency(%q<will_paginate>, ["~> 3.0.beta"])
179
+ s.add_dependency(%q<devise>, [">= 0"])
180
+ s.add_dependency(%q<governor>, [">= 0"])
181
+ s.add_dependency(%q<dynamic_form>, [">= 0"])
182
+ end
183
+ else
184
+ s.add_dependency(%q<rails>, ["~> 3.0.5"])
185
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
186
+ s.add_dependency(%q<sqlite3>, [">= 0"])
187
+ s.add_dependency(%q<rspec-rails>, [">= 0"])
188
+ s.add_dependency(%q<mocha>, [">= 0"])
189
+ s.add_dependency(%q<factory_girl>, ["~> 2.0.0.beta"])
190
+ s.add_dependency(%q<factory_girl_rails>, ["~> 1.1.beta"])
191
+ s.add_dependency(%q<activerecord-nulldb-adapter>, [">= 0"])
192
+ s.add_dependency(%q<will_paginate>, ["~> 3.0.beta"])
193
+ s.add_dependency(%q<devise>, [">= 0"])
194
+ s.add_dependency(%q<governor>, [">= 0"])
195
+ s.add_dependency(%q<dynamic_form>, [">= 0"])
196
+ end
197
+ end
198
+
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate install Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,40 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+ module Governor
4
+ class CreateArticlesGenerator < Rails::Generators::Base
5
+ include Rails::Generators::Migration
6
+ source_root File.expand_path('../templates', __FILE__)
7
+ argument :class_name, :type => :string, :default => 'Article'
8
+
9
+ def self.next_migration_number(dirname)
10
+ if ActiveRecord::Base.timestamped_migrations
11
+ Time.new.utc.strftime("%Y%m%d%H%M%S")
12
+ else
13
+ "%.3d" % (current_migration_number(dirname) + 1)
14
+ end
15
+ end
16
+
17
+ def create_model
18
+ template 'models/article.rb', "app/models/#{table_name.singularize}.rb"
19
+ end
20
+
21
+ def create_migration_file
22
+ migration_template 'migrations/create_articles.rb', "db/migrate/governor_create_#{table_name}.rb", :skip => true
23
+ end
24
+
25
+ def add_route
26
+ # route "resources :#{table_name}, :controller => 'governor/articles'"
27
+ route "governate :#{table_name}"
28
+ end
29
+
30
+ private
31
+ def table_name
32
+ @table_name ||= class_name.tableize
33
+ end
34
+
35
+ def model_name
36
+ @model_name ||= class_name.camelize
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,9 @@
1
+ module Governor
2
+ class InstallGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def copy_initializer
6
+ template 'governor.rb', 'config/initializers/governor.rb'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,25 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+ module Governor
4
+ class MigrateGenerator < Rails::Generators::Base
5
+ include Rails::Generators::Migration
6
+ source_root File.expand_path('../templates', __FILE__)
7
+
8
+ def self.next_migration_number(dirname)
9
+ if ActiveRecord::Base.timestamped_migrations
10
+ Time.new.utc.strftime("%Y%m%d%H%M%S")
11
+ else
12
+ "%.3d" % (current_migration_number(dirname) + 1)
13
+ end
14
+ end
15
+
16
+ def create_migration_file
17
+ PluginManager.plugins.each do |plugin|
18
+ plugin.migrations.each do |migration|
19
+ sleep 1 # advance the file name
20
+ migration_template File.expand_path(migration), "db/migrate/#{File.basename(migration)}", :skip => true
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,22 @@
1
+ GOVERNOR_AUTHOR = Proc.new do |actor|
2
+ if actor.respond_to?(:current_user)
3
+ actor.current_user
4
+ else
5
+ raise "Set up GOVERNOR_AUTHOR in #{File.expand_path(__FILE__)}"
6
+ end
7
+ end
8
+
9
+ Governor.authorize_if do |actor, action, article|
10
+ case action.to_sym
11
+ when :new, :create
12
+ # if respond_to?(:user_signed_in?)
13
+ actor.user_signed_in?
14
+ # else
15
+ # raise "Set up Governor.authorize_if in #{File.expand_path(__FILE__)}"
16
+ # end
17
+ when :edit, :update, :destroy
18
+ article.author == GOVERNOR_AUTHOR.call(actor)
19
+ else
20
+ raise ArgumentError.new('action must be new, create, edit, update, or destroy')
21
+ end
22
+ end
@@ -0,0 +1,15 @@
1
+ class GovernorCreate<%= model_name.pluralize %> < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :<%= table_name %> do |t|
4
+ t.string :title, :description
5
+ t.string :format, :default => 'default'
6
+ t.text :post
7
+ t.references :author, :polymorphic => true
8
+ t.timestamps
9
+ end
10
+ end
11
+
12
+ def self.down
13
+ drop_table :<%= table_name %>
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ class <%= model_name %> < ActiveRecord::Base
2
+ include Governor::Article
3
+ end
@@ -0,0 +1,32 @@
1
+ require 'governor/plugin'
2
+ require 'governor/plugin_manager'
3
+ require 'governor/article'
4
+ require 'governor/formatters'
5
+ require 'governor/mapping'
6
+
7
+ require 'governor/controllers/helpers'
8
+
9
+ require 'rails'
10
+ require 'governor/rails'
11
+
12
+
13
+ module Governor
14
+
15
+ mattr_accessor :resources
16
+ @@resources = {}
17
+ def self.map(resource, options = {})
18
+ self.resources[resource] = Governor::Mapping.new(resource, options)
19
+ end
20
+
21
+ def self.setup
22
+ yield self
23
+ end
24
+
25
+ def self.authorize_if(&blk)
26
+ @@authz_rules = blk
27
+ end
28
+
29
+ def self.authorized?(actor, action, article=nil)
30
+ @@authz_rules.call(actor, action, article)
31
+ end
32
+ end
@@ -0,0 +1,26 @@
1
+ module Governor
2
+ module Article
3
+ def self.included(base)
4
+ base.belongs_to :author, :polymorphic => true
5
+
6
+ def base.find_all_by_date(year, month = nil, day = nil, page = 1)
7
+ from, to = self.time_delta(year, month, day)
8
+ conditions = ['created_at BETWEEN ? AND ?', from, to]
9
+ paginate :page => page, :conditions => conditions, :order => 'created_at DESC'
10
+ end
11
+
12
+ private
13
+ def base.time_delta(year, month = nil, day = nil)
14
+ from = Time.mktime(year, month || 1, day || 1)
15
+ to = if day.present?
16
+ from.end_of_day
17
+ elsif month.present?
18
+ from.end_of_month
19
+ else
20
+ from.end_of_year
21
+ end
22
+ [from, to]
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,58 @@
1
+ module Governor
2
+ module Controllers
3
+ module Helpers
4
+ def resources_url
5
+ url_for :controller => mapping.controller, :governor_mapping => params[:governor_mapping], :action => 'index'
6
+ end
7
+
8
+ def edit_resource_url(resource)
9
+ url_for :controller => mapping.controller, :governor_mapping => params[:governor_mapping], :action => 'edit', :id => resource.id
10
+ end
11
+
12
+ def resource
13
+ instance_variable_get("@#{mapping.singular}")
14
+ end
15
+
16
+ def resource_sym
17
+ mapping.singular
18
+ end
19
+
20
+ def resources
21
+ instance_variable_get("@#{mapping.plural}")
22
+ end
23
+
24
+ def model_class
25
+ @model_class ||= mapping.to
26
+ end
27
+
28
+ private
29
+ def set_resources(resources)
30
+ instance_variable_set("@#{mapping.plural}", resources)
31
+ end
32
+
33
+ def set_resource(resource)
34
+ instance_variable_set("@#{mapping.singular}", resource)
35
+ end
36
+
37
+ def mapping
38
+ Governor.resources[params[:governor_mapping]]
39
+ end
40
+
41
+ def init_resource
42
+ set_resource model_class.find(params[:id])
43
+ end
44
+
45
+ def authorize_governor!
46
+ if defined?(resource)
47
+ redirect_to root_path unless governor_authorized?(action_name, resource)
48
+ else
49
+ send("authenticate_#{Devise.default_scope}!") unless governor_authorized?(action_name)
50
+ end
51
+ end
52
+
53
+ def governor_authorized?(action, article=nil)
54
+ Governor.authorized?(self, action, article)
55
+ end
56
+ end
57
+ end
58
+ end