td-client 0.8.8 → 0.8.9
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +5 -0
- data/lib/td/client/api.rb +20 -0
- data/lib/td/client/version.rb +1 -1
- data/spec/api_spec.rb +72 -0
- data/spec/spec_helper.rb +11 -0
- metadata +21 -7
data/ChangeLog
CHANGED
data/lib/td/client/api.rb
CHANGED
@@ -91,6 +91,26 @@ class API
|
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
|
+
def self.normalize_database_name(name)
|
95
|
+
name = name.to_s
|
96
|
+
if name.empty?
|
97
|
+
raise "Empty name is not allowed"
|
98
|
+
end
|
99
|
+
if name.length < 3
|
100
|
+
name += "_"*(3-name.length)
|
101
|
+
end
|
102
|
+
if 32 < name.length
|
103
|
+
name = name[0,30]+"__"
|
104
|
+
end
|
105
|
+
name = name.downcase
|
106
|
+
name = name.gsub(/[^a-z0-9_]/, '_')
|
107
|
+
name
|
108
|
+
end
|
109
|
+
|
110
|
+
def self.normalize_table_name(name)
|
111
|
+
normalize_database_name(name)
|
112
|
+
end
|
113
|
+
|
94
114
|
# TODO support array types
|
95
115
|
def self.normalize_type_name(name)
|
96
116
|
case name
|
data/lib/td/client/version.rb
CHANGED
data/spec/api_spec.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe API do
|
4
|
+
VALID_NAMES = [
|
5
|
+
'abc',
|
6
|
+
'abc_cd',
|
7
|
+
'_abc_cd',
|
8
|
+
'_abc_',
|
9
|
+
'ab0_',
|
10
|
+
'ab0',
|
11
|
+
]
|
12
|
+
|
13
|
+
INVALID_NAMES = {
|
14
|
+
'a' => 'a__',
|
15
|
+
'a'*33 => 'a'*30+'__',
|
16
|
+
'abcD' => 'abcd',
|
17
|
+
'a-b*' => 'a_b_',
|
18
|
+
}
|
19
|
+
|
20
|
+
it 'normalize_database_name should return normalized data' do
|
21
|
+
INVALID_NAMES.each_pair {|ng,ok|
|
22
|
+
API.normalize_database_name(ng).should == ok
|
23
|
+
}
|
24
|
+
lambda {
|
25
|
+
API.normalize_database_name('')
|
26
|
+
}.should raise_error(RuntimeError)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'normalize_table_name should return normalized data' do
|
30
|
+
INVALID_NAMES.each_pair {|ng,ok|
|
31
|
+
API.normalize_table_name(ng).should == ok
|
32
|
+
}
|
33
|
+
lambda {
|
34
|
+
API.normalize_table_name('')
|
35
|
+
}.should raise_error(RuntimeError)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'validate_database_name should raise errors' do
|
39
|
+
INVALID_NAMES.each_pair {|ng,ok|
|
40
|
+
lambda {
|
41
|
+
API.validate_database_name(ng)
|
42
|
+
}.should raise_error(RuntimeError)
|
43
|
+
}
|
44
|
+
lambda {
|
45
|
+
API.validate_database_name('')
|
46
|
+
}.should raise_error(RuntimeError)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'validate_table_name should raise errors' do
|
50
|
+
INVALID_NAMES.each_pair {|ng,ok|
|
51
|
+
lambda {
|
52
|
+
API.validate_table_name(ng)
|
53
|
+
}.should raise_error(RuntimeError)
|
54
|
+
}
|
55
|
+
lambda {
|
56
|
+
API.validate_table_name('')
|
57
|
+
}.should raise_error(RuntimeError)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'normalize_database_name should return valid data' do
|
61
|
+
VALID_NAMES.each {|ok|
|
62
|
+
API.normalize_database_name(ok).should == ok
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'validate_database_name should return valid data' do
|
67
|
+
VALID_NAMES.each {|ok|
|
68
|
+
API.validate_database_name(ok)
|
69
|
+
}
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: td-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-14 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: msgpack
|
16
|
-
requirement: &
|
16
|
+
requirement: &70135893795480 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.4.4
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70135893795480
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: json
|
27
|
-
requirement: &
|
27
|
+
requirement: &70135893794220 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,18 @@ dependencies:
|
|
32
32
|
version: 1.4.3
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70135893794220
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
requirement: &70135893792760 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.8.0
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70135893792760
|
36
47
|
description:
|
37
48
|
email:
|
38
49
|
executables: []
|
@@ -46,6 +57,8 @@ files:
|
|
46
57
|
- lib/td/client/api.rb
|
47
58
|
- lib/td/client/model.rb
|
48
59
|
- lib/td/client/version.rb
|
60
|
+
- spec/api_spec.rb
|
61
|
+
- spec/spec_helper.rb
|
49
62
|
- ChangeLog
|
50
63
|
- README.rdoc
|
51
64
|
homepage:
|
@@ -72,4 +85,5 @@ rubygems_version: 1.8.12
|
|
72
85
|
signing_key:
|
73
86
|
specification_version: 3
|
74
87
|
summary: Treasure Data API library for Ruby
|
75
|
-
test_files:
|
88
|
+
test_files:
|
89
|
+
- spec/api_spec.rb
|