tina4ruby 3.13.125 → 3.13.126

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b117f25af22a6186fdba82880a24d055a80558f7273d239b9c7478e51b9393d
4
- data.tar.gz: 0bfb76f6503a503bf19be89cdcf16959a77ffc4d11784f4a519628945e38d4cd
3
+ metadata.gz: f56bea80e9f63a3326a77f8903721890f45a2db216f39c24fe51c1363e0514b9
4
+ data.tar.gz: 61dd38932bcfb406abb603232dd584889223408888d3ca7aaa469775243727b7
5
5
  SHA512:
6
- metadata.gz: abb84fe5bc77b49b53ef8b6d6ef5139782a5bed7103f88377329a56ef07a376ba3003aecf6d9d3fdd4de4c073ef306b7c467e982acaa6bb451f308e7cf70f13b
7
- data.tar.gz: 8c760af751f9b0eaee5f659bc90ca5f78505d93b343f89dcdb786fc8404e6376d49800ed05ca39e1c6fa7047d3ed9f0fb0b79480898804d98f1c672893b129c4
6
+ metadata.gz: d6ca97a0dcb6adf6776f89be49871d814b678a3d499d8ec740a6b87516af474f04d1e78d2c8746a113aa8877c2b3fcceec4ebd2f9d3cc02b2f4fd0accc63d095
7
+ data.tar.gz: 5c86231d8853e00c5cbbdf22a6ea02d477eed2fe045306c498ed1b82eff9ba5bc9c1e301b53f99a394f82731001c56503615206d566e2266b6e4208c2d64aecb
@@ -1385,7 +1385,9 @@ module Tina4
1385
1385
  # the closure, not a dead keyword.
1386
1386
  fake = Tina4::FakeData.new(seed: seed)
1387
1387
  field_map = Tina4._normalize_columns(db.columns(table_name)).each_with_object({}) do |(col_name, type_sym), map|
1388
- map[col_name] = -> { fake.for_field({ type: type_sym }, col_name) }
1388
+ # Thread the TABLE name so a generic name column on a product-ish
1389
+ # table seeds a product name (parity with the seed_table path).
1390
+ map[col_name] = -> { fake.for_field({ type: type_sym }, col_name, table_name) }
1389
1391
  end
1390
1392
  # Delegate to the shared resilient seed_table helper so the endpoint
1391
1393
  # gets the exact same per-row wrap (P1) — no unhandled row failure can
data/lib/tina4/seeder.rb CHANGED
@@ -108,6 +108,30 @@ module Tina4
108
108
  CURRENCIES = %w[USD EUR GBP JPY CAD AUD CHF ZAR INR CNY].freeze
109
109
  CREDIT_CARD_PREFIXES = %w[4111 4242 5500 5105].freeze
110
110
 
111
+ # Product-name vocabulary (adjective + noun). Seeds a generic
112
+ # +name+/+full_name+ column on a product-ish table with "Wireless Keyboard"
113
+ # instead of a person name. Mirrors the Python master's word banks.
114
+ PRODUCT_ADJECTIVES = %w[
115
+ Wireless Organic Premium Classic Eco Smart Portable
116
+ Deluxe Compact Rustic Handcrafted Vintage Modern
117
+ Ergonomic Stainless Bamboo Recycled Artisan Professional
118
+ Ultra Insulated Lightweight Adjustable Foldable
119
+ ].freeze
120
+
121
+ PRODUCT_NOUNS = [
122
+ "Keyboard", "Coffee Beans", "Backpack", "Water Bottle", "Desk Lamp",
123
+ "Headphones", "Notebook", "Sneakers", "Sunglasses", "Wallet", "Mug",
124
+ "Chair", "Blender", "Speaker", "Charger", "Umbrella", "Toothbrush",
125
+ "Jacket", "Watch", "Kettle", "Picture Frame", "Planter", "Cutlery Set",
126
+ "Yoga Mat", "Phone Case"
127
+ ].freeze
128
+
129
+ # A table/model whose name contains any of these gets product names on its
130
+ # generic +name+/+full_name+ column instead of a person name.
131
+ PRODUCT_TABLE_HINTS = %w[
132
+ product item catalog inventory goods merchandise sku listing stock ware
133
+ ].freeze
134
+
111
135
  def initialize(seed: nil)
112
136
  @rng = seed ? Random.new(seed) : Random.new
113
137
  end
@@ -247,6 +271,23 @@ module Tina4
247
271
  JOB_TITLES[@rng.rand(JOB_TITLES.length)]
248
272
  end
249
273
 
