reactive_record 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTE3ZTY1ODk3NDRjYTBmMTc3OGNmOWVmNWNhYzNmYjJiZGI1NzFiYw==
4
+ ZDg0ZjdmNjhkNmJmYTE2OWQ0ODFkMzkwYmNiNmEwMjdkODY4NWZjOA==
5
5
  data.tar.gz: !binary |-
6
- ZWUzZjFmNzlkNzU1YmRiNWMwNDMxOTc0ODFiZGM3ZTg1N2RjNTI3NQ==
6
+ YmNkZjQ3OGVlZjJhNDM3MGQ0YmE0YmJmN2RkNGYzYmJiNjBlMDVkOA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MzY2ZWFkYTk5Y2VlNmYxMzhlYjQ2YTU1MjJiYTdiOGJhNzMzZmRmNGYwZTg2
10
- Y2U3YmI2MTQ1YmZlYmYyNzk2OGZhNWQ0MTQ4ZjViZTg1OTk5ZTY4ZWJiNTI5
11
- Y2I2OTc4YTE2MmE5YWM4YzFhNTZkY2ZjOTFjNGQzODIwZTQ4M2Y=
9
+ MDM2NDQxMDFiMTZlYjA2ZGM2ZDBlNjc1OTJhOWRhYTY4NTdjYzlhMDIxNTI5
10
+ N2NhYzJiZGIxMWFjMDJhOTJmNDZlOGZmOGFmYTNkNjQ0ODMyOTAxOTkwYmI1
11
+ ZGIzNTBiM2QxZjc0MWQ5OWJmOWVkYmI3NzkwNTE1MWE0NjkwNTA=
12
12
  data.tar.gz: !binary |-
13
- MGUzZDM1NTdhN2FmYzE2ZGYxMjMxZGVlYWNjNmRlYWNmZjk0YzhhMGFmNmY5
14
- NTBlZjRlYzkwNGU3ZTAwOTcxZWFmNDdhNjdmZTE3NDBmM2E0ZTFiNDNjMzMy
15
- NmRkYWUzMWYyZWUzMzBiNzcyNTVhM2RhNGI0YzUwNDhiNzdiMmU=
13
+ MTgzZTk5ZDNjODliZDhiZjAxN2ZkYmI0NzAwMjdhYmFmYjNlOThhOTVmZDM5
14
+ ZGUyZDQzZGQwNWFjODJmNWY3ZGRkYWJkMWZjYzk0MjhkOTVlNTJmYzgyMzA5
15
+ YWYzMjliMGExM2I5YTBjNWNhMTBlN2RmMzlkYzc3ZDliYzZlMjk=
data/.gitignore CHANGED
@@ -17,4 +17,3 @@ test/version_tmp
17
17
  tmp
18
18
  .ruby-version
19
19
  .ruby-gemset
20
- lib/parser.rb
data/README.md CHANGED
@@ -3,6 +3,8 @@
3
3
  alt="Reactive record logo">
4
4
  </p>
5
5
 
