fixture_fox 0.2.6 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fixture_fox/analyzer.rb +21 -15
- data/lib/fixture_fox/anchor.rb +1 -1
- data/lib/fixture_fox/hash_parser.rb +2 -2
- data/lib/fixture_fox/idr.rb +2 -2
- data/lib/fixture_fox/line.rb +8 -8
- data/lib/fixture_fox/parser.rb +4 -4
- data/lib/fixture_fox/tokenizer.rb +1 -1
- data/lib/fixture_fox/version.rb +1 -1
- data/lib/fixture_fox.rb +6 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d169cf91f6468fcd829b7edd7af5309c4a15ff17e7087d2a75609fa7ea97b606
|
4
|
+
data.tar.gz: 2d99e4c1329f4cde08ac5f808c593f5cc92d086db7f8fb8bb909932aa6a96f67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b4bee30d8d492878f68a511730e7dda92b9db40c9a4c3be68f4e5db0a14464a9879cb7d7c3d570dab3c849352decb45df6e8f6441ae5dea8eb238ee1c7450ac
|
7
|
+
data.tar.gz: b33f654ff11fd0935c49f83492829d010dd035dfaf2034229c16272d5610a2127fd097c0fe2cd60cf9234755ac1edb6b2992e455a3fa34b9fb8bdd6c2869f15f
|
data/lib/fixture_fox/analyzer.rb
CHANGED
@@ -108,7 +108,7 @@ module FixtureFox
|
|
108
108
|
ast.tables.each { |ast_table|
|
109
109
|
@type.key?(ast_table.schema.value.downcase) or
|
110
110
|
ast_table.schema.error("Can't find schema '#{ast_table.schema}'")
|
111
|
-
type = ast_table.type = @type[ast_table.schema.value.downcase][ast_table.name.downcase] or
|
111
|
+
type = ast_table.type = @type[ast_table.schema.value.downcase][ast_table.name.downcase] or
|
112
112
|
ast_table.ident.error(
|
113
113
|
"Can't find ast_table '#{ast_table.ident}' (maybe you forgot to declare a schema?)")
|
114
114
|
@tables[type.uid] = type
|
@@ -136,7 +136,7 @@ module FixtureFox
|
|
136
136
|
|
137
137
|
def assign_field_types(ast_record)
|
138
138
|
ast_record.members.each { |field|
|
139
|
-
field.column = ast_record.type[field.ident.litt.downcase] or
|
139
|
+
field.column = ast_record.type[field.ident.litt.downcase] or
|
140
140
|
field.ident.error("Can't find field '#{ast_record.type.table.name}.#{field.ident}'")
|
141
141
|
field.type = field.column.type
|
142
142
|
case field
|
@@ -174,9 +174,9 @@ module FixtureFox
|
|
174
174
|
end
|
175
175
|
|
176
176
|
values.each { |value|
|
177
|
-
if value.is_a?(klass) || !f.type.array? &&
|
178
|
-
klass == Time &&
|
179
|
-
value.is_a?(String) &&
|
177
|
+
if value.is_a?(klass) || !f.type.array? &&
|
178
|
+
(klass == Time || klass == Date) &&
|
179
|
+
value.is_a?(String) &&
|
180
180
|
value =~ /^\d\d\d\d-\d\d-\d\d(?: \d\d:\d\d(?::\d\d)?)?$/
|
181
181
|
;
|
182
182
|
else
|
@@ -192,9 +192,9 @@ module FixtureFox
|
|
192
192
|
end
|
193
193
|
|
194
194
|
def check_ref(ast_ref)
|
195
|
-
anchor = ast_ref.referenced_anchor = @anchors[ast_ref.reference.value.to_sym] or
|
195
|
+
anchor = ast_ref.referenced_anchor = @anchors[ast_ref.reference.value.to_sym] or
|
196
196
|
ast_ref.reference.error("Can't find anchor for reference '#{ast_ref.reference.litt}'")
|
197
|
-
anchor_types =
|
197
|
+
anchor_types =
|
198
198
|
[anchor.type] +
|
199
199
|
(anchor.type.table.sub_table? ? [anchor.type.table.super_table.record_type] : [])
|
200
200
|
anchor_types.any? { |anchor_type| ast_ref.type == anchor_type } or
|
@@ -211,8 +211,6 @@ module FixtureFox
|
|
211
211
|
end
|
212
212
|
|
213
213
|
def generate_record_ids
|
214
|
-
# puts "generate_record_ids"
|
215
|
-
# puts " ids: #{@ids}"
|
216
214
|
@super_table_records = [] # Array of pairs of super_table/id
|
217
215
|
records.each { |ast_record|
|
218
216
|
table = ast_record.type.table
|
@@ -270,19 +268,17 @@ module FixtureFox
|
|
270
268
|
records.each { |record|
|
271
269
|
record.members.each { |field|
|
272
270
|
table = nil # To bring table into scope. FIXME: Yt?
|
271
|
+
# puts "#{field.class}"
|
273
272
|
case field
|
274
273
|
when AstFieldMember
|
275
|
-
# puts "AstFieldMember: #{field}"
|
276
274
|
table = record.type.table
|
277
275
|
column = field.column.postgres_column
|
278
276
|
idr.put(table.schema.name, table.name, record.id, column, field.value.value)
|
279
277
|
when AstReferenceMember
|
280
|
-
# puts "AstReferenceMember: #{field}"
|
281
278
|
table = record.type.table
|
282
279
|
column = field.column.postgres_column
|
283
280
|
idr.put(table.schema.name, table.name, record.id, column, field.referenced_anchor.id)
|
284
281
|
when AstRecordMember
|
285
|
-
# puts "AstRecordMember: #{record.type}"
|
286
282
|
column = field.column
|
287
283
|
|
288
284
|
this_record_id = field.record.id
|
@@ -300,7 +296,6 @@ module FixtureFox
|
|
300
296
|
idr.put(schema.name, table.name, that_record_id, link_column, this_record_id)
|
301
297
|
end
|
302
298
|
when AstTableMember
|
303
|
-
# puts "AstTableMember: #{field}"
|
304
299
|
if field.column.is_a?(PgGraph::Type::MmTableColumn)
|
305
300
|
table = mm_table = field.column.mm_table
|
306
301
|
this_mm_column = field.column.this_mm_column
|
@@ -316,11 +311,22 @@ module FixtureFox
|
|
316
311
|
else
|
317
312
|
table = record_table = field.column.type.table
|
318
313
|
record_column = field.column
|
314
|
+
|
319
315
|
field.elements.each { |r|
|
320
316
|
record_id = r.is_a?(AstReferenceElement) ? r.referenced_anchor.id : r.id
|
317
|
+
if record_table[record_column.that_link_column].kind?
|
318
|
+
key_schema_name = record_column.table.schema.name
|
319
|
+
key_table_name = record_column.table.name
|
320
|
+
key_record_id = record.id
|
321
|
+
key_field = record_column.this_link_column.to_sym
|
322
|
+
key = idr.data[key_schema_name][key_table_name][key_record_id][key_field]
|
323
|
+
else
|
324
|
+
key = record.id
|
325
|
+
end
|
326
|
+
|
321
327
|
idr.put(
|
322
|
-
record_table.schema.name, record_table.name,
|
323
|
-
record_id, record_column.that_link_column,
|
328
|
+
record_table.schema.name, record_table.name,
|
329
|
+
record_id, record_column.that_link_column, key)
|
324
330
|
}
|
325
331
|
end
|
326
332
|
else
|
data/lib/fixture_fox/anchor.rb
CHANGED
@@ -45,7 +45,7 @@ module FixtureFox
|
|
45
45
|
constrain arg, PgGraph::Type::RecordType, String
|
46
46
|
constrain id, NilClass, Integer # id is initially nil for anchors declared in the source
|
47
47
|
!@anchors.key?(name) or raise Error, "Duplicate anchor: #{name.inspect}"
|
48
|
-
type =
|
48
|
+
type =
|
49
49
|
case arg
|
50
50
|
when PgGraph::Type::RecordType; arg
|
51
51
|
when String; @type.dot(arg) or raise Error, "Illegal path: #{path.inspect}"
|
@@ -38,7 +38,7 @@ private
|
|
38
38
|
value = extract_value
|
39
39
|
[key.to_sym, value]
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
def extract_key
|
43
43
|
key = ""
|
44
44
|
while @i < @s.size && @s[@i] =~ /\w/
|
@@ -104,7 +104,7 @@ private
|
|
104
104
|
else
|
105
105
|
litt.strip
|
106
106
|
end
|
107
|
-
value
|
107
|
+
value
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
data/lib/fixture_fox/idr.rb
CHANGED
@@ -9,7 +9,7 @@ module FixtureFox
|
|
9
9
|
# List of materialized views that depends on the tables. Assigned by the analyzer
|
10
10
|
# FIXME: Is this in use?
|
11
11
|
attr_accessor :materialized_views
|
12
|
-
|
12
|
+
|
13
13
|
# Data as a hash from schema to table to id to record to field to value.
|
14
14
|
# Ie. { "schema" => { "table" => { 1 => { id: 1, name: "Alice" } } } }
|
15
15
|
attr_reader :data
|
@@ -49,7 +49,7 @@ module FixtureFox
|
|
49
49
|
def dump
|
50
50
|
data.sort_by(&:first).each { |schema, tables|
|
51
51
|
puts schema
|
52
|
-
tables.each { |table, records|
|
52
|
+
tables.each { |table, records|
|
53
53
|
puts " #{table}"
|
54
54
|
records.each { |id, fields|
|
55
55
|
puts " #{fields.inspect}"
|
data/lib/fixture_fox/line.rb
CHANGED
@@ -88,11 +88,11 @@ module FixtureFox
|
|
88
88
|
end
|
89
89
|
|
90
90
|
class Line < TokenizedLine
|
91
|
-
attr_reader :dash
|
91
|
+
attr_reader :dash
|
92
92
|
attr_reader :ident
|
93
93
|
attr_reader :empty # Empty token
|
94
|
-
attr_reader :value
|
95
|
-
attr_reader :reference
|
94
|
+
attr_reader :value
|
95
|
+
attr_reader :reference
|
96
96
|
attr_reader :anchor
|
97
97
|
|
98
98
|
attr_reader :directive # SchemaDirective token
|
@@ -143,7 +143,7 @@ module FixtureFox
|
|
143
143
|
error "Illegal character after '-'"
|
144
144
|
end
|
145
145
|
|
146
|
-
# Expect key/value pair
|
146
|
+
# Expect key/value pair
|
147
147
|
case line
|
148
148
|
when /^(\w+)(\s*):\s*$/ # Record
|
149
149
|
@ident = make_ident($1)
|
@@ -197,15 +197,15 @@ module FixtureFox
|
|
197
197
|
def to_s(long: false)
|
198
198
|
super +
|
199
199
|
if long
|
200
|
-
[ dash && "dash:#{dash.pos}",
|
201
|
-
ident && "ident:#{ident.pos} #{ident.value}",
|
200
|
+
[ dash && "dash:#{dash.pos}",
|
201
|
+
ident && "ident:#{ident.pos} #{ident.value}",
|
202
202
|
value && "value:#{value.pos} #{value.value}",
|
203
203
|
reference && "reference:#{reference.pos} #{reference.value}",
|
204
204
|
anchor && "anchor:##{anchor.pos} #{anchor.value}"
|
205
205
|
]
|
206
206
|
else
|
207
|
-
[ dash && "dash",
|
208
|
-
ident && "ident: #{ident.to_s}",
|
207
|
+
[ dash && "dash",
|
208
|
+
ident && "ident: #{ident.to_s}",
|
209
209
|
value && "value: #{value.to_s}",
|
210
210
|
reference && "reference: #{reference.to_s}",
|
211
211
|
anchor && "anchor: #{anchor.to_s}"
|
data/lib/fixture_fox/parser.rb
CHANGED
@@ -8,7 +8,7 @@ module FixtureFox
|
|
8
8
|
attr_reader :anchor_files # Name of external anchor files from @anchors directive
|
9
9
|
|
10
10
|
def initialize(file, lines, schema: nil)
|
11
|
-
@file = file
|
11
|
+
@file = file
|
12
12
|
@lines = lines
|
13
13
|
@schema = schema || "public"
|
14
14
|
@anchor_files = []
|
@@ -18,7 +18,7 @@ module FixtureFox
|
|
18
18
|
@ast = ast || Ast.new(file)
|
19
19
|
|
20
20
|
# Current schema. The schema is initialized with a synthetic Ident token
|
21
|
-
# because the #analyzer needs a token to emit an error message if the
|
21
|
+
# because the #analyzer needs a token to emit an error message if the
|
22
22
|
# public schema doesn't exist
|
23
23
|
schema = Ident.new(file, 1, peek.initial_indent, 1, @schema)
|
24
24
|
|
@@ -86,14 +86,14 @@ module FixtureFox
|
|
86
86
|
include_file = include_path.to_s
|
87
87
|
else
|
88
88
|
including_dir = Pathname.new(file).expand_path.dirname
|
89
|
-
include_file =
|
89
|
+
include_file =
|
90
90
|
Pathname.new(including_dir.to_s + "/" + include_path.to_s)
|
91
91
|
.cleanpath
|
92
92
|
.relative_path_from(Pathname.getwd).to_s
|
93
93
|
end
|
94
94
|
tokenizer = Tokenizer.new(include_file)
|
95
95
|
Parser.new(tokenizer.file, tokenizer.call).call(@ast)
|
96
|
-
end
|
96
|
+
end
|
97
97
|
|
98
98
|
# Parse table elements. Current line should be the first element
|
99
99
|
def parse_elements(table)
|
data/lib/fixture_fox/version.rb
CHANGED
data/lib/fixture_fox.rb
CHANGED
@@ -22,7 +22,7 @@ module FixtureFox
|
|
22
22
|
attr_reader :type
|
23
23
|
|
24
24
|
# Name of first source file
|
25
|
-
attr_reader :file
|
25
|
+
attr_reader :file
|
26
26
|
|
27
27
|
# Names of all source files except included files. FIXME: Not maintained - always []
|
28
28
|
attr_reader :files
|
@@ -43,8 +43,8 @@ module FixtureFox
|
|
43
43
|
def idr() @idr || generate end
|
44
44
|
|
45
45
|
# List of tables with records (PgGraph::Type::Table)
|
46
|
-
def tables()
|
47
|
-
@analyzer.data_tables
|
46
|
+
def tables()
|
47
|
+
@analyzer.data_tables
|
48
48
|
end
|
49
49
|
|
50
50
|
# Default schema. Defaults to "public"
|
@@ -60,12 +60,12 @@ module FixtureFox
|
|
60
60
|
|
61
61
|
# List of anchors defined by the sources
|
62
62
|
def defined_anchors()
|
63
|
-
@analyzer.defined_anchors.values
|
63
|
+
@analyzer.defined_anchors.values
|
64
64
|
end
|
65
65
|
|
66
66
|
# List of external anchors referenced by the sources. FIXME: Unused
|
67
|
-
def referenced_anchors()
|
68
|
-
@analyzer.referenced_anchors.values
|
67
|
+
def referenced_anchors()
|
68
|
+
@analyzer.referenced_anchors.values
|
69
69
|
end
|
70
70
|
|
71
71
|
def parsed?() !@ast.nil? end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fixture_fox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Claus Rasmussen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|