274
+ # A plausible product name, e.g. "Wireless Keyboard" or "Organic Coffee
275
+ # Beans". Deterministic under a seed like every other generator (draws from
276
+ # the same @rng), so a seeded run reproduces it. Mirrors the Python master's
277
+ # FakeData.product().
278
+ def product
279
+ "#{PRODUCT_ADJECTIVES[@rng.rand(PRODUCT_ADJECTIVES.length)]} #{PRODUCT_NOUNS[@rng.rand(PRODUCT_NOUNS.length)]}"
280
+ end
281
+
282
+ # True when the table/model name looks like a product catalogue, so a generic
283
+ # +name+/+full_name+ column seeds a product name, not a person name. With no
284
+ # table context (nil/"") this is false, so the person-name default is kept
285
+ # (back-compat). Mirrors the Python master's +_is_product_table+.
286
+ def self.product_table?(table)
287
+ down = table.to_s.downcase
288
+ PRODUCT_TABLE_HINTS.any? { |hint| down.include?(hint) }
289
+ end
290
+
250
291
  def currency
251
292
  CURRENCIES[@rng.rand(CURRENCIES.length)]
252
293
  end
@@ -282,7 +323,13 @@ module Tina4
282
323
  end
283
324
 
284
325
  # Generate appropriate data based on field definition and column name.
285
- def for_field(field_def, column_name = nil)
326
+ #
327
+ # +table+ (optional) is the table/model name. When it names a product-ish
328
+ # catalogue (see FakeData.product_table?) a generic +name+/+full_name+/
329
+ # +fullname+ column yields a product name ("Wireless Keyboard") instead of a
330
+ # person name. With no table context the person-name default is kept
331
+ # (back-compat). first_name/last_name/user_name stay person either way.
332
+ def for_field(field_def, column_name = nil, table = nil)
286
333
  col = (column_name || "").to_s.downcase
287
334
  type = field_def[:type]
288
335
 
@@ -323,7 +370,7 @@ module Tina4
323
370
 
324
371
  when :string, :text
325
372
  max_len = field_def[:length] || 255
326
- val = generate_string_for(col, max_len)
373
+ val = generate_string_for(col, max_len, table)
327
374
  val.length > max_len ? val[0...max_len] : val
328
375
 
329
376
  else
@@ -333,9 +380,15 @@ module Tina4
333
380
 
334
381
  private
335
382
 
336
- def generate_string_for(col, max_len)
383
+ def generate_string_for(col, max_len, table = nil)
337
384
  return email[0...max_len] if col.include?("email")
338
- return name[0...max_len] if %w[name full_name fullname display_name].include?(col)
385
+ if %w[name full_name fullname display_name].include?(col)
386
+ # GENERIC full-name column: a product-ish table gets a product name, any
387
+ # other table (or no table context) keeps the person name. first_name/
388
+ # last_name/user_name are handled by the branches below, so they stay
389
+ # person on a product table too.
390
+ return (self.class.product_table?(table) ? product : name)[0...max_len]
391
+ end
339
392
  return first_name[0...max_len] if col.include?("first") && col.include?("name")
340
393
  return last_name[0...max_len] if col.include?("last") && col.include?("name")
341
394
  return last_name[0...max_len] if col =~ /surname|family_name/
@@ -523,7 +576,10 @@ module Tina4
523
576
  elsif fk_pools[name] && !fk_pools[name].empty?
524
577
  attrs[name] = fake.choice(fk_pools[name])
525
578
  else
526
- generated = fake.for_field(field_def, name)
579
+ # Thread the MODEL name (orm_class.name) so a generic name column on
580
+ # a product-ish model seeds a product name (parity with the Python
581
+ # master, which passes orm_class.__name__).
582
+ generated = fake.for_field(field_def, name, orm_class.name)
527
583
  attrs[name] = generated unless generated.nil?
528
584
  end
529
585
  end
@@ -614,7 +670,10 @@ module Tina4
614
670
  row[col_name] = type_str.arity.zero? ? type_str.call : type_str.call(fake)
615
671
  else
616
672
  field_def = { type: type_str.to_sym }
617
- row[col_name] = fake.for_field(field_def, col_name)
673
+ # Thread the TABLE name so a generic name column on a product-ish
674
+ # table (incl. the MCP seed_table dev tool, which reaches here via
675
+ # db.columns) seeds a product name instead of a person name.
676
+ row[col_name] = fake.for_field(field_def, col_name, table_name)
618
677
  end
619
678
  end
620
679
 
data/lib/tina4/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tina4
4
- VERSION = "3.13.125"
4
+ VERSION = "3.13.126"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tina4ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.13.125
4
+ version: 3.13.126
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tina4 Team