rails3_plugin_toolbox 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -97,7 +97,8 @@ _Usage example:_
97
97
  require 'rspec'
98
98
  require 'rails3_plugin_toolbox'
99
99
  require 'rails/all'
100
-
100
+
101
+ describe "My Plugin rails extensions" do
101
102
  it "should extend Action View with View Helpers" do
102
103
  Rails3::PluginExtender.new do
103
104
  extend_rails :view do
@@ -105,13 +106,37 @@ require 'rails/all'
105
106
  extend_with Helper::View::Button, Helper::View::Form
106
107
  end
107
108
  end
108
-
109
- # Initialize the rails application
109
+
110
+ # pull in a macro that makes 'after_init' available!
111
+ extend Rails3::PluginExtender::Macro
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
116
+ end
117
+
110
118
  Minimal::Application.initialize!
111
-
112
- :view.should be_extended_with Helper::View, :panel, :window, :button, :form
113
- :view.should_not be_extended_with Helper::View, :unknown
114
119
  end
120
+ end
121
+
122
+ # alternative RSpec configuration using macros
123
+
124
+ describe "My other Plugin rails extensions" do
125
+ before :each do
126
+ Rails3::PluginExtender.new do
127
+ extend_rails :view do
128
+ extend_from_module Helper::View, :grid, :tree
129
+ end
130
+ end
131
+ end
132
+
133
+ after_init :view do |view|
134
+ view.should be_extended_with Helper::View, :panel, :window, :button, :form
135
+ end
136
+
137
+ it "should extend Action View" do
138
+ Minimal::Application.initialize!
139
+ end
115
140
  </pre>
116
141
 
117
142
  ## Note on Patches/Pull Requests
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ begin
3
3
  Jeweler::Tasks.new do |gem|
4
4
  gem.name = "rails3_plugin_toolbox"
5
5
  gem.summary = %Q{Toolbox to facilitate Rails 3 plugin development}
6
- gem.description = %Q{Toolbox to facilitate Rails 3 plugin development}
6
+ gem.description = %Q{Provides a more intuitive DSL for Rails 3 plugin configuration and a specialized RSpec 2 matcher. Makes it much easier to develop Rails 3 plugins!}
7
7
  gem.email = "kmandrup@gmail.com"
8
8
  gem.homepage = "http://github.com/kristianmandrup/rails3_plugin_toolbox"
9
9
  gem.authors = ["Kristian Mandrup"]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.3.2
@@ -2,6 +2,7 @@ require 'rspec'
2
2
 
3
3
  RSpec.configure do |config|
4
4
  config.include Rails3::PluginExtender::Matchers
5
+ config.extend Rails3::PluginExtender::Macro
5
6
  end
6
7
 
7
8
 
@@ -0,0 +1,29 @@
1
+ module Rails3
2
+ class PluginExtender
3
+ module Macro
4
+ ACTIVE_MODULES = {:AR => :active_record, :view => :action_view, :controller => :action_controller, :mailer => :action_mailer}
5
+
6
+ def after_init component, &block
7
+ type = get_load_type component
8
+ Rails3::PluginExtender.new do
9
+ extend_rails type do
10
+ after :initialize do
11
+ yield self
12
+ end
13
+ end
14
+ end
15
+ end # def
16
+
17
+ protected
18
+
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."
24
+ end
25
+
26
+ end
27
+ end
28
+ end
29
+
@@ -2,9 +2,9 @@ module Rails3
2
2
  class PluginExtender
3
3
  module Matchers
4
4
  class BeExtendedWith
5
- include Rails3::PluginExtender::Util
5
+ include Rails3::PluginExtender::Util
6
6
 
7
- attr_reader :methods, :module_const, :rails_const, :submodules, :bad_const, :cause
7
+ attr_reader :methods, :module_const, :rails_const, :submodules, :bad_const, :cause, :rails_const_name
8
8
 
9
9
  def initialize(module_const, submodules=nil)
10
10
  @module_const = module_const
@@ -14,9 +14,10 @@ module Rails3
14
14
 
15
15
  def matches? type
16
16
  begin
17
- @rails_const = get_base_class(type)
18
- return match_submodules? if submodules
19
- @bad_const = module_const
17
+ @rails_const_name = get_base_class(type)
18
+ @bad_const = module_const
19
+ @rails_const = const.constantize
20
+ return match_submodules? if submodules
20
21
  methods_included? module_const.instance_methods
21
22
  rescue
22
23
  @cause = ", but the extension module wasn't found"
@@ -47,11 +48,11 @@ module Rails3
47
48
  end
48
49
 
49
50
  def failure_message
50
- "Expected the rails class #{rails_const} to be extended with the methods in #{bad_const}#{cause}"
51
+ "Expected the rails class #{rails_const_name} to be extended with the methods in #{bad_const}#{cause}"
51
52
  end
52
53
 
53
54
  def negative_failure_message
54
- "Did not expect the rails class #{rails_const} 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 #{module_const}"
55
56
  end
56
57
  end
57
58
 
@@ -5,13 +5,8 @@ module Rails3
5
5
  ACTIVE_MODULES = {:AR => :active_record, :view => :action_view, :controller => :action_controller, :mailer => :action_mailer}
6
6
 
7
7
  def get_base_class type
8
- begin
9
- type = get_load_type(type).to_s
10
- const = act_type?(type) ? rails_const_base(type) : "#{type.to_s.camelize}"
11
- const.constantize
12
- rescue
13
- raise ArgumentError, "Can't find rails constant: #{const}"
14
- end
8
+ type = get_load_type(type).to_s
9
+ const = act_type?(type) ? rails_const_base(type) : "#{type.to_s.camelize}"
15
10
  end
16
11
 
17
12
  def act_type? type
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rails3_plugin_toolbox}
8
- s.version = "0.3.1"
8
+ s.version = "0.3.2"
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"]
12
- s.date = %q{2010-08-22}
13
- s.description = %q{Toolbox to facilitate Rails 3 plugin development}
12
+ s.date = %q{2010-08-23}
13
+ s.description = %q{Provides a more intuitive DSL for Rails 3 plugin configuration and a specialized RSpec 2 matcher. Makes it much easier to develop Rails 3 plugins!}
14
14
  s.email = %q{kmandrup@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
28
28
  "lib/plugin_toolbox/extender.rb",
29
29
  "lib/plugin_toolbox/loader.rb",
30
30
  "lib/plugin_toolbox/rspec/config.rb",
31
+ "lib/plugin_toolbox/rspec/macro.rb",
31
32
  "lib/plugin_toolbox/rspec/matchers/be_extended_with.rb",
32
33
  "lib/plugin_toolbox/util.rb",
33
34
  "lib/rails3_plugin_toolbox.rb",
@@ -28,24 +28,35 @@ module Helper
28
28
  end
29
29
  end
30
30
 
31
+
31
32
  describe Rails3::PluginExtender do
32
- describe '#extend_rails' do
33
- it "should extend Action View" do
33
+ describe '#extend_rails' do
34
+
35
+ before :each do
34
36
  Rails3::PluginExtender.new do
35
37
  extend_rails :view do
36
38
  extend_from_module Helper::View, :panel, :window
37
39
  extend_with Helper::View::Button, Helper::View::Form
38
- end
40
+
41
+ end
39
42
  end
43
+ end
44
+
45
+ # after_init :view do |view|
46
+ # view.should be_extended_with Helper::View, :panel, :window, :button, :form
47
+ # end
48
+
40
49
 
41
- # Initialize the rails application
42
- Minimal::Application.initialize!
43
-
44
- :view.should be_extended_with Helper::View, :panel, :window, :button, :form
45
- :view.should_not be_extended_with Helper::View, :unknown
50
+ it "should extend Action View" do
51
+ extend Rails3::PluginExtender::Macro
46
52
 
47
- lambda {:view.should be_extended_with Helper::View, :unknown}.should raise_error
48
- # :view.should be_extended_with Helper::View, :unknown
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
57
+ end
58
+
59
+ Minimal::Application.initialize!
49
60
  end
50
61
  end
51
62
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 1
9
- version: 0.3.1
8
+ - 2
9
+ version: 0.3.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Kristian Mandrup
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-22 00:00:00 +02:00
17
+ date: 2010-08-23 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: 1.1.0
66
66
  type: :runtime
67
67
  version_requirements: *id003
68
- description: Toolbox to facilitate Rails 3 plugin development
68
+ description: Provides a more intuitive DSL for Rails 3 plugin configuration and a specialized RSpec 2 matcher. Makes it much easier to develop Rails 3 plugins!
69
69
  email: kmandrup@gmail.com
70
70
  executables: []
71
71
 
@@ -86,6 +86,7 @@ files:
86
86
  - lib/plugin_toolbox/extender.rb
87
87
  - lib/plugin_toolbox/loader.rb
88
88
  - lib/plugin_toolbox/rspec/config.rb
89
+ - lib/plugin_toolbox/rspec/macro.rb
89
90
  - lib/plugin_toolbox/rspec/matchers/be_extended_with.rb
90
91
  - lib/plugin_toolbox/util.rb
91
92
  - lib/rails3_plugin_toolbox.rb