ddl_parser 0.0.7 → 0.0.8

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ef82b48ea80076815061bcbf9796dfc705378cb8
4
- data.tar.gz: cc04e393d7673c5941164bf953b2a7e3256d536a
3
+ metadata.gz: 43e8f3aea2bd03ccdd4c2a7b1a0b2c325f7bee84
4
+ data.tar.gz: 2a21651fe9805d07d7f80f79a160cec065557297
5
5
  SHA512:
6
- metadata.gz: 8ba708dd93de83da7b45c1a207ded32c4640b6bb2da148feb9402aa0798a540aeda239591c65ff1559e71d4df502f0ac5a252e816751d5aed9a5290450d42883
7
- data.tar.gz: ac3de3daa335758e0f153d03f7f6bcc8943d755b0a0b18bf187cc4c7bb70d87f9d2c5eed0c5a492c6bb5fc017df754f637445cf57cdb16b8ca50b53091d53c64
6
+ metadata.gz: c6173cef6daad97465aac30304464b255d06955e88cbde966cdc940619cc2c653d2e872fdca48c534b2ac31678c35ad8697a025604eff2c2e0a2f49f51b75754
7
+ data.tar.gz: 10aa29aa0671fe7773d6b607c7b31fe1ffcb17dafa70ba49f9370e9f8fa89d6f7508692c4548a9d1ded2e5c6f8665671a28134fdbfa4dee367cdeaea366164e4
@@ -74,8 +74,8 @@ module DDLParser
74
74
  rule(:term) { const | item }
75
75
 
76
76
  rule(:function) {
77
- identifier.as(:function) >> space? >>
78
- lparen >> arglist.as(:arguments) >> rparen
77
+ (identifier.as(:name) >> space? >>
78
+ lparen >> arglist.as(:arguments) >> rparen).as(:function)
79
79
  }
80
80
 
81
81
  rule(:item) { function | identifier | string }
@@ -27,12 +27,12 @@ module DDLParser
27
27
 
28
28
 
29
29
  rule(:string) {
30
- str("'") >>
30
+ (str("'") >>
31
31
  (
32
32
  str('\\') >> any |
33
33
  str("'").absent? >> any
34
34
  ).repeat >>
35
- str("'")
35
+ str("'")).as(:string)
36
36
  }
37
37
 
38
38
  rule(:const) {
@@ -40,7 +40,7 @@ module DDLParser
40
40
  }
41
41
 
42
42
  rule(:identifier) { match('\\w').repeat(1) }
43
- rule(:current_timestamp) { str('current timestamp') }
43
+ rule(:current_timestamp) { str('current timestamp').as(:timestamp) }
44
44
 
45
45
  end
46
46
  end
@@ -67,11 +67,18 @@ class DDLParser::Translator::Column
67
67
  unless options.nil?
68
68
  default_value = options.select{|h|h.has_key?(:default_clause)}.first
69
69
  if default_value
70
- default_value[:default_clause].each do |c|
71
- # TODO must handle other then integer
72
- if c.has_key?(:integer)
73
- return c[:integer].to_i
70
+ if default_value[:default_clause].is_a?(Array)
71
+ default_value[:default_clause].each do |c|
72
+ # TODO must handle other then integer
73
+ case c.keys.first
74
+ when :integer
75
+ return c[:integer].to_i
76
+ else
77
+ return c[c.keys.first].to_s
78
+ end
74
79
  end
80
+ else
81
+ raise "Unknown default_clause #{default_value.inspect}"
75
82
  end
76
83
  end
77
84
  end
@@ -1,3 +1,3 @@
1
1
  module DDLParser
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
@@ -19,11 +19,11 @@ describe DDLParser::DDL::DB2::Parser do
19
19
  end
20
20
 
21
21
  it 'parses default values' do
22
- expect(parser.column_options).to parse('default 1')
23
- expect(parser.column_options).to parse('with default 1')
24
- expect(parser.column_options).to parse('default current timestamp')
25
- expect(parser.column_options).to parse("default 'foobar'")
26
- expect(parser.column_options).to parse('default max(foo)')
22
+ parser.column_options.parse('default 1').should == [{:default_clause=>[{:integer=> '1'}]}]
23
+ parser.column_options.parse('with default 1').should == [{:default_clause=>[{:integer=> '1'}]}]
24
+ parser.column_options.parse('default current timestamp').should == [{:default_clause=>[{:timestamp => "current timestamp"}]}]
25
+ parser.column_options.parse("default 'foobar'").should == [{:default_clause=>[{:string => "'foobar'"}]}]
26
+ parser.column_options.parse('default max(foo)').should == [{:default_clause=>[{:function=>{:name=>"max", :arguments=>{:item=>"foo"}}}]}]
27
27
 
28
28
  expect(
29
29
  parser.column_options.parse('default 1')
@@ -11,7 +11,8 @@ describe 'DDLParser::Translator::Column' do
11
11
  DDLParser::Translator::Column.new(
12
12
  {:field=> 'char_field',
13
13
  :data_type=>{:char=>{:length=>{:integer=> '4'}}},
14
- :options=> ''})
14
+ :options=> [{:default_clause=>[{:string => "'foobar'"}]}]}
15
+ )
15
16
  }
16
17
 
17
18
  let(:decimal_column) {
@@ -63,7 +64,7 @@ describe 'DDLParser::Translator::Column' do
63
64
 
64
65
  it 'should return options' do
65
66
  int_column.options.should == nil
66
- char_column.options.should == nil
67
+ char_column.options.should == [{:default_clause=>[{:string =>"'foobar'"}]}]
67
68
  decimal_column.options.should == [{:column_option=> 'not null'}, {:default_clause=>[{:integer=> '0'}]}]
68
69
  end
69
70
 
@@ -75,7 +76,7 @@ describe 'DDLParser::Translator::Column' do
75
76
 
76
77
  it 'should return default clause' do
77
78
  int_column.default_clause.should == nil
78
- char_column.default_clause.should == nil
79
+ char_column.default_clause.should == "'foobar'"
79
80
  decimal_column.default_clause.should == 0
80
81
  end
81
82
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ddl_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rasmus Bergholdt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-09 00:00:00.000000000 Z
11
+ date: 2014-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parslet