6
+ [![Gem Version](https://badge.fury.io/rb/reactive_record.png)](http://badge.fury.io/rb/reactive_record)
7
+
6
8
  Generates ActiveRecord models to fit a pre-existing Postgres database.
7
9
  Now you can use Rails with the db schema you always wanted. It's
8
10
  **your** convention over configuration.
@@ -156,6 +156,8 @@ class OperatorNode < Node
156
156
  MathExpr.new @value, @expr1, @expr2
157
157
  when :match
158
158
  MatchExpr.new @expr1, @expr2
159
+ when :and
160
+ AndExpr.new @expr1, @expr2
159
161
  end
160
162
  end
161
163
 
@@ -203,6 +205,16 @@ class ComparisonExpr
203
205
  end
204
206
  end
205
207
 
208
+ class AndExpr
209
+ def initialize e1, e2
210
+ @e1, @e2 = e1, e2
211
+ end
212
+
213
+ def gen
214
+ "#{@e1.gen} && #{@e2.gen}"
215
+ end
216
+ end
217
+
206
218
  class MathExpr
207
219
  def initialize op, e1, e2
208
220
  @e1, @e2 = e1, e2
@@ -2,6 +2,7 @@ require 'strscan'
2
2
 
3
3
  module ConstraintParser
4
4
  class Lexer
5
+ AND = /AND/
5
6
  CASCADE = /CASCADE/
6
7
  CHECK = /CHECK/
7
8
  COMMA = /,/
@@ -50,6 +51,7 @@ module ConstraintParser
50
51
  when text = @ss.scan(EQ) then [:EQ, text]
51
52
  when text = @ss.scan(PLUS) then [:PLUS, text]
52
53
  when text = @ss.scan(MATCH_OP) then [:MATCH_OP, text]
54
+ when text = @ss.scan(AND) then [:AND, text]
53
55
 
54
56
  # SQL Keywords
55
57
  when text = @ss.scan(CHECK) then [:CHECK, text]
@@ -0,0 +1,360 @@
1
+ #
2
+ # DO NOT MODIFY!!!!
3
+ # This file is automatically generated by Racc 1.4.9
4
+ # from Racc grammer file "".
5
+ #
6
+
7
+ require 'racc/parser.rb'
8
+ module ConstraintParser
9
+ class Parser < Racc::Parser
10
+
11
+
12
+ require 'lexer'
13
+ require 'code_generator'
14
+
15
+ def initialize tokenizer, handler = nil
16
+ @tokenizer = tokenizer
17
+ super()
18
+ end
19
+
20
+ def next_token
21
+ @tokenizer.next_token
22
+ end
23
+
24
+ def parse
25
+ do_parse
26
+ end
27
+ ##### State transition tables begin ###
28
+
29
+ racc_action_table = [
30
+ 27, 28, 21, 22, 23, 24, 25, 26, 29, 27,
31
+ 28, 21, 22, 23, 24, 25, 26, 29, 46, 12,
32
+ 14, 11, 12, 14, 11, 30, 36, 32, 6, 13,
33
+ 45, 7, 13, 33, 30, 27, 28, 21, 22, 23,
34
+ 24, 25, 26, 29, 5, 12, 14, 11, 16, 18,
35
+ 17, 9, 39, 40, 8, 13, 42, 37, 16, 44,
36
+ 30, 34 ]
37
+
38
+ racc_action_check = [
39
+ 10, 10, 10, 10, 10, 10, 10, 10, 10, 35,
40
+ 35, 35, 35, 35, 35, 35, 35, 35, 44, 11,
41
+ 11, 11, 20, 20, 20, 10, 30, 15, 0, 11,
42
+ 44, 0, 20, 16, 35, 31, 31, 31, 31, 31,
43
+ 31, 31, 31, 31, 0, 6, 6, 6, 7, 9,
44
+ 8, 5, 32, 33, 1, 6, 38, 31, 39, 42,
45
+ 31, 18 ]
46
+
47
+ racc_action_pointer = [
48
+ 16, 54, nil, nil, nil, 33, 29, 30, 50, 33,
49
+ -2, 3, nil, nil, nil, 5, 17, nil, 37, nil,
50
+ 6, nil, nil, nil, nil, nil, nil, nil, nil, nil,
51
+ 10, 33, 36, 29, nil, 7, nil, nil, 36, 40,
52
+ nil, nil, 45, nil, 7, nil, nil ]
53
+
54
+ racc_action_default = [
55
+ -29, -29, -1, -2, -3, -29, -6, -29, -29, -29,
56
+ -5, -6, -10, -11, -12, -29, -29, 47, -29, -8,
57
+ -6, -13, -14, -15, -16, -17, -18, -19, -20, -21,
58
+ -29, -29, -29, -29, -4, -9, -22, -7, -23, -29,
59
+ -25, -24, -29, -26, -29, -27, -28 ]
60
+
61
+ racc_goto_table = [
62
+ 15, 10, 1, 4, 3, 2, 31, 38, 41, nil,
63
+ nil, nil, nil, nil, nil, 35, nil, nil, nil, nil,
64
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
65
+ nil, nil, 43 ]
66
+
67
+ racc_goto_check = [
68
+ 8, 5, 1, 4, 3, 2, 5, 9, 10, nil,
69
+ nil, nil, nil, nil, nil, 5, nil, nil, nil, nil,
70
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
71
+ nil, nil, 8 ]
72
+
73
+ racc_goto_pointer = [
74
+ nil, 2, 5, 4, 3, -5, nil, nil, -7, -25,
75
+ -30 ]
76
+
77
+ racc_goto_default = [
78
+ nil, nil, nil, nil, nil, nil, 19, 20, nil, nil,
79
+ nil ]
80
+
81
+ racc_reduce_table = [
82
+ 0, 0, :racc_error,
83
+ 1, 30, :_reduce_1,
84
+ 1, 30, :_reduce_2,
85
+ 1, 30, :_reduce_3,
86
+ 4, 31, :_reduce_4,
87
+ 2, 32, :_reduce_5,
88
+ 0, 34, :_reduce_6,
89
+ 3, 34, :_reduce_7,
90
+ 2, 34, :_reduce_8,
91
+ 3, 34, :_reduce_9,
92
+ 1, 34, :_reduce_10,
93
+ 1, 34, :_reduce_11,
94
+ 1, 34, :_reduce_12,
95
+ 1, 36, :_reduce_13,
96
+ 1, 36, :_reduce_14,
97
+ 1, 36, :_reduce_15,
98
+ 1, 36, :_reduce_16,
99
+ 1, 36, :_reduce_17,
100
+ 1, 36, :_reduce_18,
101
+ 1, 36, :_reduce_19,
102
+ 1, 36, :_reduce_20,
103
+ 1, 36, :_reduce_21,
104
+ 2, 35, :_reduce_22,
105
+ 4, 33, :_reduce_23,
106
+ 5, 33, :_reduce_24,
107
+ 3, 37, :_reduce_25,
108
+ 2, 38, :_reduce_26,
109
+ 3, 39, :_reduce_27,
110
+ 3, 39, :_reduce_28 ]
111
+
112
+ racc_reduce_n = 29
113
+
114
+ racc_shift_n = 47
115
+
116
+ racc_token_table = {
117
+ false => 0,
118
+ :error => 1,
119
+ :PLUS => 2,
120
+ :MATCH_OP => 3,
121
+ :GTEQ => 4,
122
+ :LTEQ => 5,
123
+ :NEQ => 6,
124
+ :EQ => 7,
125
+ :GT => 8,
126
+ :LT => 9,
127
+ :AND => 10,
128
+ :CASCADE => 11,
129
+ :CHECK => 12,
130
+ :COMMA => 13,
131
+ :DELETE => 14,
132
+ :FOREIGN_KEY => 15,
133
+ :IDENT => 16,
134
+ :INT => 17,
135
+ :LPAREN => 18,
136
+ :NEWLINE => 19,
137
+ :ON => 20,
138
+ :PRIMARY_KEY => 21,
139
+ :REFERENCES => 22,
140
+ :RESTRICT => 23,
141
+ :RPAREN => 24,
142
+ :SPACE => 25,
143
+ :STRLIT => 26,
144
+ :TYPE => 27,
145
+ :UNIQUE => 28 }
146
+
147
+ racc_nt_base = 29
148
+
149
+ racc_use_result_var = true
150
+
151
+ Racc_arg = [
152
+ racc_action_table,
153
+ racc_action_check,
154
+ racc_action_default,
155
+ racc_action_pointer,
156
+ racc_goto_table,
157
+ racc_goto_check,
158
+ racc_goto_default,
159
+ racc_goto_pointer,
160
+ racc_nt_base,
161
+ racc_reduce_table,
162
+ racc_token_table,
163
+ racc_shift_n,
164
+ racc_reduce_n,
165
+ racc_use_result_var ]
166
+
167
+ Racc_token_to_s_table = [
168
+ "$end",
169
+ "error",
170
+ "PLUS",
171
+ "MATCH_OP",
172
+ "GTEQ",
173
+ "LTEQ",
174
+ "NEQ",
175
+ "EQ",
176
+ "GT",
177
+ "LT",
178
+ "AND",
179
+ "CASCADE",
180
+ "CHECK",
181
+ "COMMA",
182
+ "DELETE",
183
+ "FOREIGN_KEY",
184
+ "IDENT",
185
+ "INT",
186
+ "LPAREN",
187
+ "NEWLINE",
188
+ "ON",
189
+ "PRIMARY_KEY",
190
+ "REFERENCES",
191
+ "RESTRICT",
192
+ "RPAREN",
193
+ "SPACE",
194
+ "STRLIT",
195
+ "TYPE",
196
+ "UNIQUE",
197
+ "$start",
198
+ "constraint",
199
+ "unique_column",
200
+ "check_statement",
201
+ "foreign_key",
202
+ "expr",
203
+ "type_signature",
204
+ "operator",
205
+ "column_spec",
206
+ "table_spec",
207
+ "action_spec" ]
208
+
209
+ Racc_debug_parser = false
210
+
211
+ ##### State transition tables end #####
212
+
213
+ # reduce 0 omitted
214
+
215
+ def _reduce_1(val, _values, result)
216
+ result = val[0]
217
+ result
218
+ end
219
+
220
+ def _reduce_2(val, _values, result)
221
+ result = val[0]
222
+ result
223
+ end
224
+
225
+ def _reduce_3(val, _values, result)
226
+ result = val[0]
227
+ result
228
+ end
229
+
230
+ def _reduce_4(val, _values, result)
231
+ result = UniqueNode.new(IdentNode.new(val[2]))
232
+ result
233
+ end
234
+
235
+ def _reduce_5(val, _values, result)
236
+ result = CheckNode.new(val[1])
237
+ result
238
+ end
239
+
240
+ def _reduce_6(val, _values, result)
241
+ result = EmptyExprNode.new :empty
242
+ result
243
+ end
244
+
245
+ def _reduce_7(val, _values, result)
246
+ result = ExprNode.new(val[1])
247
+ result
248
+ end
249
+
250
+ def _reduce_8(val, _values, result)
251
+ result = TypedExprNode.new(val[0], val[1])
252
+ result
253
+ end
254
+
255
+ def _reduce_9(val, _values, result)
256
+ result = OperatorNode.new(val[1], val[0], val[2])
257
+ result
258
+ end
259
+
260
+ def _reduce_10(val, _values, result)
261
+ result = IdentNode.new(val[0])
262
+ result
263
+ end
264
+
265
+ def _reduce_11(val, _values, result)
266
+ result = StrLitNode.new(val[0])
267
+ result
268
+ end
269
+
270
+ def _reduce_12(val, _values, result)
271
+ result = IntNode.new(val[0])
272
+ result
273
+ end
274
+
275
+ def _reduce_13(val, _values, result)
276
+ result = :gteq
277
+ result
278
+ end
279
+
280
+ def _reduce_14(val, _values, result)
281
+ result = :lteq
282
+ result
283
+ end
284
+
285
+ def _reduce_15(val, _values, result)
286
+ result = :neq
287
+ result
288
+ end
289
+
290
+ def _reduce_16(val, _values, result)
291
+ result = :eq
292
+ result
293
+ end
294
+
295
+ def _reduce_17(val, _values, result)
296
+ result = :gt
297
+ result
298
+ end
299
+
300
+ def _reduce_18(val, _values, result)
301
+ result = :lt
302
+ result
303
+ end
304
+
305
+ def _reduce_19(val, _values, result)
306
+ result = :plus
307
+ result
308
+ end
309
+
310
+ def _reduce_20(val, _values, result)
311
+ result = :match
312
+ result
313
+ end
314
+
315
+ def _reduce_21(val, _values, result)
316
+ result = :and
317
+ result
318
+ end
319
+
320
+ def _reduce_22(val, _values, result)
321
+ result = IdentNode.new(val[1])
322
+ result
323
+ end
324
+
325
+ def _reduce_23(val, _values, result)
326
+ result = ForeignKeyNode.new(val[1], val[3])
327
+ result
328
+ end
329
+
330
+ def _reduce_24(val, _values, result)
331
+ result = ForeignKeyNode.new(val[1], val[3], val[4])
332
+ result
333
+ end
334
+
335
+ def _reduce_25(val, _values, result)
336
+ result = IdentNode.new(val[1])
337
+ result
338
+ end
339
+
340
+ def _reduce_26(val, _values, result)
341
+ result = TableNode.new(IdentNode.new(val[0]), val[1])
342
+ result
343
+ end
344
+
345
+ def _reduce_27(val, _values, result)
346
+ result = ActionNode.new(:delete, :restrict)
347
+ result
348
+ end
349
+
350
+ def _reduce_28(val, _values, result)
351
+ result = ActionNode.new(:delete, :cascade)
352
+ result
353
+ end
354
+
355
+ def _reduce_none(val, _values, result)
356
+ val[0]
357
+ end
358
+
359
+ end # class Parser
360
+ end # module ConstraintParser
@@ -4,7 +4,8 @@ prechigh
4
4
  left GTEQ LTEQ NEQ EQ GT LT
5
5
  preclow
6
6
 
7
- token CASCADE
7
+ token AND
8
+ CASCADE
8
9
  CHECK
9
10
  COMMA
10
11
  DELETE
@@ -59,6 +60,7 @@ rule
59
60
  | LT { result = :lt }
60
61
  | PLUS { result = :plus }
61
62
  | MATCH_OP { result = :match }
63
+ | AND { result = :and }
62
64
  ;
63
65
 
64
66
  type_signature : TYPE IDENT { result = IdentNode.new(val[1]) }
@@ -1,3 +1,3 @@
1
1
  module ReactiveRecord
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -13,7 +13,7 @@ Gem::Specification.new do |gem|
13
13
  gem.homepage = "https://github.com/twopoint718/reactive_record"
14
14
  gem.licenses = ['MIT']
15
15
 
16
- gem.files = [`git ls-files`.split($/), "lib/parser.rb"]
16
+ gem.files = `git ls-files`.split("\n")
17
17
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ["lib"]
@@ -142,4 +142,26 @@ describe ConstraintParser::Lexer do
142
142
  [:RPAREN, ')'],
143
143
  ]
144
144
  end
145
+ it "CHECK (((port >= 1024) AND (port <= 65634)))" do
146
+ @lex = lex.new StringIO.new "CHECK (((port >= 1024) AND (port <= 65634)))"
147
+ @lex.tokenize.should == [
148
+ [:CHECK, 'CHECK'],
149
+ [:LPAREN, '('],
150
+ [:LPAREN, '('],
151
+ [:LPAREN, '('],
152
+ [:IDENT, 'port'],
153
+ [:GTEQ, '>='],
154
+ [:INT, "1024"],
155
+ [:RPAREN, ')'],
156
+ [:AND, 'AND'],
157
+ [:LPAREN, '('],
158
+ [:IDENT, 'port'],
159
+ [:LTEQ, '<='],
160
+ [:INT, "65634"],
161
+ [:RPAREN, ')'],
162
+ [:RPAREN, ')'],
163
+ [:RPAREN, ')'],
164
+ ]
165
+ end
166
+
145
167
  end
@@ -32,6 +32,11 @@ describe ConstraintParser::Parser do
32
32
  @parser.parse.gen.should == 'validate { errors.add(:start_date, "Expected TODO") unless start_date <= Time.now.to_date + 365 }'
33
33
  end
34
34
 
35
+ it "CHECK (((port >= 1024) AND (port <= 65634)))" do
36
+ @parser = par.new(lex.new StringIO.new "CHECK (((port >= 1024) AND (port <= 65634)))")
37
+ @parser.parse.gen.should == 'validate { errors.add(:port, "Expected TODO") unless port >= 1024 && port <= 65634 }'
38
+ end
39
+
35
40
  it "FOREIGN KEY (employee_id) REFERENCES employees(employee_id) ON DELETE RESTRICT" do
36
41
  @parser = par.new(lex.new StringIO.new "FOREIGN KEY (employee_id) REFERENCES employees(employee_id) ON DELETE RESTRICT")
37
42
  @parser.parse.gen.should == "belongs_to :employees, foreign_key: 'employee_id', class: 'Employees', primary_key: 'employee_id'"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reactive_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Nelson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-20 00:00:00.000000000 Z
12
+ date: 2013-12-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pg
@@ -85,6 +85,7 @@ files:
85
85
  - lib/code_generator.rb
86
86
  - lib/generators/reactive_record/install_generator.rb
87
87
  - lib/lexer.rb
88
+ - lib/parser.rb
88
89
  - lib/parser.y
89
90
  - lib/reactive_record.rb
90
91
  - lib/reactive_record/version.rb
@@ -93,7 +94,6 @@ files:
93
94
  - spec/parser_spec.rb
94
95
  - spec/reactive_record_spec.rb
95
96
  - spec/seed/database.sql
96
- - lib/parser.rb
97
97
  homepage: https://github.com/twopoint718/reactive_record
98
98
  licenses:
99
99
  - MIT