GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Rubygem
Description: Ruby library for auto-loading and auto-creation of classes and modules.
Homepage: http://dev.zeraweb.com/autocode
Clone URL: git://github.com/dyoder/autocode.git
tweaked for 1.0.0 release
automatthew (author)
Mon Jun 09 10:15:02 -0700 2008
commit  56a020f8dca6d6d286fd5412e92b7a2f42b1442b
tree    93e5659bc739e9d797687a7bf7f4820967dea5d0
parent  231ca262a2d9493b813caf8f765fc4ba116672e8
...
 
 
1
2
3
...
1
2
3
4
5
0
@@ -1,3 +1,5 @@
0
+1.0.0
0
+- Clarified intent of camel-casing constant names
0
 0.9.9
0
 - Added auto_eval
0
 - Fixed loading bug for "multi-word" constants
0
...
40
41
42
43
 
44
45
46
47
48
49
50
 
 
 
 
51
52
53
54
55
56
 
57
58
59
60
 
61
62
 
63
64
...
40
41
42
 
43
44
45
46
47
48
 
 
49
50
51
52
53
54
55
56
57
 
58
59
60
61
 
62
63
 
64
65
66
0
@@ -40,25 +40,27 @@ For example, referencing <tt>Application::Models::Customer</tt> will cause the f
0
 
0
 == Initializing
0
 
0
-Sometimes you want to reopen a class or module and add or change methods, etc. However, in the case of auto-loading or creating unless your code is in an auto_load or auto_create block, it will get clobbered upon reload. You address this using auto_eval which registers blocks against constant names so that auto_create and auto_load can run them after object creation.
0
+Sometimes you want to reopen a class or module and add or change methods, etc. However, in the case of auto-loading or creating unless your code is in an auto_loaded file or an auto_create block, it will get clobbered upon reload. You avoid the clobber using auto_eval, which registers blocks against constant names so that auto_create and auto_load can run them after object creation.
0
 
0
 require 'auto_code'
0
 
0
 module Application
0
   include AutoCode
0
- Models.auto_eval(true) do
0
- set_model self.name
0
+ auto_eval :views do
0
+ auto_eval :error do
0
+ def not_found; "404 Not Found"; end
0
+ end
0
   end
0
 end
0
 
0
 == Other Uses
0
 
0
-Autoloading and autocreation, along with reloading, can be used to provide sophisticated rules for loading and even generating modules and classes within a given module. These capabilities are increasingly found within frameworks like Rails and Camping, but *AutoCode* makes it possible to mixin these capabilities into any situation and precisely control how they are applied.
0
+Autoloading and autocreation, along with reloading, can be used to provide sophisticated rules for loading, generating, and configuring modules and classes within a given module. These capabilities are increasingly found within frameworks like Rails and Camping, but *AutoCode* makes it possible to mixin these capabilities into any situation and precisely control how they are applied.
0
 
0
 == Support
0
 
0
-If you have questions or comments, please go to the Waves support forum (which also supports AutoCode, since AutoCode is principally used within Waves) at http://groups.google.com/group/rubywaves.
0
+Direct questions or comments to the Waves support forum (which also supports AutoCode, as it is principally used within Waves) at http://groups.google.com/group/rubywaves. You can submit bugs to the Waves issue tracker at http://waves.lighthouseapp.com.
0
 
0
-(c) 2007 Dan Yoder
0
+(c) 2008 Dan Yoder
0
 
0
 Licensed under the MIT License.
...
1
2
3
4
5
 
 
 
6
7
8
...
18
19
20
21
22
23
24
...
60
61
62
63
64
 
65
66
67
...
 
 
 
 
 
1
2
3
4
5
6
...
16
17
18
 
19
20
21
...
57
58
59
 
 
60
61
 
62
0
@@ -1,8 +1,6 @@
0
-require 'rubygems'
0
-require 'date'
0
-require 'rake/rdoctask'
0
-require 'rake/testtask'
0
-require 'fileutils'
0
+%w{ rubygems date rake/rdoctask rake/testtask fileutils }.each do |dep|
0
+ require dep
0
+end
0
 
0
 Gem::manage_gems
0
 include FileUtils
0
@@ -18,7 +16,6 @@ spec = Gem::Specification.new do |s|
0
   s.authors = ["Dan Yoder", "Matthew King", "Lawrence Pitt"]
0
   s.email = 'dan@zeraweb.com'
