sugar-high 0.4.9.5 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,5 +1,3 @@
1
- require 'psych'
2
-
3
1
  begin
4
2
  require 'jeweler'
5
3
  Jeweler::Tasks.new do |gem|
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.9.5
1
+ 0.5.0
@@ -14,15 +14,17 @@ class Module
14
14
 
15
15
  def autoload_modules *args
16
16
 
17
- options = args.extract_options!
17
+ options = args.extract_options!
18
18
  root = options[:root] || AutoLoader.root || ''
19
19
  path = root.strip.empty? ? self.name.to_s.underscore : [root, self.name.to_s.underscore].join('/')
20
20
  from = options[:from] || path
21
21
 
22
22
  # Here also could be adding of the file in top of load_paths like: $:.unshift File.dirname(__FILE__)
23
23
  # It is very useful for situations of having not load_paths built Rails or Gems way.
24
- args.each do |req_name|
25
- send :autoload, req_name, "#{from}/#{req_name.to_s.underscore}"
24
+ args.each do |req_name|
25
+ ruby_file = req_name.to_s.underscore
26
+
27
+ send :autoload, req_name, AutoLoader.translate("#{from}/#{ruby_file}")
26
28
  end
27
29
  end
28
30
 
@@ -30,13 +32,30 @@ end
30
32
 
31
33
  module AutoLoader
32
34
  @@root = ''
35
+ @@namespaces = {}
33
36
 
34
37
  def self.root
35
38
  @@root
36
39
  end
37
40
 
38
- def self.root= root_dir
39
- @@root = root_dir
41
+ def self.namespaces
42
+ @@namespaces
43
+ end
44
+
45
+ def self.root= root
46
+ @@root = root
47
+ end
48
+
49
+ def self.namespaces= namespaces
50
+ @@namespaces = namespaces
51
+ end
52
+
53
+ def self.translate name
54
+ names = name.split('/')
55
+ names.map do |name|
56
+ clazz_name = name.to_s.camelize
57
+ namespaces[clazz_name.to_sym] ? namespaces[clazz_name.to_sym] : name
58
+ end.join('/')
40
59
  end
41
60
  end
42
61
 
@@ -0,0 +1,3 @@
1
+ module AutoLoadBlankRoot
2
+ autoload_modules :HelloSailor
3
+ end
@@ -0,0 +1,7 @@
1
+ module AutoLoadBlankRoot
2
+ module HelloSailor
3
+ def self.test
4
+ "test"
5
+ end
6
+ end
7
+ end
@@ -42,39 +42,53 @@ end
42
42
  describe Module do
43
43
 
44
44
  describe "#include_and_extend" do
45
- it "should include class methods" do
46
- Third.should respond_to(:class_method)
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)
47
52
  end
48
53
 
49
54
  it "should include class methods" do
50
55
  Third.new.should respond_to(:instance_method)
51
56
  end
52
57
  end
53
-
58
+
54
59
  describe "#autoload_modules" do
55
60
  it "should autoload modules using :from => path" do
56
61
  require 'fixtures/autoload_modules'
57
62
  AutoloadModules::Third.should respond_to(:test)
58
63
  end
59
-
64
+
60
65
  it "should autoload modules from __FILE__'s dir if :from is omitted'" do
61
66
  require 'fixtures/autoload_modulez'
62
67
  AutoloadModulez::ThirdOneHere.should respond_to(:test)
63
68
  end
64
-
69
+
65
70
  context 'using AutoLoader.root' do
66
71
  it 'empty root' do
67
72
  AutoLoader.root = ''
68
73
  require 'autoload_blank_root'
69
74
  AutoloadBlankRoot::Hello.should respond_to(:test)
70
- end
75
+ end
71
76
 
72
77
  it 'should autoload modules using ClassExt#autoload_root' do
73
78
  AutoLoader.root = 'fixtures'
74
79
  require 'fixtures/autoload_modules_root'
75
80
  AutoloadModulesRoot::Third.should respond_to(:test)
76
- end
77
- end
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
78
92
  end
79
93
  end
80
94
 
@@ -116,7 +130,7 @@ describe ClassExt do
116
130
  trial.try_class('GoodBye').should be_false
117
131
  end
118
132
  end
119
-
133
+
120
134
  describe '#class_exists?' do
121
135
  it "should return false if no class found" do
122
136
  trial.class_exists?('Blip').should be_false
@@ -129,8 +143,8 @@ describe ClassExt do
129
143
  it "should return false if module found" do
130
144
  trial.class_exists?('GoodBye').should be_false
131
145
  end
132
- end
133
-
146
+ end
147
+
134
148
  describe '#module_exists?' do
135
149
  it "should return false if no module found" do
136
150
  trial.module_exists?('Blip').should be_false
@@ -139,10 +153,10 @@ describe ClassExt do
139
153
  it "should return true if module found" do
140
154
  trial.module_exists?('GoodBye').should be_true
141
155
  end
142
-
156
+
143
157
  it "should return false if only class found" do
144
158
  trial.module_exists?('Hello').should be_false
145
- end
159
+ end
146
160
  end
147
161
 
148
162
  describe '#try_module_only' do
@@ -150,16 +164,16 @@ describe ClassExt do
150
164
  trial.try_module_only('Hello').should be_false
151
165
  trial.try_module_only('GoodBye').should be_true
152
166
  end
153
- end
167
+ end
154
168
 
155
169
  describe '#find_first_class' do
156
170
  it 'should find first class' do
157
171
  trial.find_first_class('GoodBye', 'Hello').should == Hello
158
172
  end
159
-
173
+
160
174
  it 'should not find any module' do
161
175
  lambda {trial.find_first_class('Good', 'Bye') }.should raise_error
