governor 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/app/controllers/governor/articles_controller.rb +1 -0
- data/governor.gemspec +3 -2
- data/lib/governor/article.rb +2 -2
- data/lib/governor/controllers/methods.rb +7 -0
- data/lib/governor/plugin.rb +35 -17
- data/lib/governor/plugin_manager.rb +0 -12
- data/lib/governor/rails/routes.rb +2 -6
- data/lib/governor.rb +1 -0
- data/spec/action_dispatch/routing/mapper_spec.rb +12 -6
- data/spec/governor/plugin_manager_spec.rb +0 -9
- data/spec/governor/plugin_spec.rb +15 -4
- metadata +5 -4
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
@@ -1,5 +1,6 @@
|
|
1
1
|
class Governor::ArticlesController < ApplicationController
|
2
2
|
include Governor::Controllers::Helpers
|
3
|
+
include Governor::Controllers::Methods
|
3
4
|
before_filter :init_resource, :only => [:show, :edit, :update, :destroy]
|
4
5
|
before_filter :authorize_governor!, :only => [:new, :edit, :create, :update, :destroy]
|
5
6
|
helper :governor
|
data/governor.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{governor}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Liam Morley"]
|
12
|
-
s.date = %q{2011-04-
|
12
|
+
s.date = %q{2011-04-11}
|
13
13
|
s.description = %q{Because Blogojevich would be too tough to remember. It's a pluggable blogging system for Rails 3.}
|
14
14
|
s.email = %q{liam@carpeliam.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -45,6 +45,7 @@ Gem::Specification.new do |s|
|
|
45
45
|
"lib/governor.rb",
|
46
46
|
"lib/governor/article.rb",
|
47
47
|
"lib/governor/controllers/helpers.rb",
|
48
|
+
"lib/governor/controllers/methods.rb",
|
48
49
|
"lib/governor/formatters.rb",
|
49
50
|
"lib/governor/mapping.rb",
|
50
51
|
"lib/governor/plugin.rb",
|
data/lib/governor/article.rb
CHANGED
@@ -4,8 +4,8 @@ module Governor
|
|
4
4
|
module Article
|
5
5
|
def self.included(base) #:nodoc:
|
6
6
|
base.belongs_to :author, :polymorphic => true
|
7
|
-
Governor::PluginManager.
|
8
|
-
base
|
7
|
+
Governor::PluginManager.plugins.each do |plugin|
|
8
|
+
plugin.include_in_model(base)
|
9
9
|
end
|
10
10
|
|
11
11
|
# Will retrieve all of the articles with a given year, month, or day. If
|
data/lib/governor/plugin.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Governor
|
2
2
|
class Plugin
|
3
|
-
attr_reader :name, :migrations, :resources, :helpers
|
3
|
+
attr_reader :name, :migrations, :routes, :resources, :helpers
|
4
4
|
def initialize(name)
|
5
5
|
@name = name
|
6
6
|
@migrations = []
|
@@ -13,22 +13,22 @@ module Governor
|
|
13
13
|
@migrations << path
|
14
14
|
end
|
15
15
|
|
16
|
-
# Adds
|
17
|
-
#
|
16
|
+
# Adds routes for articles. These can add member or collection routes to
|
17
|
+
# articles, or even nested resources.
|
18
18
|
#
|
19
19
|
# Example:
|
20
20
|
#
|
21
21
|
# comments = Governor::Plugin.new('comments')
|
22
|
-
# comments.
|
23
|
-
#
|
24
|
-
#
|
22
|
+
# comments.set_routes do
|
23
|
+
# resources :comments do
|
24
|
+
# member do
|
25
|
+
# put 'mark_spam', 'not_spam'
|
26
|
+
# end
|
25
27
|
# end
|
26
28
|
# end
|
27
29
|
#
|
28
|
-
def
|
29
|
-
|
30
|
-
@resources[:child_resources] ||= {}
|
31
|
-
@resources[:child_resources][name] = options
|
30
|
+
def set_routes(&block)
|
31
|
+
@routes = block
|
32
32
|
end
|
33
33
|
|
34
34
|
# Specifies that this plugin will display a partial of the given type, at
|
@@ -46,13 +46,7 @@ module Governor
|
|
46
46
|
@partials[type.to_sym] = path
|
47
47
|
end
|
48
48
|
|
49
|
-
|
50
|
-
#
|
51
|
-
# Example:
|
52
|
-
#
|
53
|
-
# comments.partial_for(:after_article_whole) # => 'articles/comments'
|
54
|
-
#
|
55
|
-
def partial_for(type)
|
49
|
+
def partial_for(type) #:nodoc:
|
56
50
|
@partials[type.to_sym]
|
57
51
|
end
|
58
52
|
|
@@ -68,5 +62,29 @@ module Governor
|
|
68
62
|
def add_helper(mod)
|
69
63
|
@helpers << mod
|
70
64
|
end
|
65
|
+
|
66
|
+
def include_in_model(base) #:nodoc:
|
67
|
+
instance_exec(base, &@model_callback) if @model_callback
|
68
|
+
end
|
69
|
+
|
70
|
+
# Evaluates the block in the scope of the model. This is the equivalent of
|
71
|
+
# creating a mixin, including it within your article class and
|
72
|
+
# implementing +self.included+.
|
73
|
+
#
|
74
|
+
# Example:
|
75
|
+
#
|
76
|
+
# thinking_sphinx = Governor::Plugin.new('thinking_sphinx')
|
77
|
+
# thinking_sphinx.register_model_callback do |base|
|
78
|
+
# base.define_index do
|
79
|
+
# indexes title
|
80
|
+
# indexes description
|
81
|
+
# indexes post
|
82
|
+
# has created_at
|
83
|
+
# set_property :delta => true
|
84
|
+
# end
|
85
|
+
# end
|
86
|
+
def register_model_callback(&block)
|
87
|
+
@model_callback = block
|
88
|
+
end
|
71
89
|
end
|
72
90
|
end
|
@@ -18,18 +18,6 @@ module Governor
|
|
18
18
|
def register(*plugins)
|
19
19
|
@@plugins += plugins
|
20
20
|
end
|
21
|
-
|
22
|
-
# A convenience method for obtaining the resources for plugins.
|
23
|
-
#
|
24
|
-
# Example:
|
25
|
-
#
|
26
|
-
# comments = Governor::Plugin.new('comments')
|
27
|
-
# comments.add_child_resource :comments, :path_names => {:create => 'comment'}
|
28
|
-
# Governor::PluginManager.register comments
|
29
|
-
# Governor::PluginManager.resources(:child_resources) # => {:comments => {:create => 'comment'}}
|
30
|
-
def resources(name)
|
31
|
-
@@plugins.map{|p| p.resources[name] }.compact.reduce({}, :merge)
|
32
|
-
end
|
33
21
|
end
|
34
22
|
end
|
35
23
|
end
|
@@ -19,12 +19,8 @@ module ActionDispatch #:nodoc:
|
|
19
19
|
resources.each do |resource|
|
20
20
|
mapping = Governor.map(resource, options)
|
21
21
|
resources mapping.resource, :controller => mapping.controller, :governor_mapping => resource do
|
22
|
-
Governor::PluginManager.
|
23
|
-
|
24
|
-
block = options.delete :block
|
25
|
-
resources(child_resource, options) do
|
26
|
-
instance_eval(&block) if block.present?
|
27
|
-
end
|
22
|
+
Governor::PluginManager.plugins.map{|p| p.routes }.each do |routes|
|
23
|
+
instance_eval(&routes)
|
28
24
|
end
|
29
25
|
end
|
30
26
|
end
|
data/lib/governor.rb
CHANGED
@@ -3,18 +3,24 @@ require 'spec_helper'
|
|
3
3
|
module ActionDispatch::Routing
|
4
4
|
|
5
5
|
describe Mapper do
|
6
|
-
context "#governate" do
|
6
|
+
context "#governate", :type => :routing do
|
7
7
|
|
8
8
|
before do
|
9
9
|
@plugin = Governor::Plugin.new('test')
|
10
|
-
@plugin.
|
10
|
+
@plugin.set_routes do
|
11
|
+
resources :foos
|
12
|
+
end
|
11
13
|
Governor::PluginManager.register @plugin
|
14
|
+
|
15
|
+
@article = Factory(:article)
|
16
|
+
Rails.application.reload_routes!
|
12
17
|
end
|
13
18
|
|
14
|
-
it "
|
15
|
-
Rails.application.
|
16
|
-
|
17
|
-
|
19
|
+
it "adds the route" do
|
20
|
+
Rails.application.routes.routes.map(&:name).should include 'article_foos'
|
21
|
+
# the above works, but the below does not :/
|
22
|
+
pending "check with rspec folks to figure out why this doesn't pass"
|
23
|
+
{:get => "/articles/#{@article.id}/foos"}.should route_to(:controller => 'foos', :action => 'show', :governor_mapping => :articles)
|
18
24
|
end
|
19
25
|
|
20
26
|
after do
|
@@ -12,15 +12,6 @@ module Governor
|
|
12
12
|
PluginManager.plugins.should include plugin
|
13
13
|
end
|
14
14
|
|
15
|
-
it "collects resources for plugins" do
|
16
|
-
plugin1 = Plugin.new('test 1')
|
17
|
-
plugin1.add_child_resource(:moneys)
|
18
|
-
plugin2 = Plugin.new('test 2')
|
19
|
-
plugin2.add_child_resource(:powers, :module => :illinois)
|
20
|
-
PluginManager.register plugin1, plugin2
|
21
|
-
PluginManager.resources(:child_resources).should == {:moneys => {}, :powers => {:module => :illinois}}
|
22
|
-
end
|
23
|
-
|
24
15
|
after do
|
25
16
|
remove_plugins = Governor::PluginManager.plugins - @plugins
|
26
17
|
remove_plugins.each do |plugin|
|
@@ -2,10 +2,21 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module Governor
|
4
4
|
describe Plugin do
|
5
|
-
before(:each)
|
6
|
-
|
7
|
-
@plugin.
|
8
|
-
|
5
|
+
before(:each) do
|
6
|
+
@plugin = Plugin.new('test')
|
7
|
+
@plugin.register_model_callback do |base|
|
8
|
+
def base.test_method
|
9
|
+
true
|
10
|
+
end
|
11
|
+
end
|
12
|
+
PluginManager.register @plugin
|
13
|
+
end
|
14
|
+
it "can add code to the model" do
|
15
|
+
class ArticleStub < ActiveRecord::Base
|
16
|
+
establish_connection 'nulldb'
|
17
|
+
include Article
|
18
|
+
end
|
19
|
+
ArticleStub.should respond_to :test_method
|
9
20
|
end
|
10
21
|
end
|
11
22
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: governor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 2
|
10
|
+
version: 0.2.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Liam Morley
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-04-
|
18
|
+
date: 2011-04-11 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -235,6 +235,7 @@ files:
|
|
235
235
|
- lib/governor.rb
|
236
236
|
- lib/governor/article.rb
|
237
237
|
- lib/governor/controllers/helpers.rb
|
238
|
+
- lib/governor/controllers/methods.rb
|
238
239
|
- lib/governor/formatters.rb
|
239
240
|
- lib/governor/mapping.rb
|
240
241
|
- lib/governor/plugin.rb
|