autocode 0.9.9 → 1.0.0
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/lib/autocode.rb +8 -4
- data/test/auto_create.rb +4 -4
- data/test/auto_eval.rb +3 -3
- data/test/auto_load.rb +3 -11
- data/test/helpers.rb +2 -2
- data/test/normalize.rb +30 -0
- metadata +7 -12
data/lib/autocode.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
module AutoCode
|
2
2
|
|
3
3
|
# always make sure we have a camel-cased symbol
|
4
|
-
def AutoCode.normalize( cname )
|
5
|
-
return cname
|
6
|
-
|
4
|
+
def AutoCode.normalize( cname )
|
5
|
+
return cname unless cname.is_a? Symbol or cname.is_a? String
|
6
|
+
camel_case( cname )
|
7
|
+
end
|
8
|
+
|
9
|
+
def AutoCode.camel_case( cname )
|
10
|
+
cname.to_s.gsub(/^([a-z])/) { $1.upcase }.gsub(/(_)(\w)/) { $2.upcase }.intern
|
7
11
|
end
|
8
12
|
|
9
13
|
def AutoCode.snake_case( cname )
|
@@ -82,7 +86,7 @@ module AutoCode
|
|
82
86
|
constructors.pop.call( cname ) until ( const_defined?( cname ) or constructors.empty? )
|
83
87
|
return old.call( cname ) unless const_defined?( cname )
|
84
88
|
initializers = @autocode[:initializers][true] + @autocode[:initializers][cname]
|
85
|
-
mod = const_get( cname ) ; initializers.
|
89
|
+
mod = const_get( cname ) ; initializers.shift.call( mod ) until initializers.empty?
|
86
90
|
@autocode[:loaded] << cname ; const_get( cname )
|
87
91
|
end
|
88
92
|
end
|
data/test/auto_create.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'helpers.rb')
|
2
2
|
|
3
|
-
describe "auto_create
|
3
|
+
describe "auto_create" do
|
4
4
|
|
5
5
|
before do
|
6
6
|
Object.instance_eval { remove_const(:A) if const_defined?(:A) }
|
@@ -13,15 +13,15 @@ describe "auto_create should" do
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
specify "
|
16
|
+
specify "allows you to create and initialize a given const name" do
|
17
17
|
A::B.class.should == Module
|
18
18
|
end
|
19
19
|
|
20
|
-
specify "
|
20
|
+
specify "allows you to create and initialize const using a wildcard" do
|
21
21
|
A::B::C.class.should === Class
|
22
22
|
end
|
23
23
|
|
24
|
-
specify "
|
24
|
+
specify "raises a NameError if a const doesn't match" do
|
25
25
|
lambda{ A::C }.should.raise NameError
|
26
26
|
end
|
27
27
|
|
data/test/auto_eval.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'helpers.rb')
|
2
2
|
|
3
|
-
describe "auto_eval
|
3
|
+
describe "auto_eval" do
|
4
4
|
|
5
5
|
before do
|
6
6
|
Object.instance_eval { remove_const(:A) if const_defined?(:A) }
|
@@ -20,11 +20,11 @@ describe "auto_eval should" do
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
specify "
|
23
|
+
specify "allows you to run blocks after an object is first created" do
|
24
24
|
A::B::C.class.should == Class
|
25
25
|
end
|
26
26
|
|
27
|
-
specify "
|
27
|
+
specify "allows you to define nested auto_eval declarations" do
|
28
28
|
A::B::C::D.should == true
|
29
29
|
end
|
30
30
|
|
data/test/auto_load.rb
CHANGED
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), 'helpers.rb')
|
|
2
2
|
require 'extensions/io'
|
3
3
|
|
4
4
|
|
5
|
-
describe "auto_load
|
5
|
+
describe "auto_load" do
|
6
6
|
|
7
7
|
before do
|
8
8
|
Object.instance_eval { remove_const(:A) if const_defined?(:A) }
|
@@ -28,7 +28,7 @@ describe "auto_load should" do
|
|
28
28
|
FileUtils.rmdir( 'tmp' )
|
29
29
|
end
|
30
30
|
|
31
|
-
specify "
|
31
|
+
specify "allows you to load a file to define a const" do
|
32
32
|
A::B.class.should == Module
|
33
33
|
end
|
34
34
|
|
@@ -36,16 +36,8 @@ describe "auto_load should" do
|
|
36
36
|
A::B.class.should == Module
|
37
37
|
end
|
38
38
|
|
39
|
-
specify "
|
39
|
+
specify "raises a NameError if a const doesn't match" do
|
40
40
|
lambda{ A::C }.should.raise NameError
|
41
41
|
end
|
42
|
-
|
43
|
-
specify "snake case the constant name which is used to map a constant to a filename" do
|
44
|
-
AutoCode.snake_case(:Post).should == "post"
|
45
|
-
AutoCode.snake_case(:GitHub).should == "git_hub"
|
46
|
-
AutoCode.snake_case(:GITRepository).should == "git_repository"
|
47
|
-
AutoCode.snake_case(:Git42Repository).should == "git42_repository"
|
48
|
-
AutoCode.snake_case(:GIT42Repository).should == "git42_repository"
|
49
|
-
end
|
50
42
|
|
51
43
|
end
|
data/test/helpers.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
%w{ bacon
|
2
|
+
%w{ bacon }.each { |dep| require dep }
|
3
3
|
# Bacon.extend Bacon::TestUnitOutput
|
4
4
|
Bacon.summary_on_exit
|
5
5
|
|
@@ -12,4 +12,4 @@ Bacon::Context.instance_eval do
|
|
12
12
|
alias_method :specify, :it
|
13
13
|
end
|
14
14
|
|
15
|
-
require
|
15
|
+
require "#{File.dirname(__FILE__)}/../lib/autocode"
|
data/test/normalize.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'helpers.rb')
|
2
|
+
|
3
|
+
describe "AutoCode should normalize const names" do
|
4
|
+
|
5
|
+
before do
|
6
|
+
Object.instance_eval { remove_const(:A) if const_defined?(:A) }
|
7
|
+
module A
|
8
|
+
include AutoCode
|
9
|
+
auto_create_module :foo_bar
|
10
|
+
auto_create_module :foo_bar_baz
|
11
|
+
auto_create_module :weird_Casing
|
12
|
+
auto_create_module :catch_22
|
13
|
+
auto_create_module :front242
|
14
|
+
end
|
15
|
+
A.auto_eval( :foo_bar ) { self::D = true }
|
16
|
+
A.auto_eval( :foo_bar_baz ) { self::D = true }
|
17
|
+
A.auto_eval( :weird_Casing ) { self::D = true }
|
18
|
+
A.auto_eval( :Catch22 ) { self::D = true }
|
19
|
+
A.auto_eval( :Front242 ) { self::D = true }
|
20
|
+
end
|
21
|
+
|
22
|
+
specify "converting from snake-case to camel-case" do
|
23
|
+
A::FooBar::D.should == true
|
24
|
+
A::FooBarBaz::D.should == true
|
25
|
+
A::WeirdCasing::D.should == true
|
26
|
+
A::Catch22::D.should == true
|
27
|
+
A::Front242::D.should == true
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
metadata
CHANGED
@@ -1,26 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: autocode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Yoder
|
8
|
+
- Matthew King
|
9
|
+
- Lawrence Pitt
|
8
10
|
autorequire:
|
9
11
|
bindir: bin
|
10
12
|
cert_chain: []
|
11
13
|
|
12
|
-
date: 2008-
|
14
|
+
date: 2008-06-09 00:00:00 -05:00
|
13
15
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
16
|
-
name: metaid
|
17
|
-
version_requirement:
|
18
|
-
version_requirements: !ruby/object:Gem::Requirement
|
19
|
-
requirements:
|
20
|
-
- - ">="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: "0"
|
23
|
-
version:
|
16
|
+
dependencies: []
|
17
|
+
|
24
18
|
description:
|
25
19
|
email: dan@zeraweb.com
|
26
20
|
executables: []
|
@@ -35,6 +29,7 @@ files:
|
|
35
29
|
- test/auto_eval.rb
|
36
30
|
- test/auto_load.rb
|
37
31
|
- test/helpers.rb
|
32
|
+
- test/normalize.rb
|
38
33
|
has_rdoc: true
|
39
34
|
homepage: http://dev.zeraweb.com/
|
40
35
|
post_install_message:
|