0
   s.homepage = 'http://dev.zeraweb.com/'
0
- s.add_dependency 'metaid'
0
   s.summary = "Utility for auto-including, reloading, and generating classes and modules."
0
   s.files = Dir['*/**/*']
0
   s.bindir = 'bin'
0
@@ -60,8 +57,6 @@ Rake::RDocTask.new do |rdoc|
0
 end
0
 
0
 Rake::TestTask.new(:test) do |t|
0
- t.test_files = FileList["test/*.rb"].exclude("test/helpers.rb", "test_lib/**/*")
0
- Dir.chdir 'test'
0
+ t.test_files = FileList["test/*.rb"].exclude("test/helpers.rb")
0
   t.verbose = true
0
- Dir.chdir '..'
0
 end
...
1
2
3
 
4
5
6
7
8
9
10
 
 
 
 
11
12
13
14
15
 
 
16
17
18
19
...
1
2
 
3
4
5
6
7
 
 
 
8
9
10
11
12
13
14
15
 
16
17
18
 
 
19
0
@@ -1,19 +1,19 @@
0
 Gem::Specification.new do |s|
0
   s.name = %q{autocode}
0
- s.version = "0.9.9"
0
+ s.version = "1.0.0"
0
 
0
   s.specification_version = 2 if s.respond_to? :specification_version=
0
 
0
   s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
0
- s.authors = ["Dan Yoder"]
0
- s.date = %q{2008-05-15}
0
- s.files = ["lib/autocode.rb", "test/auto_code.gemspec", "test/auto_create.rb", "test/auto_eval.rb", "test/auto_load.rb", "test/autocode.gemspec", "test/helpers.rb"]
0
+ s.authors = ["Dan Yoder", "Matthew King", "Lawrence Pitt"]
0
+ s.date = %q{2008-06-09}
0
+ s.email = %q{dan@zeraweb.com}
0
+ s.files = ["lib/autocode.rb", "test/auto_create.rb", "test/auto_eval.rb", "test/auto_load.rb", "test/helpers.rb", "test/normalize.rb"]
0
   s.has_rdoc = true
0
   s.homepage = %q{http://dev.zeraweb.com/}
0
   s.require_paths = ["lib"]
0
   s.required_ruby_version = Gem::Requirement.new(">= 1.8.6")
0
- s.rubygems_version = %q{1.1.1}
0
+ s.rubyforge_project = %q{autocode}
0
+ s.rubygems_version = %q{1.0.1}
0
   s.summary = %q{Utility for auto-including, reloading, and generating classes and modules.}
0
-
0
- s.add_dependency(%q<metaid>, [">= 0"])
0
 end
...
1
2
3
 
4
5
6
...
13
14
15
16
 
17
18
19
20
 
21
22
23
24
 
25
26
27
...
1
2
 
3
4
5
6
...
13
14
15
 
16
17
18
19
 
20
21
22
23
 
24
25
26
27
0
@@ -1,6 +1,6 @@
0
 require File.join(File.dirname(__FILE__), 'helpers.rb')
0
 
0
-describe "auto_create should" do
0
+describe "auto_create" do
0
 
0
   before do
0
     Object.instance_eval { remove_const(:A) if const_defined?(:A) }
0
@@ -13,15 +13,15 @@ describe "auto_create should" do
0
     end
0
   end
0
   
0
- specify "allow you create and initialize a given const name" do
0
+ specify "allows you to create and initialize a given const name" do
0
     A::B.class.should == Module
0
   end
0
   
0
- specify "allow you create and initialize const using a wildcard" do
0
+ specify "allows you to create and initialize const using a wildcard" do
0
     A::B::C.class.should === Class
0
   end
0
   
0
- specify "should raise a NameError if a const doesn't match" do
0
+ specify "raises a NameError if a const doesn't match" do
0
     lambda{ A::C }.should.raise NameError
0
   end
0
   
...
1
2
3
 
4
5
6
...
20
21
22
23
 
24
25
26
27
 
28
29
30
...
1
2
 
3
4
5
6
...
20
21
22
 
23
24
25
26
 
27
28
29
30
0
@@ -1,6 +1,6 @@
0
 require File.join(File.dirname(__FILE__), 'helpers.rb')
0
 
0
-describe "auto_eval should" do
0
+describe "auto_eval" do
0
 
0
   before do
0
     Object.instance_eval { remove_const(:A) if const_defined?(:A) }
0
@@ -20,11 +20,11 @@ describe "auto_eval should" do
0
     end
0
   end
0
   
0
- specify "allow you to run blocks after an object is first created" do
0
+ specify "allows you to run blocks after an object is first created" do
0
     A::B::C.class.should == Class
0
   end
0
   
0
- specify "allow you to define nested auto_eval declarations" do
0
+ specify "allows you to define nested auto_eval declarations" do
0
     A::B::C::D.should == true
0
   end
0
 
...
2
3
4
5
 
6
7
8
...
28
29
30
31
 
32
33
34
...
36
37
38
39
 
40
41
42
43
44
45
46
47
48
49
50
51
52
...
2
3
4
 
5
6
7
8
...
28
29
30
 
31
32
33
34
...
36
37
38
 
39
40
41
 
 
 
 
 
 
 
 
42
43
44
0
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), 'helpers.rb')
0
 require 'extensions/io'
