sweetloader 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "activesupport", ">= 3.0.1"
4
+ gem "i18n"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", ">= 2.5.0"
10
+ gem "bundler", "~> 1.0.10"
11
+ gem "jeweler", ">= 1.6.4"
12
+ gem "rcov", ">= 0"
13
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Kristian Mandrup
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.textile ADDED
@@ -0,0 +1,59 @@
1
+ h1. sweetloader
2
+
3
+ A Sweet autoloader that can autoload your modules and classes more easily, by taking advantage of a standard directory structure approach for the placement of your classes and modules.
4
+
5
+ h2. Install
6
+
7
+ In your Gemfile:
8
+
9
+ <pre>
10
+ gem 'sweetload'
11
+ </pre>
12
+
13
+ Run bundler to install
14
+
15
+ $bundle$
16
+
17
+ h2. Usage
18
+
19
+ Simply use the autoload_modules macro in your Module and Class definitions.
20
+
21
+ <pre>
22
+ CanTango
23
+ autoload_module :Configuration, :Factory, :Permit
24
+ end
25
+ </pre>
26
+
27
+ Each of these modules are then expected to be in @catango/configuration.rb@ and similar relative to a load path.
28
+
29
+ h3. Configuration
30
+
31
+ The following global config vars are available in AutoLoader:
32
+ * root
33
+ * namespaces
34
+
35
+ Set a specific root which the dir will be calculated relative to, using root.
36
+ Override namespace to directory auto-mapping using the namespaces hash.
37
+
38
+ <pre>
39
+ AutoLoader.root = ''
40
+ AutoLoader.namespaces= {:CanTango => 'cantango', :Permithelper => 'permit_helper'}
41
+ </pre>
42
+
43
+ Normally the namespace/constant CanTango will be translated to the dir 'can_tango', here we override this so it will instead be translated to 'cantango'.
44
+
45
+ h2. Contributing to sweetload
46
+
47
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
48
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
49
+ * Fork the project
50
+ * Start a feature/bugfix branch
51
+ * Commit and push until you are happy with your contribution
52
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
53
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
54
+
55
+ h2. Copyright
56
+
57
+ Copyright (c) 2011 Kristian Mandrup. See LICENSE.txt for
58
+ further details.
59
+
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "sweetloader"
18
+ gem.homepage = "http://github.com/kristianmandrup/sweetloader"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{sweetens up autoloading using file structure conventions}
21
+ gem.description = %Q{sweet autoloading using file structure conventions while allowing configuration overrides for special cases}
22
+ gem.email = "kmandrup@gmail.com"
23
+ gem.authors = ["Kristian Mandrup"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rake/rdoctask'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "sweetload #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,133 @@
1
+ require 'active_support/core_ext/string/inflections'
2
+
3
+ class Module
4
+ def include_and_extend(the_module, options={})
5
+ options[:instance_methods] ||= :InstanceMethods
6
+ options[:class_methods] ||= :ClassMethods
7
+ # Mainly include but be flexible
8
+ main_module = const_get(the_module.to_s.to_sym)
9
+ include main_module # for an extend_and_include method, change this to extend main_module
10
+ include main_module.const_get(options[:instance_methods]) if main_module.const_defined?(options[:instance_methods])
11
+ extend main_module.const_get(options[:class_methods]) if main_module.const_defined?(options[:class_methods])
12
+ end
13
+
14
+ def autoload_modules *args
15
+
16
+ options = args.extract_options!
17
+ root = options[:root] || AutoLoader.root || ''
18
+ path = root.strip.empty? ? self.name.to_s.underscore : [root, self.name.to_s.underscore].join('/')
19
+ from = options[:from] || path
20
+
21
+ # Here also could be adding of the file in top of load_paths like: $:.unshift File.dirname(__FILE__)
22
+ # It is very useful for situations of having not load_paths built Rails or Gems way.
23
+ args.each do |req_name|
24
+ ruby_file = req_name.to_s.underscore
25
+
26
+ send :autoload, req_name, AutoLoader.translate("#{from}/#{ruby_file}")
27
+ end
28
+ end
29
+
30
+ end
31
+
32
+ module AutoLoader
33
+ @@root = ''
34
+ @@namespaces = {}
35
+
36
+ def self.root
37
+ @@root
38
+ end
39
+
40
+ def self.namespaces
41
+ @@namespaces
42
+ end
43
+
44
+ def self.root= root
45
+ @@root = root
46
+ end
47
+
48
+ def self.namespaces= namespaces
49
+ @@namespaces = namespaces
50
+ end
51
+
52
+ def self.translate name
53
+ names = name.split('/')
54
+ names.map do |name|
55
+ clazz_name = name.to_s.camelize
56
+ namespaces[clazz_name.to_sym] ? namespaces[clazz_name.to_sym] : name
57
+ end.join('/')
58
+ end
59
+ end
60
+
61
+ module ClassExt
62
+ def get_module name
63
+ # Module.const_get(name)
64
+ name.to_s.camelize.constantize
65
+ rescue
66
+ nil
67
+ end
68
+
69
+ def is_class?(clazz)
70
+ clazz.is_a?(Class) && (clazz.respond_to? :new)
71
+ end
72
+
73
+ def is_module?(clazz)
74
+ clazz.is_a?(Module) && !(clazz.respond_to? :new)
75
+ end
76
+
77
+ def class_exists?(name)
78
+ is_class? get_module(name)
79
+ rescue
80
+ return false
81
+ end
82
+
83
+ def module_exists?(name)
84
+ is_module? get_module(name)
85
+ rescue NameError
86
+ return false
87
+ end
88
+
89
+ def try_class name
90
+ return name if name.kind_of?(Class)
91
+ found = get_module(name) if name.is_a?(String) || name.is_a?(Symbol)
92
+ return found if found.is_a?(Class)
93
+ rescue
94
+ false
95
+ end
96
+
97
+ def try_module name
98
+ return name if name.kind_of?(Module)
99
+ found = get_module(name.to_s) if name.is_a?(String) || name.is_a?(Symbol)
100
+ return found if found.is_a?(Module)
101
+ rescue
102
+ false
103
+ end
104
+
105
+ def try_module_only name
106
+ return name if is_module?(name)
107
+ found = get_module(name) if name.is_a?(String) || name.is_a?(Symbol)
108
+ return found if is_module?(found)
109
+ rescue
110
+ false
111
+ end
112
+
113
+
114
+ def find_first_class *names
115
+ classes = names.flatten.compact.uniq.inject([]) do |res, class_name|
116
+ found_class = try_class(class_name.to_s.camelize)
117
+ res << found_class if found_class
118
+ res
119
+ end
120
+ raise "Not one Class for any of: #{names} is currently loaded" if classes.empty?
121
+ classes.first
122
+ end
123
+
124
+ def find_first_module *names
125
+ modules = names.flatten.compact.uniq.inject([]) do |res, class_name|
126
+ found_class = try_module(class_name.to_s.camelize)
127
+ res << found_class if found_class
128
+ res
129
+ end
130
+ raise "Not one Module for any of: #{names} is currently loaded" if modules.empty?
131
+ modules.first
132
+ end
133
+ end
@@ -0,0 +1,3 @@
1
+ module AutoLoadBlankRoot
2
+ autoload_modules :HelloSailor
3
+ end
@@ -0,0 +1,6 @@
1
+ module AutoloadBlankRoot
2
+ module Hello
3
+ def self.test
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ module AutoLoadBlankRoot
2
+ module HelloSailor
3
+ def self.test
4
+ "test"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module AutoloadBlankRoot
2
+ autoload_modules :Hello
3
+ end
@@ -0,0 +1,189 @@
1
+ require 'spec_helper'
2
+ require 'sugar-high/class_ext'
3
+
4
+ class Trial
5
+ include ClassExt
6
+ end
7
+
8
+ class Hello
9
+ end
10
+
11
+ module GoodBye
12
+ module Alpha
13
+ module Beta
14
+ end
15
+ end
16
+ end
17
+
18
+ module First
19
+ module ClassMethods
20
+ def class_method
21
+ end
22
+ end
23
+
24
+ module InstanceMethods
25
+ def instance_method
26
+ end
27
+ end
28
+ end
29
+
30
+ module Second
31
+ include_and_extend First
32
+ end
33
+
34
+ class Third
35
+ include_and_extend Second
36
+ end
37
+
38
+ def trial
39
+ @trial ||= Trial.new
40
+ end
41
+
42
+ describe Module do
43
+
44
+ describe "#include_and_extend" do
45
+ it "should include class methods directly" do
46
+ Second.should respond_to(:class_method)
47
+ end
48
+
49
+
50
+ it "should not include class methods indirectly" do
51
+ Third.should_not respond_to(:class_method)
52
+ end
53
+
54
+ it "should include class methods" do
55
+ Third.new.should respond_to(:instance_method)
56
+ end
57
+ end
58
+
59
+ describe "#autoload_modules" do
60
+ it "should autoload modules using :from => path" do
61
+ require 'fixtures/autoload_modules'
62
+ AutoloadModules::Third.should respond_to(:test)
63
+ end
64
+
65
+ it "should autoload modules from __FILE__'s dir if :from is omitted'" do
66
+ require 'fixtures/autoload_modulez'
67
+ AutoloadModulez::ThirdOneHere.should respond_to(:test)
68
+ end
69
+
70
+ context 'using AutoLoader.root' do
71
+ it 'empty root' do
72
+ AutoLoader.root = ''
73
+ require 'autoload_blank_root'
74
+ AutoloadBlankRoot::Hello.should respond_to(:test)
75
+ end
76
+
77
+ it 'should autoload modules using ClassExt#autoload_root' do
78
+ AutoLoader.root = 'fixtures'
79
+ require 'fixtures/autoload_modules_root'
80
+ AutoloadModulesRoot::Third.should respond_to(:test)
81
+ end
82
+ end
83
+
84
+ context 'using AutoLoader.namespaces' do
85
+ it 'empty root' do
86
+ AutoLoader.root = ''
87
+ AutoLoader.namespaces= {:AutoLoadBlankRoot => 'autoload_blank_root', :HelloSailor => 'sailor'}
88
+ require 'auto_load_blank_root'
89
+ AutoLoadBlankRoot::HelloSailor.should respond_to(:test)
90
+ end
91
+ end
92
+ end
93
+ end
94
+
95
+ describe ClassExt do
96
+ describe '#try_module' do
97
+ it "should return false if no module found" do
98
+ trial.try_module('Blip').should be_false
99
+ trial.try_module(:Blip).should be_false
100
+ trial.try_module(nil).should be_false
101
+ end
102
+
103
+ it "should return module if found" do
104
+ trial.try_module('GoodBye').should be_a(Module)
105
+ trial.try_module(:GoodBye).should be_a(Module)
106
+ end
107
+
108
+ it "should return namespaced module if found" do
109
+ trial.try_module('GoodBye::Alpha::Beta').should be_a(Module)
110
+ end
111
+
112
+ it "should return false if only class of that name is found" do
113
+ trial.try_module('Hello').should be_true
114
+ end
115
+ end
116
+
117
+ describe '#try_class' do
118
+ it "should return false if no class found" do
119
+ trial.try_class('Blip').should be_false
120
+ trial.try_class(:Blip).should be_false
121
+ trial.try_class(nil).should be_false
122
+ end
123
+
124
+ it "should return class if found" do
125
+ trial.try_class('Hello').should be_a(Class)
126
+ trial.try_class(:Hello).should be_a(Class)
127
+ end
128
+
129
+ it "should return false if only class of that name is found" do
130
+ trial.try_class('GoodBye').should be_false
131
+ end
132
+ end
133
+
134
+ describe '#class_exists?' do
135
+ it "should return false if no class found" do
136
+ trial.class_exists?('Blip').should be_false
137
+ end
138
+
139
+ it "should return true if class found" do
140
+ trial.class_exists?('Hello').should be_true
141
+ end
142
+
143
+ it "should return false if module found" do
144
+ trial.class_exists?('GoodBye').should be_false
145
+ end
146
+ end
147
+
148
+ describe '#module_exists?' do
149
+ it "should return false if no module found" do
150
+ trial.module_exists?('Blip').should be_false
151
+ end
152
+
153
+ it "should return true if module found" do
154
+ trial.module_exists?('GoodBye').should be_true
155
+ end
156
+
157
+ it "should return false if only class found" do
158
+ trial.module_exists?('Hello').should be_false
159
+ end
160
+ end
161
+
162
+ describe '#try_module_only' do
163
+ it 'should find module' do
164
+ trial.try_module_only('Hello').should be_false
165
+ trial.try_module_only('GoodBye').should be_true
166
+ end
167
+ end
168
+
169
+ describe '#find_first_class' do
170
+ it 'should find first class' do
171
+ trial.find_first_class('GoodBye', 'Hello').should == Hello
172
+ end
173
+
174
+ it 'should not find any module' do
175
+ lambda {trial.find_first_class('Good', 'Bye') }.should raise_error
176
+ end
177
+ end
178
+
179
+ describe '#find_first_module' do
180
+ it 'should find first module' do
181
+ first_module = trial.find_first_module('GoodBye::Alpha::Beta', 'Hello')
182
+ first_module.should == GoodBye::Alpha::Beta
183
+ end
184
+
185
+ it 'should not find any module' do
186
+ lambda {trial.find_first_module('Good', 'Bye') }.should raise_error
187
+ end
188
+ end
189
+ end
@@ -0,0 +1,7 @@
1
+ module AutoloadModules
2
+ module First
3
+ def test
4
+ puts "here is the test"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module AutoloadModules
2
+ class Second
3
+ extend AutoloadModules::First
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ module AutoloadModules
2
+ class Third < AutoloadModules::Second
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module AutoloadModules
2
+ autoload_modules :First, :Second, :Third, :from => 'fixtures/autoload_modules/subdir'
3
+ end
@@ -0,0 +1,7 @@
1
+ module AutoloadModulesRoot
2
+ module First
3
+ def test
4
+ puts "here is the test"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ module AutoloadModulesRoot
2
+ class Second
3
+ end
4
+ end
@@ -0,0 +1,7 @@
1
+ module AutoloadModulesRoot
2
+ class Third
3
+ def self.test
4
+ puts "here is the test"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module AutoloadModulesRoot
2
+ autoload_modules :First, :Second, :Third
3
+ end
@@ -0,0 +1,7 @@
1
+ module AutoloadModulez
2
+ module First
3
+ def test
4
+ puts "here is the test"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module AutoloadModulez
2
+ class Second
3
+ extend AutoloadModulez::First
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ module AutoloadModulez
2
+ class ThirdOneHere < AutoloadModulez::Second
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module AutoloadModulez
2
+ autoload_modules :First, :Second, :ThirdOneHere, :root => 'fixtures'
3
+ end
4
+
@@ -0,0 +1,6 @@
1
+ require 'rspec'
2
+ require 'sweetloader'
3
+
4
+ RSpec.configure do |config|
5
+
6
+ end
@@ -0,0 +1,189 @@
1
+ require 'spec_helper'
2
+
3
+ class Trial
4
+ include ClassExt
5
+ end
6
+
7
+ class Hello
8
+ end
9
+
10
+ module GoodBye
11
+ module Alpha
12
+ module Beta
13
+ end
14
+ end
15
+ end
16
+
17
+ module First
18
+ module ClassMethods
19
+ def class_method
20
+ end
21
+ end
22
+
23
+ module InstanceMethods
24
+ def instance_method
25
+ end
26
+ end
27
+ end
28
+
29
+ module Second
30
+ include_and_extend First
31
+ end
32
+
33
+ class Third
34
+ include_and_extend Second
35
+ end
36
+
37
+ def trial
38
+ @trial ||= Trial.new
39
+ end
40
+
41
+ describe Module do
42
+
43
+ describe "#include_and_extend" do
44
+ it "should include class methods directly" do
45
+ Second.should respond_to(:class_method)
46
+ end
47
+
48
+
49
+ it "should not include class methods indirectly" do
50
+ Third.should respond_to(:class_method)
51
+ end
52
+
53
+ it "should include class methods" do
54
+ Third.new.should respond_to(:instance_method)
55
+ end
56
+ end
57
+
58
+ describe "#autoload_modules" do
59
+ it "should autoload modules using :from => path" do
60
+ require 'fixtures/autoload_modules'
61
+ AutoloadModules::Third.should respond_to(:test)
62
+ end
63
+
64
+ it "should autoload modules from __FILE__'s dir if :from is omitted'" do
65
+ require 'fixtures/autoload_modulez'
66
+ AutoloadModulez::ThirdOneHere.should respond_to(:test)
67
+ end
68
+
69
+ context 'using AutoLoader.root' do
70
+ it 'empty root' do
71
+ AutoLoader.root = ''
72
+ require 'autoload_blank_root'
73
+ AutoloadBlankRoot::Hello.should respond_to(:test)
74
+ end
75
+
76
+ it 'should autoload modules using ClassExt#autoload_root' do
77
+ AutoLoader.root = 'fixtures'
78
+ require 'fixtures/autoload_modules_root'
79
+ AutoloadModulesRoot::Third.should respond_to(:test)
80
+ end
81
+ end
82
+
83
+ context 'using AutoLoader.namespaces' do
84
+ it 'empty root' do
85
+ AutoLoader.root = ''
86
+ AutoLoader.namespaces= {:AutoLoadBlankRoot => 'autoload_blank_root', :HelloSailor => 'sailor'}
87
+ require 'auto_load_blank_root'
88
+ AutoLoadBlankRoot::HelloSailor.should respond_to(:test)
89
+ end
90
+ end
91
+ end
92
+ end
93
+
94
+ describe ClassExt do
95
+ describe '#try_module' do
96
+ it "should return false if no module found" do
97
+ trial.try_module('Blip').should be_false
98
+ trial.try_module(:Blip).should be_false
99
+ trial.try_module(nil).should be_false
100
+ end
101
+
102
+ it "should return module if found" do
103
+ trial.try_module('GoodBye').should be_a(Module)
104
+ trial.try_module(:GoodBye).should be_a(Module)
105
+ end
106
+
107
+ it "should return namespaced module if found" do
108
+ trial.try_module('GoodBye::Alpha::Beta').should be_a(Module)
109
+ end
110
+
111
+ it "should return false if only class of that name is found" do
112
+ trial.try_module('Hello').should be_true
113
+ end
114
+ end
115
+
116
+ describe '#try_class' do
117
+ it "should return false if no class found" do
118
+ trial.try_class('Blip').should be_false
119
+ trial.try_class(:Blip).should be_false
120
+ trial.try_class(nil).should be_false
121
+ end
122
+
123
+ it "should return class if found" do
124
+ trial.try_class('Hello').should be_a(Class)
125
+ trial.try_class(:Hello).should be_a(Class)
126
+ end
127
+
128
+ it "should return false if only class of that name is found" do
129
+ trial.try_class('GoodBye').should be_false
130
+ end
131
+ end
132
+
133
+ describe '#class_exists?' do
134
+ it "should return false if no class found" do
135
+ trial.class_exists?('Blip').should be_false
136
+ end
137
+
138
+ it "should return true if class found" do
139
+ trial.class_exists?('Hello').should be_true
140
+ end
141
+
142
+ it "should return false if module found" do
143
+ trial.class_exists?('GoodBye').should be_false
144
+ end
145
+ end
146
+
147
+ describe '#module_exists?' do
148
+ it "should return false if no module found" do
149
+ trial.module_exists?('Blip').should be_false
150
+ end
151
+
152
+ it "should return true if module found" do
153
+ trial.module_exists?('GoodBye').should be_true
154
+ end
155
+
156
+ it "should return false if only class found" do
157
+ trial.module_exists?('Hello').should be_false
158
+ end
159
+ end
160
+
161
+ describe '#try_module_only' do
162
+ it 'should find module' do
163
+ trial.try_module_only('Hello').should be_false
164
+ trial.try_module_only('GoodBye').should be_true
165
+ end
166
+ end
167
+
168
+ describe '#find_first_class' do
169
+ it 'should find first class' do
170
+ trial.find_first_class('GoodBye', 'Hello').should == Hello
171
+ end
172
+
173
+ it 'should not find any module' do
174
+ lambda {trial.find_first_class('Good', 'Bye') }.should raise_error
175
+ end
176
+ end
177
+
178
+ describe '#find_first_module' do
179
+ it 'should find first module' do
180
+ first_module = trial.find_first_module('GoodBye::Alpha::Beta', 'Hello')
181
+ first_module.should == GoodBye::Alpha::Beta
182
+ end
183
+
184
+ it 'should not find any module' do
185
+ lambda {trial.find_first_module('Good', 'Bye') }.should raise_error
186
+ end
187
+ end
188
+ end
189
+
@@ -0,0 +1,82 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{sweetloader}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = [%q{Kristian Mandrup}]
12
+ s.date = %q{2011-08-21}
13
+ s.description = %q{sweet autoloading using file structure conventions while allowing configuration overrides for special cases}
14
+ s.email = %q{kmandrup@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.textile"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "LICENSE.txt",
24
+ "README.textile",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/sweetloader.rb",
28
+ "spec/auto_load_blank_root.rb",
29
+ "spec/autoload_blank_root.rb",
30
+ "spec/autoload_blank_root/hello.rb",
31
+ "spec/autoload_blank_root/sailor.rb",
32
+ "spec/class_ext_spec.rb",
33
+ "spec/fixtures/autoload_modules.rb",
34
+ "spec/fixtures/autoload_modules/subdir/first.rb",
35
+ "spec/fixtures/autoload_modules/subdir/second.rb",
36
+ "spec/fixtures/autoload_modules/subdir/third.rb",
37
+ "spec/fixtures/autoload_modules_root.rb",
38
+ "spec/fixtures/autoload_modules_root/first.rb",
39
+ "spec/fixtures/autoload_modules_root/second.rb",
40
+ "spec/fixtures/autoload_modules_root/third.rb",
41
+ "spec/fixtures/autoload_modulez.rb",
42
+ "spec/fixtures/autoload_modulez/first.rb",
43
+ "spec/fixtures/autoload_modulez/second.rb",
44
+ "spec/fixtures/autoload_modulez/third_one_here.rb",
45
+ "spec/spec_helper.rb",
46
+ "spec/sweetloader/sweetloader_spec.rb",
47
+ "sweetloader.gemspec"
48
+ ]
49
+ s.homepage = %q{http://github.com/kristianmandrup/sweetloader}
50
+ s.licenses = [%q{MIT}]
51
+ s.require_paths = [%q{lib}]
52
+ s.rubygems_version = %q{1.8.8}
53
+ s.summary = %q{sweetens up autoloading using file structure conventions}
54
+
55
+ if s.respond_to? :specification_version then
56
+ s.specification_version = 3
57
+
58
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
59
+ s.add_runtime_dependency(%q<activesupport>, [">= 3.0.1"])
60
+ s.add_runtime_dependency(%q<i18n>, [">= 0"])
61
+ s.add_development_dependency(%q<rspec>, [">= 2.5.0"])
62
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.10"])
63
+ s.add_development_dependency(%q<jeweler>, [">= 1.6.4"])
64
+ s.add_development_dependency(%q<rcov>, [">= 0"])
65
+ else
66
+ s.add_dependency(%q<activesupport>, [">= 3.0.1"])
67
+ s.add_dependency(%q<i18n>, [">= 0"])
68
+ s.add_dependency(%q<rspec>, [">= 2.5.0"])
69
+ s.add_dependency(%q<bundler>, ["~> 1.0.10"])
70
+ s.add_dependency(%q<jeweler>, [">= 1.6.4"])
71
+ s.add_dependency(%q<rcov>, [">= 0"])
72
+ end
73
+ else
74
+ s.add_dependency(%q<activesupport>, [">= 3.0.1"])
75
+ s.add_dependency(%q<i18n>, [">= 0"])
76
+ s.add_dependency(%q<rspec>, [">= 2.5.0"])
77
+ s.add_dependency(%q<bundler>, ["~> 1.0.10"])
78
+ s.add_dependency(%q<jeweler>, [">= 1.6.4"])
79
+ s.add_dependency(%q<rcov>, [">= 0"])
80
+ end
81
+ end
82
+
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sweetloader
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kristian Mandrup
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-21 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: &2155225860 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2155225860
25
+ - !ruby/object:Gem::Dependency
26
+ name: i18n
27
+ requirement: &2155225300 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2155225300
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &2155224820 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 2.5.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *2155224820
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: &2155224240 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.10
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *2155224240
58
+ - !ruby/object:Gem::Dependency
59
+ name: jeweler
60
+ requirement: &2155223640 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: 1.6.4
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *2155223640
69
+ - !ruby/object:Gem::Dependency
70
+ name: rcov
71
+ requirement: &2155223020 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *2155223020
80
+ description: sweet autoloading using file structure conventions while allowing configuration
81
+ overrides for special cases
82
+ email: kmandrup@gmail.com
83
+ executables: []
84
+ extensions: []
85
+ extra_rdoc_files:
86
+ - LICENSE.txt
87
+ - README.textile
88
+ files:
89
+ - .document
90
+ - .rspec
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.textile
94
+ - Rakefile
95
+ - VERSION
96
+ - lib/sweetloader.rb
97
+ - spec/auto_load_blank_root.rb
98
+ - spec/autoload_blank_root.rb
99
+ - spec/autoload_blank_root/hello.rb
100
+ - spec/autoload_blank_root/sailor.rb
101
+ - spec/class_ext_spec.rb
102
+ - spec/fixtures/autoload_modules.rb
103
+ - spec/fixtures/autoload_modules/subdir/first.rb
104
+ - spec/fixtures/autoload_modules/subdir/second.rb
105
+ - spec/fixtures/autoload_modules/subdir/third.rb
106
+ - spec/fixtures/autoload_modules_root.rb
107
+ - spec/fixtures/autoload_modules_root/first.rb
108
+ - spec/fixtures/autoload_modules_root/second.rb
109
+ - spec/fixtures/autoload_modules_root/third.rb
110
+ - spec/fixtures/autoload_modulez.rb
111
+ - spec/fixtures/autoload_modulez/first.rb
112
+ - spec/fixtures/autoload_modulez/second.rb
113
+ - spec/fixtures/autoload_modulez/third_one_here.rb
114
+ - spec/spec_helper.rb
115
+ - spec/sweetloader/sweetloader_spec.rb
116
+ - sweetloader.gemspec
117
+ homepage: http://github.com/kristianmandrup/sweetloader
118
+ licenses:
119
+ - MIT
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ! '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ segments:
131
+ - 0
132
+ hash: 2409886545275746865
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ none: false
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 1.8.8
142
+ signing_key:
143
+ specification_version: 3
144
+ summary: sweetens up autoloading using file structure conventions
145
+ test_files: []