anbt-sql-formatter 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@ require "anbt-sql-formatter/version"
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "anbt-sql-formatter"
7
7
  s.version = Anbt::Sql::Formatter::VERSION
8
- s.authors = ["sonota"]
8
+ s.authors = ["sonota88"]
9
9
  s.email = ["yosiot8753@gmail.com"]
10
10
  s.homepage = ""
11
11
  s.summary = %q{A tool for SQL formatting written in Ruby.}
@@ -1,4 +1,4 @@
1
- #! /usr/bin/ruby1.8
1
+ #! /usr/bin/env ruby
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
4
  begin
@@ -22,7 +22,7 @@ class AnbtSql
22
22
  end
23
23
 
24
24
 
25
- def split_by_semicolon(tokens)
25
+ def split_to_statements(tokens)
26
26
  statements = []
27
27
  buf = []
28
28
  tokens.each{|token|
@@ -48,14 +48,14 @@ class AnbtSql
48
48
  def format(sql_str)
49
49
  @function_bracket.clear()
50
50
  begin
51
- isSqlEndsWithNewLine = false
51
+ is_sql_ends_with_new_line = false
52
52
  if sql_str.end_with?("\n")
53
- isSqlEndsWithNewLine = true
53
+ is_sql_ends_with_new_line = true
54
54
  end
55
55
 
56
56
  tokens = @parser.parse(sql_str)
57
57
 
58
- statements = split_by_semicolon(tokens)
58
+ statements = split_to_statements(tokens)
59
59
 
60
60
  statements = statements.map{|tokens|
61
61
  format_list(tokens)
@@ -66,7 +66,7 @@ class AnbtSql
66
66
  tokens.map{ |t| t.string }.join("")
67
67
  }.join("\n;\n\n").sub( /\n\n\Z/, "" )
68
68
 
69
- after += "\n" if isSqlEndsWithNewLine
69
+ after += "\n" if is_sql_ends_with_new_line
70
70
 
71
71
  return after
72
72
  rescue => e
@@ -112,19 +112,19 @@ class AnbtSql
112
112
 
113
113
 
114
114
  def remove_symbol_side_space(tokens)
115
- prevToken = nil
115
+ prev_token = nil
116
116
 
117
117
  (tokens.size - 1).downto(1){|index|
118
118
  token = ArrayUtil.get(tokens, index)
119
- prevToken = ArrayUtil.get(tokens, index - 1)
119
+ prev_token = ArrayUtil.get(tokens, index - 1)
120
120
 
121
121
  if (token._type == AnbtSql::TokenConstants::SPACE &&
122
- (prevToken._type == AnbtSql::TokenConstants::SYMBOL ||
123
- prevToken._type == AnbtSql::TokenConstants::COMMENT))
122
+ (prev_token._type == AnbtSql::TokenConstants::SYMBOL ||
123
+ prev_token._type == AnbtSql::TokenConstants::COMMENT))
124
124
  ArrayUtil.remove(tokens, index)
125
125
  elsif ((token._type == AnbtSql::TokenConstants::SYMBOL ||
126
126
  token._type == AnbtSql::TokenConstants::COMMENT) &&
127
- prevToken._type == AnbtSql::TokenConstants::SPACE)
127
+ prev_token._type == AnbtSql::TokenConstants::SPACE)
128
128
  ArrayUtil.remove(tokens, index - 1)
129
129
  elsif (token._type == AnbtSql::TokenConstants::SPACE)
130
130
  token.string = " "
@@ -259,15 +259,15 @@ class AnbtSql
259
259
  end
260
260
 
261
261
  if equals_ignore_case(token.string, "BETWEEN")
262
- encounterBetween = true
262
+ encounter_between = true
263
263
  end
264
264
 
265
265
  if equals_ignore_case(token.string, "AND")
266
266
  # BETWEEN のあとのANDは改行しない。
267
- if not encounterBetween
267
+ if not encounter_between
268
268
  index += insert_return_and_indent(tokens, index, indent)
269
269
  end
270
- encounterBetween = false
270
+ encounter_between = false
271
271
  end
272
272
 
273
273
  elsif (token._type == AnbtSql::TokenConstants::COMMENT) # ****
@@ -337,7 +337,7 @@ class AnbtSql
337
337
  remove_symbol_side_space(tokens)
338
338
  concat_operator_for_oracle(tokens)
339
339
 
340
- encounterBetween = false
340
+ encounter_between = false
341
341
 
342
342
  format_list_main_loop(tokens)
343
343
 
@@ -1,7 +1,7 @@
1
1
  module Anbt
2
2
  module Sql
3
3
  module Formatter
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.3"
5
5
  end
6
6
  end
7
7
  end
@@ -500,8 +500,8 @@ class TestAnbtSqlFormatter < Test::Unit::TestCase
500
500
  end
501
501
 
502
502
 
503
- def test_split_by_semicolon
504
- msg = "split_by_semicolon - "
503
+ def test_split_to_statements
504
+ msg = "split_to_statements - "
505
505
 
506
506
  ########
507
507
  tokens = @parser.parse("a;b")
@@ -509,17 +509,17 @@ class TestAnbtSqlFormatter < Test::Unit::TestCase
509
509
  assert_equals(
510
510
  msg + "first statement",
511
511
  "a",
512
- @fmt.split_by_semicolon(tokens)[0][0].string
512
+ @fmt.split_to_statements(tokens)[0][0].string
513
513
  )
514
514
  assert_equals(
515
515
  msg + "second statement",
516
516
  "b",
517
- @fmt.split_by_semicolon(tokens)[1][0].string
517
+ @fmt.split_to_statements(tokens)[1][0].string
518
518
  )
519
519
 
520
520
  ########
521
521
  tokens = @parser.parse(";")
522
- statements = @fmt.split_by_semicolon(tokens)
522
+ statements = @fmt.split_to_statements(tokens)
523
523
  assert_equals(
524
524
  msg,
525
525
  [],
@@ -533,7 +533,7 @@ class TestAnbtSqlFormatter < Test::Unit::TestCase
533
533
 
534
534
  ########
535
535
  tokens = @parser.parse("a;")
536
- statements = @fmt.split_by_semicolon(tokens)
536
+ statements = @fmt.split_to_statements(tokens)
537
537
  assert_equals(
538
538
  msg,
539
539
  "name (a)",
@@ -547,7 +547,7 @@ class TestAnbtSqlFormatter < Test::Unit::TestCase
547
547
 
548
548
  ########
549
549
  tokens = @parser.parse(";a")
550
- statements = @fmt.split_by_semicolon(tokens)
550
+ statements = @fmt.split_to_statements(tokens)
551
551
  assert_equals(
552
552
  msg,
553
553
  [],
@@ -561,7 +561,7 @@ class TestAnbtSqlFormatter < Test::Unit::TestCase
561
561
 
562
562
  ########
563
563
  tokens = @parser.parse("a;b")
564
- statements = @fmt.split_by_semicolon(tokens)
564
+ statements = @fmt.split_to_statements(tokens)
565
565
  assert_equals(
566
566
  msg,
567
567
  "name (a)",
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anbt-sql-formatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
- - sonota
8
+ - sonota88
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-01-06 00:00:00.000000000 Z
12
+ date: 2015-02-14 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A tool for SQL formatting written in Ruby. Ruby port of Blanco SQL Formatter.
15
15
  email: