r3_plugin_toolbox 0.3.5 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +0 -0
- data/.gitignore +0 -0
- data/.rspec +0 -0
- data/LICENSE +0 -0
- data/README.markdown +11 -6
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/config/database.yml +0 -0
- data/lib/r3_plugin_toolbox.rb +1 -1
- data/lib/r3_plugin_toolbox/engine.rb +77 -0
- data/lib/r3_plugin_toolbox/extender.rb +72 -0
- data/lib/r3_plugin_toolbox/extender/load_handler.rb +39 -0
- data/lib/r3_plugin_toolbox/extender/util.rb +64 -0
- data/lib/r3_plugin_toolbox/main.rb +5 -0
- data/lib/r3_plugin_toolbox/railtie.rb +85 -0
- data/lib/r3_plugin_toolbox/rspec/config.rb +14 -0
- data/lib/r3_plugin_toolbox/rspec/macro.rb +33 -0
- data/lib/r3_plugin_toolbox/rspec/matchers/be_extended_with.rb +66 -0
- data/lib/r3_plugin_toolbox/shortcuts.rb +11 -0
- data/log/development.log +0 -0
- data/r3_plugin_toolbox.gemspec +30 -16
- data/spec/fixtures/extension_modules.rb +29 -0
- data/spec/r3_plugin_toolbox/engine_spec.rb +17 -0
- data/spec/{plugin_toolbox → r3_plugin_toolbox/extender}/extend_view_content_spec.rb +5 -2
- data/spec/{plugin_toolbox → r3_plugin_toolbox/extender}/extender_action_spec.rb +4 -4
- data/spec/{plugin_toolbox → r3_plugin_toolbox/extender}/extender_i18n_spec.rb +2 -2
- data/spec/{plugin_toolbox → r3_plugin_toolbox}/extender_spec.rb +3 -3
- data/spec/r3_plugin_toolbox/railtie_spec.rb +16 -0
- data/spec/r3_plugin_toolbox/shortcuts_spec.rb +54 -0
- data/spec/spec_helper.rb +3 -32
- data/wiki/add_rake_tasks.markdown +0 -0
- data/wiki/engine.markdown +0 -0
- data/wiki/how_to_guide.markdown +0 -0
- metadata +49 -21
- data/lib/plugin_toolbox/extender.rb +0 -65
- data/lib/plugin_toolbox/loader.rb +0 -32
- data/lib/plugin_toolbox/rspec/config.rb +0 -12
- data/lib/plugin_toolbox/rspec/macro.rb +0 -32
- data/lib/plugin_toolbox/rspec/matchers/be_extended_with.rb +0 -64
- data/lib/plugin_toolbox/util.rb +0 -62
- data/rails3_plugin_toolbox.gemspec +0 -78
@@ -0,0 +1,33 @@
|
|
1
|
+
module Rails3
|
2
|
+
class Plugin
|
3
|
+
class Extender
|
4
|
+
module Macro
|
5
|
+
class << self
|
6
|
+
include Rails3::Plugin::Extender::Util
|
7
|
+
end
|
8
|
+
|
9
|
+
MACRO = Rails3::Plugin::Extender::Macro
|
10
|
+
|
11
|
+
def after_init component, &block
|
12
|
+
type = MACRO.get_load_type component
|
13
|
+
Rails3::Plugin::Extender.new do
|
14
|
+
extend_rails type do
|
15
|
+
after :initialize do
|
16
|
+
yield self
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end # def
|
21
|
+
|
22
|
+
def init_app_railties app_name, *railties
|
23
|
+
app = "#{app_name.to_s.camelize}::Application".constantize
|
24
|
+
app.initialize!
|
25
|
+
railties.each do |railtie|
|
26
|
+
MACRO.get_base_class(railtie).constantize
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Rails3
|
2
|
+
class Plugin
|
3
|
+
class Extender
|
4
|
+
module Matchers
|
5
|
+
class BeExtendedWith
|
6
|
+
include Rails3::Plugin::Extender::Util
|
7
|
+
|
8
|
+
attr_reader :methods, :module_const, :rails_const, :submodules, :cause, :rails_const_name, :bad_const
|
9
|
+
|
10
|
+
def initialize(module_const, submodules=nil)
|
11
|
+
@module_const = module_const
|
12
|
+
raise ArgumentError, "List of submodules must be given as a collection of Symbols or Strings" if submodules && !submodules.respond_to?(:flatten)
|
13
|
+
@submodules = submodules.flatten if submodules
|
14
|
+
end
|
15
|
+
|
16
|
+
def matches? type
|
17
|
+
begin
|
18
|
+
@rails_const_name = get_base_class(type)
|
19
|
+
@bad_const = module_const
|
20
|
+
@rails_const = rails_const_name.constantize
|
21
|
+
|
22
|
+
return match_submodules? if submodules
|
23
|
+
|
24
|
+
methods_included? module_const.instance_methods
|
25
|
+
rescue
|
26
|
+
@cause = ", but the extension module wasn't found"
|
27
|
+
false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def base_class_methods
|
32
|
+
(rails_const == I18n) ? rails_const.methods : rails_const.instance_methods
|
33
|
+
end
|
34
|
+
|
35
|
+
def match_submodules?
|
36
|
+
submodules.each do |name|
|
37
|
+
@bad_const = make_constant(module_const, name)
|
38
|
+
return false if !methods_included? get_methods(name)
|
39
|
+
end
|
40
|
+
true
|
41
|
+
end
|
42
|
+
|
43
|
+
def methods_included? methods
|
44
|
+
(base_class_methods & methods) == methods
|
45
|
+
end
|
46
|
+
|
47
|
+
def get_methods name
|
48
|
+
get_constant(module_const, name).instance_methods
|
49
|
+
end
|
50
|
+
|
51
|
+
def failure_message
|
52
|
+
"Expected the rails class #{rails_const_name} to be extended with the methods in #{bad_const}#{cause}"
|
53
|
+
end
|
54
|
+
|
55
|
+
def negative_failure_message
|
56
|
+
"Did not expect the rails class #{rails_const_name} to be extended with the methods in #{bad_const}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def be_extended_with(module_const, *submodules)
|
61
|
+
BeExtendedWith.new module_const, submodules
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/log/development.log
CHANGED
File without changes
|
data/r3_plugin_toolbox.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{r3_plugin_toolbox}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.6"
|
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"]
|
@@ -25,20 +25,27 @@ Gem::Specification.new do |s|
|
|
25
25
|
"Rakefile",
|
26
26
|
"VERSION",
|
27
27
|
"config/database.yml",
|
28
|
-
"lib/plugin_toolbox/extender.rb",
|
29
|
-
"lib/plugin_toolbox/loader.rb",
|
30
|
-
"lib/plugin_toolbox/rspec/config.rb",
|
31
|
-
"lib/plugin_toolbox/rspec/macro.rb",
|
32
|
-
"lib/plugin_toolbox/rspec/matchers/be_extended_with.rb",
|
33
|
-
"lib/plugin_toolbox/util.rb",
|
34
28
|
"lib/r3_plugin_toolbox.rb",
|
29
|
+
"lib/r3_plugin_toolbox/engine.rb",
|
30
|
+
"lib/r3_plugin_toolbox/extender.rb",
|
31
|
+
"lib/r3_plugin_toolbox/extender/load_handler.rb",
|
32
|
+
"lib/r3_plugin_toolbox/extender/util.rb",
|
33
|
+
"lib/r3_plugin_toolbox/main.rb",
|
34
|
+
"lib/r3_plugin_toolbox/railtie.rb",
|
35
|
+
"lib/r3_plugin_toolbox/rspec/config.rb",
|
36
|
+
"lib/r3_plugin_toolbox/rspec/macro.rb",
|
37
|
+
"lib/r3_plugin_toolbox/rspec/matchers/be_extended_with.rb",
|
38
|
+
"lib/r3_plugin_toolbox/shortcuts.rb",
|
35
39
|
"log/development.log",
|
36
40
|
"r3_plugin_toolbox.gemspec",
|
37
|
-
"
|
38
|
-
"spec/
|
39
|
-
"spec/
|
40
|
-
"spec/
|
41
|
-
"spec/
|
41
|
+
"spec/fixtures/extension_modules.rb",
|
42
|
+
"spec/r3_plugin_toolbox/engine_spec.rb",
|
43
|
+
"spec/r3_plugin_toolbox/extender/extend_view_content_spec.rb",
|
44
|
+
"spec/r3_plugin_toolbox/extender/extender_action_spec.rb",
|
45
|
+
"spec/r3_plugin_toolbox/extender/extender_i18n_spec.rb",
|
46
|
+
"spec/r3_plugin_toolbox/extender_spec.rb",
|
47
|
+
"spec/r3_plugin_toolbox/railtie_spec.rb",
|
48
|
+
"spec/r3_plugin_toolbox/shortcuts_spec.rb",
|
42
49
|
"spec/spec_helper.rb",
|
43
50
|
"wiki/add_rake_tasks.markdown",
|
44
51
|
"wiki/engine.markdown",
|
@@ -50,10 +57,14 @@ Gem::Specification.new do |s|
|
|
50
57
|
s.rubygems_version = %q{1.3.7}
|
51
58
|
s.summary = %q{Toolbox to facilitate Rails 3 plugin development}
|
52
59
|
s.test_files = [
|
53
|
-
"spec/
|
54
|
-
"spec/
|
55
|
-
"spec/
|
56
|
-
"spec/
|
60
|
+
"spec/fixtures/extension_modules.rb",
|
61
|
+
"spec/r3_plugin_toolbox/engine_spec.rb",
|
62
|
+
"spec/r3_plugin_toolbox/extender/extend_view_content_spec.rb",
|
63
|
+
"spec/r3_plugin_toolbox/extender/extender_action_spec.rb",
|
64
|
+
"spec/r3_plugin_toolbox/extender/extender_i18n_spec.rb",
|
65
|
+
"spec/r3_plugin_toolbox/extender_spec.rb",
|
66
|
+
"spec/r3_plugin_toolbox/railtie_spec.rb",
|
67
|
+
"spec/r3_plugin_toolbox/shortcuts_spec.rb",
|
57
68
|
"spec/spec_helper.rb"
|
58
69
|
]
|
59
70
|
|
@@ -63,15 +74,18 @@ Gem::Specification.new do |s|
|
|
63
74
|
|
64
75
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
65
76
|
s.add_development_dependency(%q<rspec>, ["~> 2.0.0"])
|
77
|
+
s.add_development_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
|
66
78
|
s.add_runtime_dependency(%q<rails>, ["~> 3.0.0"])
|
67
79
|
s.add_runtime_dependency(%q<require_all>, ["~> 1.1.0"])
|
68
80
|
else
|
69
81
|
s.add_dependency(%q<rspec>, ["~> 2.0.0"])
|
82
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
|
70
83
|
s.add_dependency(%q<rails>, ["~> 3.0.0"])
|
71
84
|
s.add_dependency(%q<require_all>, ["~> 1.1.0"])
|
72
85
|
end
|
73
86
|
else
|
74
87
|
s.add_dependency(%q<rspec>, ["~> 2.0.0"])
|
88
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
|
75
89
|
s.add_dependency(%q<rails>, ["~> 3.0.0"])
|
76
90
|
s.add_dependency(%q<require_all>, ["~> 1.1.0"])
|
77
91
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module MyAddition
|
2
|
+
def zzz
|
3
|
+
'zzz'
|
4
|
+
end
|
5
|
+
|
6
|
+
class << self
|
7
|
+
attr_accessor :heard
|
8
|
+
|
9
|
+
def say message
|
10
|
+
@heard = message
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module MyOtherAddition
|
16
|
+
def yyy
|
17
|
+
'yyy'
|
18
|
+
end
|
19
|
+
|
20
|
+
class << self
|
21
|
+
attr_accessor :heard
|
22
|
+
attr_accessor :configured
|
23
|
+
|
24
|
+
def say message
|
25
|
+
@heard = message
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Rails3::Engine do
|
5
|
+
it "should create an engine" do
|
6
|
+
Rails3::Engine.new :my_engine do |e|
|
7
|
+
e.add_locales_dir 'my_locales'
|
8
|
+
e.set_orm :active_record
|
9
|
+
end
|
10
|
+
|
11
|
+
# Initialize the rails application
|
12
|
+
init_app_railties :minimal
|
13
|
+
|
14
|
+
Rails.configuration.generators.options[:rails][:orm].should == :active_record
|
15
|
+
Minimal::Application.config.generators.options[:rails][:orm].should == :active_record
|
16
|
+
end
|
17
|
+
end
|
@@ -1,5 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
require 'active_record'
|
4
|
+
require 'action_mailer'
|
5
|
+
|
3
6
|
module Helper
|
4
7
|
module View
|
5
8
|
module Panel
|
@@ -28,11 +31,11 @@ module Helper
|
|
28
31
|
end
|
29
32
|
end
|
30
33
|
|
31
|
-
describe Rails3::
|
34
|
+
describe Rails3::Plugin::Extender do
|
32
35
|
describe '#extend_rails' do
|
33
36
|
|
34
37
|
before :each do
|
35
|
-
Rails3::
|
38
|
+
Rails3::Plugin::Extender.new do
|
36
39
|
extend_rails :view do
|
37
40
|
extend_from_module Helper::View, :panel, :window
|
38
41
|
extend_with Helper::View::Button, Helper::View::Form
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Rails3::
|
3
|
+
describe Rails3::Plugin::Extender do
|
4
4
|
describe '#extend_rails' do
|
5
5
|
it "should extend Action View" do
|
6
|
-
extender = Rails3::
|
6
|
+
extender = Rails3::Plugin::Extender.new
|
7
7
|
|
8
8
|
extender.extend_rails :view do
|
9
9
|
with MyAddition
|
@@ -22,7 +22,7 @@ describe Rails3::PluginExtender do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should extend Action Controller" do
|
25
|
-
Rails3::
|
25
|
+
Rails3::Plugin::Extender.new do
|
26
26
|
extend_rails :controller do
|
27
27
|
with MyAddition
|
28
28
|
|
@@ -41,7 +41,7 @@ describe Rails3::PluginExtender do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
it "should extend Action Mailer" do
|
44
|
-
Rails3::
|
44
|
+
Rails3::Plugin::Extender.new do
|
45
45
|
extend_rails :mailer do
|
46
46
|
with MyAddition
|
47
47
|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Rails3::
|
3
|
+
describe Rails3::Plugin::Extender do
|
4
4
|
describe '#extend_rails' do
|
5
5
|
it "should extend i18n" do
|
6
|
-
Rails3::
|
6
|
+
Rails3::Plugin::Extender.new do
|
7
7
|
extend_rails :i18n do
|
8
8
|
with MyAddition
|
9
9
|
|
@@ -2,21 +2,21 @@ require 'spec_helper'
|
|
2
2
|
require 'active_record'
|
3
3
|
|
4
4
|
def extend_unknown
|
5
|
-
Rails3::
|
5
|
+
Rails3::Plugin::Extender.new do
|
6
6
|
extend_rails :unknown do
|
7
7
|
with MyAddition
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
describe Rails3::
|
12
|
+
describe Rails3::Plugin::Extender do
|
13
13
|
describe '#extend_rails' do
|
14
14
|
it "should NOT extend Unknown" do
|
15
15
|
lambda { extend_unknown }.should raise_error
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should extend Active Record" do
|
19
|
-
Rails3::
|
19
|
+
Rails3::Plugin::Extender.new do
|
20
20
|
extend_rails :AR do
|
21
21
|
with MyAddition
|
22
22
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rails3::Plugin do
|
4
|
+
it "should create a railtie plugin" do
|
5
|
+
Rails3::Plugin.new :my_plugin do |e|
|
6
|
+
e.set_orm :active_record
|
7
|
+
end
|
8
|
+
|
9
|
+
# Initialize the rails application
|
10
|
+
init_app_railties :minimal
|
11
|
+
|
12
|
+
Rails.configuration.generators.options[:rails][:orm].should == :active_record
|
13
|
+
Minimal::Application.config.generators.options[:rails][:orm].should == :active_record
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'r3_plugin_toolbox/shortcuts'
|
3
|
+
require 'active_record'
|
4
|
+
|
5
|
+
describe 'Plugin shortcuts' do
|
6
|
+
describe '#rails3_extensions' do
|
7
|
+
it "should extend Active Record" do
|
8
|
+
rails3_extensions do
|
9
|
+
extend_rails :AR do
|
10
|
+
with MyAddition
|
11
|
+
|
12
|
+
after :initialize do
|
13
|
+
MyAddition.say 'record me!'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Initialize the rails application
|
19
|
+
init_app_railties :minimal, :active_record
|
20
|
+
|
21
|
+
ActiveRecord::Base.instance_methods.grep(/zzz/).should_not be_empty
|
22
|
+
|
23
|
+
MyAddition.heard.should == 'record me!'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#rails3_plugin' do
|
28
|
+
it "should create a plugin" do
|
29
|
+
rails3_plugin :my_plug do
|
30
|
+
set_orm :active_record
|
31
|
+
end
|
32
|
+
|
33
|
+
# Initialize the rails application
|
34
|
+
init_app_railties :minimal
|
35
|
+
|
36
|
+
Rails.configuration.generators.options[:rails][:orm].should == :active_record
|
37
|
+
Minimal::Application.config.generators.options[:rails][:orm].should == :active_record
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#rails3_engine' do
|
42
|
+
it "should create an engine" do
|
43
|
+
rails3_engine :my_engine do
|
44
|
+
set_orm :active_record
|
45
|
+
end
|
46
|
+
|
47
|
+
# Initialize the rails application
|
48
|
+
init_app_railties :minimal
|
49
|
+
|
50
|
+
Rails.configuration.generators.options[:rails][:orm].should == :active_record
|
51
|
+
Minimal::Application.config.generators.options[:rails][:orm].should == :active_record
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -5,49 +5,20 @@ require 'r3_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
8
|
# require 'active_support'
|
11
9
|
require 'action_controller'
|
12
10
|
require 'action_view'
|
13
11
|
require 'active_support/railtie'
|
14
12
|
# require 'rails/all'
|
15
13
|
|
14
|
+
require 'fixtures/extension_modules'
|
15
|
+
|
16
16
|
module Minimal
|
17
17
|
class Application < Rails::Application
|
18
18
|
config.active_support.deprecation = :log
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
module MyAddition
|
23
|
-
def zzz
|
24
|
-
'zzz'
|
25
|
-
end
|
26
|
-
|
27
|
-
class << self
|
28
|
-
attr_accessor :heard
|
29
|
-
|
30
|
-
def say message
|
31
|
-
@heard = message
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
module MyOtherAddition
|
37
|
-
def yyy
|
38
|
-
'yyy'
|
39
|
-
end
|
40
|
-
|
41
|
-
class << self
|
42
|
-
attr_accessor :heard
|
43
|
-
attr_accessor :configured
|
44
|
-
|
45
|
-
def say message
|
46
|
-
@heard = message
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
|
52
22
|
RSpec.configure do |config|
|
23
|
+
config.mock_with :mocha
|
53
24
|
end
|