0
 
0
 
0
-describe "auto_load should" do
0
+describe "auto_load" do
0
 
0
   before do
0
     Object.instance_eval { remove_const(:A) if const_defined?(:A) }
0
@@ -28,7 +28,7 @@ describe "auto_load should" do
0
     FileUtils.rmdir( 'tmp' )
0
   end
0
   
0
- specify "allow you to load a file to define a const" do
0
+ specify "allows you to load a file to define a const" do
0
     A::B.class.should == Module
0
   end
0
   
0
@@ -36,16 +36,8 @@ describe "auto_load should" do
0
     A::B.class.should == Module
0
   end
0
 
0
- specify "should raise a NameError if a const doesn't match" do
0
+ specify "raises a NameError if a const doesn't match" do
0
     lambda{ A::C }.should.raise NameError
0
   end
0
-
0
- specify "snake case the constant name which is used to map a constant to a filename" do
0
- AutoCode.snake_case(:Post).should == "post"
0
- AutoCode.snake_case(:GitHub).should == "git_hub"
0
- AutoCode.snake_case(:GITRepository).should == "git_repository"
0
- AutoCode.snake_case(:Git42Repository).should == "git42_repository"
0
- AutoCode.snake_case(:GIT42Repository).should == "git42_repository"
0
- end
0
 
0
 end
0
\ No newline at end of file
...
1
2
 
3
4
5
...
12
13
14
15
16
 
17
...
1
 
2
3
4
5
...
12
13
14
 
15
16
17
0
@@ -1,5 +1,5 @@
0
 require 'rubygems'
0
-%w{ bacon metaid }.each { |dep| require dep }
0
+%w{ bacon }.each { |dep| require dep }
0
 # Bacon.extend Bacon::TestUnitOutput
0
 Bacon.summary_on_exit
0
 
0
@@ -12,4 +12,4 @@ Bacon::Context.instance_eval do
0
   alias_method :specify, :it
0
 end
0
 
0
-require 'lib/autocode'
0
\ No newline at end of file
0
+require "#{File.dirname(__FILE__)}/../lib/autocode"
0
\ No newline at end of file
...
7
8
9
 
 
 
 
10
11
12
13
 
 
 
 
 
14
15
16
17
 
 
 
 
18
19
20
21
...
7
8
9
10
11
12
13
14
 
 
 
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
0
@@ -7,14 +7,24 @@ describe "AutoCode should normalize const names" do
0
     module A
0
       include AutoCode
0
       auto_create_module :foo_bar
0
+ auto_create_module :foo_bar_baz
0
+ auto_create_module :weird_Casing
0
+ auto_create_module :catch_22
0
+ auto_create_module :front242
0
     end
0
- A.auto_eval :foo_bar do
0
- self::D = true
0
- end
0
+ A.auto_eval( :foo_bar ) { self::D = true }
0
+ A.auto_eval( :foo_bar_baz ) { self::D = true }
0
+ A.auto_eval( :weird_Casing ) { self::D = true }
0
+ A.auto_eval( :Catch22 ) { self::D = true }
0
+ A.auto_eval( :Front242 ) { self::D = true }
0
   end
0
   
0
   specify "converting from snake-case to camel-case" do
0
     A::FooBar::D.should == true
0
+ A::FooBarBaz::D.should == true
0
+ A::WeirdCasing::D.should == true
0
+ A::Catch22::D.should == true
0
+ A::Front242::D.should == true
0
   end
0
 
0
 end
0
\ No newline at end of file

Comments

    No one has commented yet.