kolla 0.0.2 → 0.0.3

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/kolla +1 -1
  3. data/lib/kolla/parser.rb +27 -7
  4. data/lib/kolla.rb +12 -9
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 132a825d42a4bea791e2e5e689d6d06ae3defd3d452ecf41220d9079e63ec475
4
- data.tar.gz: 8db516431150f3b81246d8042f4a8d7fe3a7cf0ede830d2374589a48ba1224af
3
+ metadata.gz: e9f49f3b572118301b672c4352947ca6cda45b9c174e8b846ec6e3707d5d5320
4
+ data.tar.gz: 70332827226bda106ebc84029a6fc5bf8ad076a9786f281f238ba6506ed8b25d
5
5
  SHA512:
6
- metadata.gz: 431e7bbeb1c5fcb61a13c3ef9007c19b7dafaede6228c5391ba102146f58adc00c867a7c26897887daee25cfe85e3568c2f8509f479ca9b936f0c360b5d9b189
7
- data.tar.gz: d6159da48b3f8e3e2ae794666313ac3a0e20d2e1609b70591fee854cca244bd858e095343f18435a6fbffb2677abffa5788e510978cdfabe71ea1df382b1d90c
6
+ metadata.gz: 975308aca1e8ebfb2442296ef663c2e4cf4ad9a2c4ba6e8abc37e1bfb8d12ac75c63aa94ca99c66e9d1a5ca0d40e255e4451280628594543083a00388c1b702b
7
+ data.tar.gz: ba2c479eb4e04f3347e3e8e919a9c330e1dd36d1586047ca2a819974960ac9559c46430ce1d6939ac21adc0deb8911ef6bd04af366eb2cfc27bad6dd2c88a749
data/bin/kolla CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'kolla'
4
- ARGV[0].nil? ? Kolla.run : Kolla.run(ARGV[0])
4
+ ARGV.empty? ? Kolla.run : Kolla.run(ARGV)
data/lib/kolla/parser.rb CHANGED
@@ -2,20 +2,40 @@
2
2
 
3
3
  module Kolla
4
4
  class Parser
5
- def initialize(file_path)
6
- @file_path = file_path
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 process
12
+ def run!
10
13
  content = File.read(file_path)
11
- matches = content.scan(/create_table\s+"(\w+)"/)
12
- matches.map(&:first).reject { |table| table.start_with?('action_', 'active_') }
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
- raise "Schema file_path not found at #{file_path}"
20
+ Kolla.logger.warn "Schema file_path not found at #{file_path}"
15
21
  end
16
22
 
17
23
  private
18
24
 
19
- attr_reader :file_path
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
- DEFAULT_FILE = 'db/schema.rb'
7
+ class << self
8
+ attr_accessor :logger
9
+ end
6
10
 
7
- def self.run(file_path = DEFAULT_FILE)
8
- absolute_path = File.expand_path(file_path)
11
+ self.logger = Logger.new($stdout)
9
12
 
10
- unless File.exist?(absolute_path)
11
- puts "File #{file_path} not found"
12
- return
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.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antony Sastre
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-02-03 00:00:00.000000000 Z
10
+ date: 2025-02-15 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  email: antony.sastre@gmail.com
13
13
  executables: