fixture_fox 0.2.5 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/fox.dsl.rb +42 -0
- data/lib/fixture_fox/analyzer.rb +9 -9
- 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 +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5d11738a008959b4da678a81352f3cf2d78c5a32dfcee362085cf9371b729ac
|
4
|
+
data.tar.gz: 7fc2a1f30a2b3f5a940e2454c9856e2979b71317559b1577955e2cae1b08348b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f34d0bf3301a95c14fc8666a86934c51e9ffc51de5016233a4567173731c1dd92827011db9b99225748dc0af26749246f177d52d98fa06df6b97989d5082cb22
|
7
|
+
data.tar.gz: 5df4eb70caa2e9e1f21bd018f7c30ce0d9c93b718b4c9796b28632c74f31ca2ef419441907496fe0fe079567305fa6d07abc94a23d2307f6bf2b905f1adb3afc
|
data/fox.dsl.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# En DSL implementation kan også løse problemet med ordinals med en simpel
|
4
|
+
# method med en tæller
|
5
|
+
|
6
|
+
record Users, :alice do
|
7
|
+
name "Alice", :alices_name # Label on value is possible syntax
|
8
|
+
age 20
|
9
|
+
groups [supers, users]
|
10
|
+
picture do
|
11
|
+
title "Picture of Alice"
|
12
|
+
blob "image.jpg"
|
13
|
+
end
|
14
|
+
role :alices_role do
|
15
|
+
name "Administrator"
|
16
|
+
active true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
record Users, :alice do # Merge with "alice" above
|
21
|
+
last_post ref(:alices_first_post)
|
22
|
+
end
|
23
|
+
|
24
|
+
record Blogs, :alices_blog do
|
25
|
+
user ref(:alice)
|
26
|
+
title "Alice's Blog"
|
27
|
+
end
|
28
|
+
|
29
|
+
table Roles do
|
30
|
+
record :user_role do
|
31
|
+
name "User"
|
32
|
+
active true
|
33
|
+
end
|
34
|
+
record :anon_role do
|
35
|
+
name "Anon"
|
36
|
+
active true
|
37
|
+
end
|
38
|
+
record do
|
39
|
+
name "RoleWithoutALabel"
|
40
|
+
active false
|
41
|
+
end
|
42
|
+
end
|
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,13 +174,13 @@ 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
|
183
|
-
f.value.error("Data type mismatch - expected #{klass}, got #{value.class}")
|
183
|
+
f.value.error("Data type mismatch - expected #{klass}, got #{value.class}: #{value.inspect}")
|
184
184
|
end
|
185
185
|
}
|
186
186
|
when AstReferenceMember
|
@@ -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
|
@@ -319,7 +319,7 @@ module FixtureFox
|
|
319
319
|
field.elements.each { |r|
|
320
320
|
record_id = r.is_a?(AstReferenceElement) ? r.referenced_anchor.id : r.id
|
321
321
|
idr.put(
|
322
|
-
record_table.schema.name, record_table.name,
|
322
|
+
record_table.schema.name, record_table.name,
|
323
323
|
record_id, record_column.that_link_column, record.id)
|
324
324
|
}
|
325
325
|
end
|
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.7
|
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-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|
@@ -217,6 +217,7 @@ files:
|
|
217
217
|
- examples/views.sql
|
218
218
|
- exe/fox
|
219
219
|
- fixture_fox.gemspec
|
220
|
+
- fox.dsl.rb
|
220
221
|
- lib/fixture_fox.rb
|
221
222
|
- lib/fixture_fox/analyzer.rb
|
222
223
|
- lib/fixture_fox/anchor.rb
|