autocode 0.9.9 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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 unless cname.is_a? String
6
- cname.gsub(/(_)(\w)/) { $2.upcase }.gsub(/^([a-z])/) { $1.upcase }.intern
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.pop.call( mod ) until initializers.empty?
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
@@ -1,6 +1,6 @@
1
1
  require File.join(File.dirname(__FILE__), 'helpers.rb')
2
2
 
3
- describe "auto_create should" do
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 "allow you create and initialize a given const name" do
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 "allow you create and initialize const using a wildcard" do
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 "should raise a NameError if a const doesn't match" do
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
 
@@ -1,6 +1,6 @@
1
1
  require File.join(File.dirname(__FILE__), 'helpers.rb')
2
2
 
3
- describe "auto_eval should" do
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 "allow you to run blocks after an object is first created" do
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 "allow you to define nested auto_eval declarations" do
27
+ specify "allows you to define nested auto_eval declarations" do
28
28
  A::B::C::D.should == true
29
29
  end
30
30
 
@@ -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 should" do
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 "allow you to load a file to define a const" do
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 "should raise a NameError if a const doesn't match" do
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
@@ -1,5 +1,5 @@
1
1
  require 'rubygems'
2
- %w{ bacon metaid }.each { |dep| require dep }
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 '../lib/autocode'
15
+ require "#{File.dirname(__FILE__)}/../lib/autocode"
@@ -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.9.9
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-05-18 00:00:00 -07:00
14
+ date: 2008-06-09 00:00:00 -05:00
13
15
  default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
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: