kolla 0.0.2 → 0.0.4
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 +4 -4
- data/bin/kolla +1 -1
- data/lib/kolla/parser.rb +27 -7
- data/lib/kolla.rb +12 -9
- 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: 80e3734cb140b8f92406cd59459951b530c430305f7e0c0a16d8ea6c9838df2a
|
4
|
+
data.tar.gz: 798b79b8a32747efb219b8941e8790d7291d7b775d6bbff3c3027df21cb57dd6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23077c2f3c679ba15337bd1c80564aaf7cf58fc6e063af7cd8bbb9477a1acaa5e12712c0164b79fb31cb519ba41b5f2b5c04f26e10d03ac56a834f0894514722
|
7
|
+
data.tar.gz: 86d20de4ec7f56e55278cc44cca232443684a816e1c59690f6597bf43a29990415b4cd225ecbc7f73afa79ace5878da751b954527fc640b758bb7cebc57ededd
|
data/bin/kolla
CHANGED
data/lib/kolla/parser.rb
CHANGED
@@ -2,20 +2,40 @@
|
|
2
2
|
|
3
3
|
module Kolla
|
4
4
|
class Parser
|
5
|
-
|
6
|
-
|
5
|
+
DEFAULT_FILE = File.join('db', 'schema.rb').freeze
|
6
|
+
|
7
|
+
def initialize(file_path: DEFAULT_FILE, options: {})
|
8
|
+
@file_path = File.expand_path(file_path)
|
9
|
+
@options = options
|
7
10
|
end
|
8
11
|
|
9
|
-
def
|
12
|
+
def run!
|
10
13
|
content = File.read(file_path)
|
11
|
-
|
12
|
-
|
14
|
+
if options[:model_name]
|
15
|
+
extract_fields(content, options[:model_name])
|
16
|
+
else
|
17
|
+
extract_tables(content)
|
18
|
+
end
|
13
19
|
rescue Errno::ENOENT
|
14
|
-
|
20
|
+
Kolla.logger.warn "Schema file_path not found at #{file_path}"
|
15
21
|
end
|
16
22
|
|
17
23
|
private
|
18
24
|
|
19
|
-
|
25
|
+
def extract_tables(schema)
|
26
|
+
matches = schema.scan(/create_table\s+"(\w+)"/)
|
27
|
+
matches.map(&:first).reject { |table| table.start_with?('action_', 'active_') }
|
28
|
+
end
|
29
|
+
|
30
|
+
def extract_fields(schema, table_name)
|
31
|
+
table_regex = /create_table "#{table_name}".*?do \|t\|(.*?)end/m
|
32
|
+
match = schema.match(table_regex)
|
33
|
+
return [] unless match
|
34
|
+
|
35
|
+
field_regex = /t\.(\w+)\s+"(\w+)"/
|
36
|
+
match[1].scan(field_regex).map { |type, name| "#{name} (#{type})" }
|
37
|
+
end
|
38
|
+
|
39
|
+
attr_reader :file_path, :options
|
20
40
|
end
|
21
41
|
end
|
data/lib/kolla.rb
CHANGED
@@ -1,19 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'logger'
|
4
|
+
|
3
5
|
# Kolla parses a file and reports matching results.
|
4
6
|
module Kolla
|
5
|
-
|
7
|
+
class << self
|
8
|
+
attr_accessor :logger
|
9
|
+
end
|
6
10
|
|
7
|
-
|
8
|
-
absolute_path = File.expand_path(file_path)
|
11
|
+
self.logger = Logger.new($stdout)
|
9
12
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
+
def self.run(args = [])
|
14
|
+
if !args[0].nil?
|
15
|
+
model_name = args[0]
|
16
|
+
puts Parser.new(options:{model_name:}).run!
|
17
|
+
else
|
18
|
+
puts Parser.new.run!
|
13
19
|
end
|
14
|
-
|
15
|
-
parser = Parser.new(absolute_path)
|
16
|
-
puts parser.process
|
17
20
|
end
|
18
21
|
end
|
19
22
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kolla
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Antony Sastre
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-02-
|
10
|
+
date: 2025-02-15 00:00:00.000000000 Z
|
11
11
|
dependencies: []
|
12
12
|
email: antony.sastre@gmail.com
|
13
13
|
executables:
|