rails3_plugin_toolbox 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -110,9 +110,9 @@ describe "My Plugin rails extensions" do
110
110
  # pull in a macro that makes 'after_init' available!
111
111
  extend Rails3::PluginExtender::Macro
112
112
 
113
- after_init :view do |view|
114
- view.should be_extended_with Helper::View, :panel, :window, :button, :form
115
- view.should_not be_extended_with Helper::View, :unknown
113
+ after_init :view do
114
+ :view.should be_extended_with Helper::View, :panel, :window, :button, :form
115
+ :view.should_not be_extended_with Helper::View, :unknown
116
116
  end
117
117
 
118
118
  Minimal::Application.initialize!
@@ -130,8 +130,8 @@ describe "My other Plugin rails extensions" do
130
130
  end
131
131
  end
132
132
 
133
- after_init :view do |view|
134
- view.should be_extended_with Helper::View, :panel, :window, :button, :form
133
+ after_init :view do
134
+ :view.should be_extended_with Helper::View, :panel, :window, :button, :form
135
135
  end
136
136
 
137
137
  it "should extend Action View" do
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.2
1
+ 0.3.3
@@ -1,10 +1,14 @@
1
1
  module Rails3
2
2
  class PluginExtender
3
3
  module Macro
4
- ACTIVE_MODULES = {:AR => :active_record, :view => :action_view, :controller => :action_controller, :mailer => :action_mailer}
4
+ class << self
5
+ include Rails3::PluginExtender::Util
6
+ end
7
+
8
+ MACRO = Rails3::PluginExtender::Macro
5
9
 
6
10
  def after_init component, &block
7
- type = get_load_type component
11
+ type = MACRO.get_load_type component
8
12
  Rails3::PluginExtender.new do
9
13
  extend_rails type do
10
14
  after :initialize do
@@ -13,16 +17,15 @@ module Rails3
13
17
  end
14
18
  end
15
19
  end # def
16
-
17
- protected
18
20
 
19
- def get_load_type type
20
- return ACTIVE_MODULES[type] if ACTIVE_MODULES[type]
21
- return type if ACTIVE_MODULES.values.include? type
22
- return type if type == :i18n
23
- logger.warn "WARNING: The Rails 3 load handler for the component #{type} is not part of the default load process."
21
+ def init_app_railties app_name, *railties
22
+ app = "#{app_name.to_s.camelize}::Application".constantize
23
+ app.initialize!
24
+ railties.each do |railtie|
25
+ MACRO.get_base_class(railtie).constantize
26
+ end
24
27
  end
25
-
28
+
26
29
  end
27
30
  end
28
31
  end
@@ -4,7 +4,7 @@ module Rails3
4
4
  class BeExtendedWith
5
5
  include Rails3::PluginExtender::Util
6
6
 
7
- attr_reader :methods, :module_const, :rails_const, :submodules, :bad_const, :cause, :rails_const_name
7
+ attr_reader :methods, :module_const, :rails_const, :submodules, :cause, :rails_const_name, :bad_const
8
8
 
9
9
  def initialize(module_const, submodules=nil)
10
10
  @module_const = module_const
@@ -13,11 +13,13 @@ module Rails3
13
13
  end
14
14
 
15
15
  def matches? type
16
- begin
16
+ begin
17
17
  @rails_const_name = get_base_class(type)
18
- @bad_const = module_const
19
- @rails_const = const.constantize
18
+ @bad_const = module_const
19
+ @rails_const = rails_const_name.constantize
20
+
20
21
  return match_submodules? if submodules
22
+
21
23
  methods_included? module_const.instance_methods
22
24
  rescue
23
25
  @cause = ", but the extension module wasn't found"
@@ -29,12 +31,10 @@ module Rails3
29
31
  (rails_const == I18n) ? rails_const.methods : rails_const.instance_methods
30
32
  end
31
33
 
32
- def match_submodules?
34
+ def match_submodules?
33
35
  submodules.each do |name|
34
36
  @bad_const = make_constant(module_const, name)
35
- if !methods_included? get_methods(name)
36
- return false
37
- end
37
+ return false if !methods_included? get_methods(name)
38
38
  end
39
39
  true
40
40
  end
@@ -52,7 +52,7 @@ module Rails3
52
52
  end
53
53
 
54
54
  def negative_failure_message
55
- "Did not expect the rails class #{rails_const_name} to be extended with the methods in #{module_const}"
55
+ "Did not expect the rails class #{rails_const_name} to be extended with the methods in #{bad_const}"
56
56
  end
57
57
  end
58
58
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rails3_plugin_toolbox}
8
- s.version = "0.3.2"
8
+ s.version = "0.3.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kristian Mandrup"]
@@ -21,23 +21,21 @@ module Helper
21
21
  end
22
22
 
23
23
  module Form
24
- def draw_button
25
- 'button'
24
+ def draw_form
25
+ 'form'
26
26
  end
27
27
  end
28
28
  end
29
29
  end
30
30
 
31
-
32
31
  describe Rails3::PluginExtender do
33
32
  describe '#extend_rails' do
34
33
 
35
- before :each do
34
+ before :each do
36
35
  Rails3::PluginExtender.new do
37
- extend_rails :view do
36
+ extend_rails :view do
38
37
  extend_from_module Helper::View, :panel, :window
39
- extend_with Helper::View::Button, Helper::View::Form
40
-
38
+ extend_with Helper::View::Button, Helper::View::Form
41
39
  end
42
40
  end
43
41
  end
@@ -50,13 +48,17 @@ describe Rails3::PluginExtender do
50
48
  it "should extend Action View" do
51
49
  extend Rails3::PluginExtender::Macro
52
50
 
53
- after_init :view do |view|
54
- view.should be_extended_with Helper::View, :panel, :window, :button, :form
55
- view.should_not be_extended_with Helper::View, :unknown
56
- lambda { view.should be_extended_with Helper::View, :unknown }.should raise_error
51
+ after_init :view do
52
+ puts "View initialized!"
53
+
54
+ :view.should be_extended_with Helper::View, :panel, :window, :button, :form
55
+ :view.should_not be_extended_with Helper::View, :unknown
56
+ lambda { :view.should be_extended_with Helper::View, :unknown }.should raise_error
57
+
58
+ # :view.should be_extended_with Helper::View, :unknown
57
59
  end
58
-
59
- Minimal::Application.initialize!
60
+
61
+ init_app_railties :minimal, :view
60
62
  end
61
63
  end
62
64
  end
@@ -5,9 +5,9 @@ require 'rails3_plugin_toolbox'
5
5
  # See http://www.igvita.com/2010/08/04/rails-3-internals-railtie-creating-plugins/
6
6
 
7
7
 
8
- require 'active_record'
9
- require 'action_mailer'
10
- require 'active_support'
8
+ # require 'active_record'
9
+ # require 'action_mailer'
10
+ # require 'active_support'
11
11
  require 'action_controller'
12
12
  require 'action_view'
13
13
  require 'active_support/railtie'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 2
9
- version: 0.3.2
8
+ - 3
9
+ version: 0.3.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Kristian Mandrup