162
- end
176
+ end
163
177
  end
164
178
 
165
179
  describe '#find_first_module' do
@@ -171,5 +185,5 @@ describe ClassExt do
171
185
  it 'should not find any module' do
172
186
  lambda {trial.find_first_module('Good', 'Bye') }.should raise_error
173
187
  end
174
- end
188
+ end
175
189
  end
data/sugar-high.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sugar-high}
8
- s.version = "0.4.9.5"
8
+ s.version = "0.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Kristian Mandrup}]
12
- s.date = %q{2011-06-30}
12
+ s.date = %q{2011-07-20}
13
13
  s.description = %q{More Ruby sugar - inspired by the 'zuker' project}
14
14
  s.email = %q{kmandrup@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -58,8 +58,10 @@ Gem::Specification.new do |s|
58
58
  "lib/sugar-high/rspec/matchers/have_aliases.rb",
59
59
  "lib/sugar-high/string.rb",
60
60
  "sandbox/test_routes_mutate.rb",
61
+ "spec/auto_load_blank_root.rb",
61
62
  "spec/autoload_blank_root.rb",
62
63
  "spec/autoload_blank_root/hello.rb",
64
+ "spec/autoload_blank_root/sailor.rb",
63
65
  "spec/fixtures/application_file.rb",
64
66
  "spec/fixtures/autoload_modules.rb",
65
67
  "spec/fixtures/autoload_modules/subdir/first.rb",
metadata CHANGED
@@ -1,57 +1,75 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: sugar-high
3
- version: !ruby/object:Gem::Version
4
- version: 0.4.9.5
3
+ version: !ruby/object:Gem::Version
4
+ hash: 11
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 5
9
+ - 0
10
+ version: 0.5.0
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Kristian Mandrup
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2011-06-30 00:00:00.000000000Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: rspec
16
- requirement: &2161649020 !ruby/object:Gem::Requirement
17
+
18
+ date: 2011-07-20 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ requirement: &id001 !ruby/object:Gem::Requirement
17
22
  none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ hash: 3
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ version_requirements: *id001
22
31
  type: :development
32
+ name: rspec
23
33
  prerelease: false
24
- version_requirements: *2161649020
25
- - !ruby/object:Gem::Dependency
26
- name: active_support
27
- requirement: &2161648440 !ruby/object:Gem::Requirement
34
+ - !ruby/object:Gem::Dependency
35
+ requirement: &id002 !ruby/object:Gem::Requirement
28
36
  none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: '0'
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ hash: 3
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ version_requirements: *id002
33
45
  type: :development
46
+ name: active_support
34
47
  prerelease: false
35
- version_requirements: *2161648440
36
- - !ruby/object:Gem::Dependency
37
- name: rspec
38
- requirement: &2161647840 !ruby/object:Gem::Requirement
48
+ - !ruby/object:Gem::Dependency
49
+ requirement: &id003 !ruby/object:Gem::Requirement
39
50
  none: false
40
- requirements:
41
- - - ! '>='
42
- - !ruby/object:Gem::Version
43
- version: '2.5'
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ hash: 9
55
+ segments:
56
+ - 2
57
+ - 5
58
+ version: "2.5"
59
+ version_requirements: *id003
44
60
  type: :development
61
+ name: rspec
45
62
  prerelease: false
46
- version_requirements: *2161647840
47
63
  description: More Ruby sugar - inspired by the 'zuker' project
48
64
  email: kmandrup@gmail.com
49
65
  executables: []
66
+
50
67
  extensions: []
51
- extra_rdoc_files:
68
+
69
+ extra_rdoc_files:
52
70
  - LICENSE
53
71
  - README.markdown
54
- files:
72
+ files:
55
73
  - .document
56
74
  - .rspec
57
75
  - Gemfile
@@ -93,8 +111,10 @@ files:
93
111
  - lib/sugar-high/rspec/matchers/have_aliases.rb
94
112
  - lib/sugar-high/string.rb
95
113
  - sandbox/test_routes_mutate.rb
114
+ - spec/auto_load_blank_root.rb
96
115
  - spec/autoload_blank_root.rb
97
116
  - spec/autoload_blank_root/hello.rb
117
+ - spec/autoload_blank_root/sailor.rb
98
118
  - spec/fixtures/application_file.rb
99
119
  - spec/fixtures/autoload_modules.rb
100
120
  - spec/fixtures/autoload_modules/subdir/first.rb
@@ -143,26 +163,36 @@ files:
143
163
  - sugar-high.gemspec
144
164
  homepage: http://github.com/kristianmandrup/sugar-high
145
165
  licenses: []
166
+
146
167
  post_install_message:
147
168
  rdoc_options: []
148
- require_paths:
169
+
170
+ require_paths:
149
171
  - lib
150
- required_ruby_version: !ruby/object:Gem::Requirement
172
+ required_ruby_version: !ruby/object:Gem::Requirement
151
173
  none: false
152
- requirements:
153
- - - ! '>='
154
- - !ruby/object:Gem::Version
155
- version: '0'
156
- required_rubygems_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ hash: 3
178
+ segments:
179
+ - 0
180
+ version: "0"
181
+ required_rubygems_version: !ruby/object:Gem::Requirement
157
182
  none: false
158
- requirements:
159
- - - ! '>='
160
- - !ruby/object:Gem::Version
161
- version: '0'
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ hash: 3
187
+ segments:
188
+ - 0
189
+ version: "0"
162
190
  requirements: []
191
+
163
192
  rubyforge_project:
164
193
  rubygems_version: 1.8.5
165
194
  signing_key:
166
195
  specification_version: 3
167
196
  summary: Ruby convenience sugar packs!
168
197
  test_files: []
198
+