confetti 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- confetti (0.2.5)
4
+ confetti (0.2.6)
5
5
  mustache (= 0.11.2)
6
6
  thor (= 0.14.3)
7
7
 
@@ -15,11 +15,7 @@ module Confetti
15
15
  }
16
16
 
17
17
  def package_name
18
- if @config
19
- if is_java_package_id(@config.package)
20
- @config.package
21
- end
22
- end
18
+ convert_to_java_package_id(@config.package)
23
19
  end
24
20
 
25
21
  def class_name
@@ -6,7 +6,10 @@ module Confetti
6
6
  end
7
7
 
8
8
  def convert_to_java_identifier(str)
9
- str.sub(/^\d/,"_").gsub(/\s/,"").gsub(/[^a-zA-Z0-9_]/,"_")
9
+ str.
10
+ sub(/^\d/,"_").
11
+ gsub(/\s/,"").
12
+ gsub(/[^a-zA-Z0-9_]/,"_")
10
13
  end
11
14
 
12
15
  def is_java_package_id(str)
@@ -15,6 +18,19 @@ module Confetti
15
18
  # second param to #split ensures can't be dot-terminated
16
19
  components.length > 1 and components.all? { |s| is_java_identifier(s) }
17
20
  end
21
+
22
+ def convert_to_java_package_id(str)
23
+ return str if is_java_package_id(str)
24
+
25
+ bits = str.split('.', -1)
26
+ fixed_bits = bits.reject {|cmp| cmp.empty? }.map do |cmp|
27
+ convert_to_java_identifier(cmp)
28
+ end
29
+
30
+ fixed_bits.unshift('com') if fixed_bits.length == 1
31
+
32
+ fixed_bits.join('.')
33
+ end
18
34
  end
19
35
  end
20
36
  end
@@ -1,3 +1,3 @@
1
1
  module Confetti
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.6"
3
3
  end
@@ -59,5 +59,34 @@ describe Confetti::Template::JavaChecks do
59
59
  it "should not accept a single java identifier" do
60
60
  is_java_package_id("a27a4").should be_false
61
61
  end
62
+
63
+ it "should not accept a package with hypens in there" do
64
+ is_java_package_id("com.makalumedia.rock-am-ring").should be_false
65
+ end
66
+ end
67
+
68
+ describe "#convert_to_java_package_id" do
69
+ it "should not affect a valid package id" do
70
+ pkg = "com.alunny.foo"
71
+ convert_to_java_package_id(pkg).should == pkg
72
+ end
73
+
74
+ it "should strip out incorrect characters" do
75
+ pkg = "com.makalumedia.rock-am-ring"
76
+ fixed_pkg = "com.makalumedia.rock_am_ring"
77
+ convert_to_java_package_id(pkg).should == fixed_pkg
78
+ end
79
+
80
+ it "should strip out leading dots" do
81
+ pkg = ".com.alunny.foo"
82
+ fixed_pkg = "com.alunny.foo"
83
+ convert_to_java_package_id(pkg).should == fixed_pkg
84
+ end
85
+
86
+ it "should make sense of terrible identifiers" do
87
+ pkg = "http://BestBusU"
88
+ fixed_pkg = "com.http___BestBusU"
89
+ convert_to_java_package_id(pkg).should == fixed_pkg
90
+ end
62
91
  end
63
92
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: confetti
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 5
10
- version: 0.2.5
9
+ - 6
10
+ version: 0.2.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andrew Lunny
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-20 00:00:00 -07:00
18
+ date: 2011-05-24 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency