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 CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ./
3
3
  specs:
4
- governor (0.2.0)
4
+ governor (0.2.2)
5
5
  rails (~> 3.0.5)
6
6
 
7
7
  GEM
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
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.1"
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-10}
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",
@@ -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.resources(:child_resources).each_key do |resource|
8
- base.has_many resource
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
@@ -0,0 +1,7 @@
1
+ module Governor
2
+ module Controllers
3
+ module Methods
4
+
5
+ end
6
+ end
7
+ end
@@ -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 a nested resource. Any options are passed directly to the router.
17
- # Any member or collection routes can be passed in as a block.
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.add_child_resource :comments do
23
- # member do
24
- # put 'mark_spam', 'not_spam'
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 add_child_resource(name, options={}, &block)
29
- options[:block] = block if block_given?
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
- # Returns the path associated with the given partial type.
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.resources(:child_resources).each_pair do |child_resource, options|
23
- options = {:module => :governor}.merge options
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
@@ -5,6 +5,7 @@ require 'governor/formatters'
5
5
  require 'governor/mapping'
6
6
 
7
7
  require 'governor/controllers/helpers'
8
+ require 'governor/controllers/methods'
8
9
 
9
10
  require 'governor/rails'
10
11
 
@@ -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.add_child_resource('test', :some_option => 'value')
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 "doesn't alter a plugin's options" do
15
- Rails.application.reload_routes!
16
-
17
- @plugin.resources[:child_resources].should == {'test' => {:some_option => 'value'}}
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) {@plugin = Plugin.new('test')}
6
- it "collects child resources" do
7
- @plugin.add_child_resource('tests', :controller => 'governor/tests')
8
- @plugin.resources.should == {:child_resources => {'tests' => {:controller => 'governor/tests'}}}
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: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 1
10
- version: 0.2.1
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-10 00:00:00 -04:00
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