Module: Synthra

Extended by:
API
Defined in:
lib/synthra.rb,
lib/synthra/api.rb,
lib/synthra/cli.rb,
lib/synthra/field.rb,
lib/synthra/mixin.rb,
lib/synthra/engine.rb,
lib/synthra/errors.rb,
lib/synthra/export.rb,
lib/synthra/limits.rb,
lib/synthra/schema.rb,
lib/synthra/version.rb,
lib/synthra/personas.rb,
lib/synthra/registry.rb,
lib/synthra/scenarios.rb,
lib/synthra/api_server.rb,
lib/synthra/export/csv.rb,
lib/synthra/export/sql.rb,
lib/synthra/lsp/server.rb,
lib/synthra/parser/ast.rb,
lib/synthra/types/base.rb,
lib/synthra/config_file.rb,
lib/synthra/export/base.rb,
lib/synthra/mock_server.rb,
lib/synthra/time_travel.rb,
lib/synthra/types/regex.rb,
lib/synthra/live_preview.rb,
lib/synthra/parser/lexer.rb,
lib/synthra/configuration.rb,
lib/synthra/export/python.rb,
lib/synthra/generator/rng.rb,
lib/synthra/native_engine.rb,
lib/synthra/parser/parser.rb,
lib/synthra/parser/tokens.rb,
lib/synthra/relationships.rb,
lib/synthra/types/formula.rb,
lib/synthra/behaviors/base.rb,
lib/synthra/export/graphql.rb,
lib/synthra/export/openapi.rb,
lib/synthra/repl/formatter.rb,
lib/synthra/types/registry.rb,
lib/synthra/types/scenario.rb,
lib/synthra/types/template.rb,
lib/synthra/database_seeder.rb,
lib/synthra/export/graphviz.rb,
lib/synthra/export/protobuf.rb,
lib/synthra/export/xml_data.rb,
lib/synthra/generator/modes.rb,
lib/synthra/quality_metrics.rb,
lib/synthra/export/json_data.rb,
lib/synthra/export/terraform.rb,
lib/synthra/export/yaml_data.rb,
lib/synthra/generator/engine.rb,
lib/synthra/openapi_importer.rb,
lib/synthra/performance_mode.rb,
lib/synthra/property_testing.rb,
lib/synthra/snapshot_testing.rb,
lib/synthra/type_definitions.rb,
lib/synthra/types/core/enums.rb,
lib/synthra/types/json_array.rb,
lib/synthra/behaviors/failure.rb,
lib/synthra/behaviors/latency.rb,
lib/synthra/cli/commands/base.rb,
lib/synthra/cli/commands/diff.rb,
lib/synthra/cli/commands/docs.rb,
lib/synthra/cli/commands/lint.rb,
lib/synthra/cli/commands/live.rb,
lib/synthra/cli/commands/seed.rb,
lib/synthra/deterministic_ids.rb,
lib/synthra/export/javascript.rb,
lib/synthra/export/sql_insert.rb,
lib/synthra/export/typescript.rb,
lib/synthra/generator/context.rb,
lib/synthra/rails_test_helper.rb,
lib/synthra/schema_versioning.rb,
lib/synthra/webhook_simulator.rb,
lib/synthra/behaviors/registry.rb,
lib/synthra/contracts_registry.rb,
lib/synthra/export/json_schema.rb,
lib/synthra/functions/registry.rb,
lib/synthra/generator/resolver.rb,
lib/synthra/generator/streamer.rb,
lib/synthra/repl/enhanced_repl.rb,
lib/synthra/schema_inheritance.rb,
lib/synthra/cli/commands/export.rb,
lib/synthra/cli/commands/import.rb,
lib/synthra/export/type_mapping.rb,
lib/synthra/migration_generator.rb,
lib/synthra/types/core/defaults.rb,
lib/synthra/types/crypto/crypto.rb,
lib/synthra/types/travel/travel.rb,
lib/synthra/behaviors/applicator.rb,
lib/synthra/behaviors/deprecated.rb,
lib/synthra/generator/uniqueness.rb,
lib/synthra/types/core/sequences.rb,
lib/synthra/types/naughty_string.rb,
lib/synthra/cli/commands/generate.rb,
lib/synthra/cli/commands/validate.rb,
lib/synthra/output/json_formatter.rb,
lib/synthra/types/core/primitives.rb,
lib/synthra/types/core/references.rb,
lib/synthra/types/date_time/dates.rb,
lib/synthra/utils/string_distance.rb,
lib/synthra/activerecord_inference.rb,
lib/synthra/behaviors/partial_data.rb,
lib/synthra/types/core/collections.rb,
lib/synthra/types/core/identifiers.rb,
lib/synthra/types/hostile_payloads.rb,
lib/synthra/documentation_generator.rb,
lib/synthra/factory_bot_integration.rb,
lib/synthra/generator/faker_adapter.rb,
lib/synthra/output/ndjson_formatter.rb,
lib/synthra/types/repeating_element.rb,
lib/synthra/types/text_content/misc.rb,
lib/synthra/validator/dsl_validator.rb,
lib/synthra/behaviors/simulate_error.rb,
lib/synthra/validator/path_validator.rb,
lib/synthra/behaviors/randomize_order.rb,
lib/synthra/export/graphql_federation.rb,
lib/synthra/types/text_content/colors.rb,
lib/synthra/behaviors/close_connection.rb,
lib/synthra/types/personal_names/names.rb,
lib/synthra/types/text_content/business.rb,
lib/synthra/types/text_content/security.rb,
lib/generators/synthra/install_generator.rb,
lib/synthra/types/health_medical/medical.rb,
lib/synthra/types/personal_names/chinese.rb,
lib/synthra/types/finance_banking/banking.rb,
lib/synthra/types/technology_internet/apps.rb,
lib/synthra/types/address_location/airports.rb,
lib/synthra/types/media_entertainment/media.rb,
lib/synthra/types/address_location/addresses.rb,
lib/synthra/types/address_location/locations.rb,
lib/synthra/types/commerce_products/commerce.rb,
lib/synthra/types/commerce_products/products.rb,
lib/synthra/types/personal_names/identifiers.rb,
lib/synthra/types/personal_names/national_id.rb,
lib/synthra/types/commerce_products/companies.rb,
lib/synthra/types/finance_banking/identifiers.rb,
lib/synthra/types/technology_internet/devices.rb,
lib/synthra/types/technology_internet/formats.rb,
lib/synthra/types/finance_banking/credit_cards.rb,
lib/synthra/types/text_content/text_generation.rb,
lib/synthra/types/commerce_products/construction.rb,
lib/synthra/types/personal_names/titles_suffixes.rb,
lib/synthra/types/technology_internet/networking.rb,
lib/synthra/types/address_location/banks_hospitals.rb,
lib/synthra/types/technology_internet/communication.rb

Overview

=============================================================================

Synthra National ID Type Generator

Generates government-issued identifier numbers (SSN, etc.). Format varies by country.

=============================================================================

Examples:

DSL usage

Person:
  ssn: national_id(country: :us)
  nino: national_id(country: :uk)

Generated values

"123-45-6789" (US SSN)
"AB123456C" (UK NINO)

Defined Under Namespace

Modules: API, Behaviors, CommonMixins, ConfigFile, DeterministicIds, Errors, Export, FactoryBotBridge, FactoryBotIntegration, Functions, Generator, Generators, HostilePayloads, LSP, Mixin, Output, Parser, PerformanceMode, Personas, PropertyTesting, QualityMetrics, REPL, RailsTestHelper, Relationships, Scenarios, SchemaInference, SchemaInheritance, SchemaVersioning, SnapshotTesting, TestHelpers, TimeTravel, Traits, Types, Utils, Validator, WebhookSimulator Classes: APIServer, ActiveRecordInference, CLI, Configuration, ContractError, ContractsRegistry, DatabaseSeeder, DocumentationGenerator, Engine, Error, Field, FieldBehavior, Limits, LivePreview, MigrationGenerator, MockServer, NativeEngine, OpenAPIImporter, Registry, Schema

Constant Summary collapse

OPTIONAL_FIELD_PRESENCE_RATE =

Probability that an optional field will be included (80%)

0.8
NULLABLE_FIELD_NULL_RATE =

Probability that a nullable field will be null (10%)

0.1
MAX_DSL_FILE_SIZE =

Maximum DSL file size to prevent DoS (10MB)

10 * 1024 * 1024
MODES =

Valid generation modes, in dispatch order (see Generator::Modes). Exposed so callers can discover the accepted mode: values instead of guessing.

%i[random edge invalid hostile mixed].freeze
ParseError =

Parsing errors

Errors::ParseError
SyntaxError =
Errors::SyntaxError
UnknownTypeError =
Errors::UnknownTypeError
PathError =
Errors::PathError
InvalidProbabilityError =
Errors::InvalidProbabilityError
IndentationError =
Errors::IndentationError
ValidationError =

Simulyra DSL validation errors

Errors::ValidationError
SchemaError =
Errors::SchemaError
ApiError =
Errors::ApiError
ScenarioError =
Errors::ScenarioError
ReferenceError =
Errors::ReferenceError
ContextError =
Errors::ContextError
GenerationError =

Generation errors

Errors::GenerationError
UniquenessError =
Errors::UniquenessError
CyclicReferenceError =
Errors::CyclicReferenceError
MissingReferenceError =
Errors::MissingReferenceError
MissingFunctionError =
Errors::MissingFunctionError
ConditionError =
Errors::ConditionError
ResourceLimitError =

Resource limit errors

Errors::ResourceLimitError
LatencyLimitError =
Errors::LatencyLimitError
RecursionLimitError =
Errors::RecursionLimitError
ArraySizeLimitError =
Errors::ArraySizeLimitError
TextLengthLimitError =
Errors::TextLengthLimitError
SimulatedBehaviorError =

Simulated behavior errors

Errors::SimulatedBehaviorError
SimulatedFailure =
Errors::SimulatedFailure
SimulatedConnectionDrop =
Errors::SimulatedConnectionDrop
SimulatedError =
Errors::SimulatedError
VERSION =

Current version of the Synthra gem

Examples:

Check version

puts Synthra::VERSION  # => "0.1.0"

Compare versions

Gem::Version.new(Synthra::VERSION) >= Gem::Version.new("0.1.0")

Returns:

  • (String)

    the semantic version string

"0.1.0"

Class Method Summary collapse

Class Method Details

.[](*args, **options) ⇒ Object

Shorthand accessor

Examples:

Synthra[:User]
Synthra[:Order, seed: 42]


243
244
245
246
247
248
249
# File 'lib/synthra/engine.rb', line 243

def Synthra.[](*args, **options)
  if args.length == 1
    generate(args.first.to_s, **options)
  else
    args.map { |name| generate(name.to_s, **options) }
  end
end

.as(persona_name) { ... } ⇒ Object

Generate data using a persona

Examples:

Synthra.as(:happy_path) { generate("User") }

Parameters:

  • persona_name (Symbol)

    persona to use

Yields:

  • block for generation

Returns:

  • (Object)

    result



382
383
384
# File 'lib/synthra/personas.rb', line 382

def as(persona_name, &block)
  Personas.as(persona_name, &block)
end

.configurationConfiguration Originally defined in module API

Returns the global configuration instance

Returns:

.configure {|Configuration| ... } ⇒ void Originally defined in module API

This method returns an undefined value.

Configure Synthra with a block

Yields:

.configure_test_helper!void

This method returns an undefined value.

Configure Rails test helper



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/synthra/rails_test_helper.rb', line 232

def configure_test_helper!
  return unless defined?(Rails)
  
  # Auto-load schemas from standard locations
  schema_paths = [
    Rails.root.join("schemas"),
    Rails.root.join("test/schemas"),
    Rails.root.join("spec/schemas")
  ]
  
  @default_registry ||= Registry.new
  schema_paths.each do |path|
    @default_registry.load_dir(path.to_s) if path.exist?
  end
end

.current_personaPersonas::PersonaContext?

Get current persona context

Returns:



390
391
392
# File 'lib/synthra/personas.rb', line 390

def current_persona
  Thread.current[:synthra_persona]
end

.data_export_formatsObject Originally defined in module API

List data export formats

.define_factory(factory_name, schema:) { ... } ⇒ void Originally defined in module API

This method returns an undefined value.

Define a factory using a Synthra schema

Examples:

Synthra.define_factory(:user, schema: "User") do
  trait(:admin) { role { "admin" } }
end

Parameters:

  • factory_name (Symbol)

    the factory name

  • schema (String)

    schema name

Yields:

  • block for defining traits and overrides

.each_schema {|schema| ... } ⇒ Object Originally defined in module API

Iterate over all loaded schemas

Yields:

  • (schema)

    block to execute for each schema

.export(format, schema, **options) ⇒ Object Originally defined in module API

Export to any supported format

.export_extension(format) ⇒ Object Originally defined in module API

Get file extension for export format

.export_filename(schema_name, format) ⇒ Object Originally defined in module API

Generate auto filename for export

.export_formatsObject Originally defined in module API

List available export formats

.export_to_file(format, schema, output_dir: ".", **options) ⇒ Object Originally defined in module API

Export to file with auto-generated filename

.generate_native(schema_or_dsl, count, seed: nil, locale: "en", threads: nil) ⇒ Array<Hash> Originally defined in module API

Generate records using native engine

Parameters:

  • schema_or_dsl (Schema, String)

    schema instance or DSL string

  • count (Integer)

    number of records to generate

  • seed (Integer, nil) (defaults to: nil)

    random seed for reproducibility

  • locale (String) (defaults to: "en")

    locale for data generation

  • threads (Integer, nil) (defaults to: nil)

    number of threads

Returns:

  • (Array<Hash>)

    generated records

.generate_native_to_file(schema_or_dsl, count, path, seed: nil, locale: "en", format: "jsonl", threads: nil) ⇒ Integer Originally defined in module API

Generate records to file using native engine

Parameters:

  • schema_or_dsl (Schema, String)

    schema instance or DSL string

  • count (Integer)

    number of records to generate

  • path (String)

    output file path

  • seed (Integer, nil) (defaults to: nil)

    random seed

  • locale (String) (defaults to: "en")

    locale for data generation

  • format (String) (defaults to: "jsonl")

    output format: "jsonl", "json", "csv"

  • threads (Integer, nil) (defaults to: nil)

    number of threads

Returns:

  • (Integer)

    number of records written

.load(path) ⇒ Schema Originally defined in module API

Load and parse a single DSL file

Parameters:

  • path (String)

    path to the DSL file

Returns:

  • (Schema)

    the parsed schema object

Raises:

.load_all(path) ⇒ Array<Schema> Originally defined in module API

Load a DSL file and return ALL schemas it defines (not just the first).

Parameters:

  • path (String)

    path to the DSL file

Returns:

  • (Array<Schema>)

    every schema defined in the file

.load_config_file!void

This method returns an undefined value.

Load configuration from config file on first use



221
222
223
224
225
226
# File 'lib/synthra.rb', line 221

def load_config_file!
  @config_loaded ||= begin
    ConfigFile.load_and_apply
    true
  end
end

.load_schemas(path) ⇒ Object Originally defined in module API

Load schemas into default registry for iteration

Parameters:

  • path (String)

    path to schema file or directory

.native_available?Boolean Originally defined in module API

Check if native Rust engine is available

Returns:

  • (Boolean)

    true if native extension is available

.native_engine(schema, locale: "en") ⇒ NativeEngine Originally defined in module API

Create a native engine for a schema

Parameters:

  • schema (Schema)

    the schema to use

  • locale (String) (defaults to: "en")

    locale for data generation

Returns:

.parse(source) ⇒ Schema Originally defined in module API

Parse a DSL string and return the first schema

Parameters:

  • source (String)

    DSL source code

Returns:

  • (Schema)

    the parsed schema object

.parse_all(source) ⇒ Array<Schema> Originally defined in module API

Parse a DSL string and return ALL schemas it defines (not just the first).

parse/load return a single schema for convenience, which silently drops the rest of a multi-schema file. Use these when a source may define more than one schema.

Parameters:

  • source (String)

    DSL source code

Returns:

  • (Array<Schema>)

    every schema defined in the source

.register_address_types!Object (private)



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/synthra/type_definitions.rb', line 144

def register_address_types!
  Types::Registry.register("country_code", Types::AddressLocation::CountryCode)
  Types::Registry.register("country", Types::AddressLocation::Country)
  Types::Registry.register("city", Types::AddressLocation::City)
  Types::Registry.register("state", Types::AddressLocation::State)
  Types::Registry.register("address", Types::AddressLocation::Address)
  Types::Registry.register("latitude", Types::AddressLocation::Latitude)
  Types::Registry.register("longitude", Types::AddressLocation::Longitude)
  Types::Registry.register("timezone", Types::AddressLocation::Timezone)
  Types::Registry.register("postal_code", Types::AddressLocation::PostalCode)
  Types::Registry.register("zip_code", Types::AddressLocation::PostalCode)
  Types::Registry.register("address_line_2", Types::AddressLocation::AddressLine2)
  Types::Registry.register("street_name", Types::AddressLocation::StreetName)
  Types::Registry.register("street_address", Types::AddressLocation::StreetName)
  Types::Registry.register("street_number", Types::AddressLocation::StreetNumber)
  Types::Registry.register("street_suffix", Types::AddressLocation::StreetSuffix)
  Types::Registry.register("airport_name", Types::AddressLocation::AirportName)
  Types::Registry.register("airport_continent", Types::AddressLocation::AirportContinent)
  Types::Registry.register("airport_country_code", Types::AddressLocation::AirportCountryCode)
  Types::Registry.register("airport_elevation", Types::AddressLocation::AirportElevation)
  Types::Registry.register("airport_gps_code", Types::AddressLocation::AirportGpsCode)
  Types::Registry.register("airport_latitude", Types::AddressLocation::AirportLatitude)
  Types::Registry.register("airport_longitude", Types::AddressLocation::AirportLongitude)
  Types::Registry.register("airport_municipality", Types::AddressLocation::AirportMunicipality)
  Types::Registry.register("airport_region_code", Types::AddressLocation::AirportRegionCode)
  Types::Registry.register("bank_city", Types::AddressLocation::BankCity)
  Types::Registry.register("bank_country_code", Types::AddressLocation::BankCountryCode)
  Types::Registry.register("bank_street_address", Types::AddressLocation::BankStreetAddress)
  Types::Registry.register("bank_state", Types::AddressLocation::BankState)
  Types::Registry.register("hospital_city", Types::AddressLocation::HospitalCity)
  Types::Registry.register("hospital_postal_code", Types::AddressLocation::HospitalPostalCode)
  Types::Registry.register("hospital_state", Types::AddressLocation::HospitalState)
  Types::Registry.register("hospital_street_address", Types::AddressLocation::HospitalStreetAddress)
end

.register_advanced_types!Object (private)



260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/synthra/type_definitions.rb', line 260

def register_advanced_types!
  # Date/Time
  register_datetime_types!

  # Advanced types
  Types::Registry.register("formula", Types::Formula)
  Types::Registry.register("json_array", Types::JsonArray)
  Types::Registry.register("naughty_string", Types::NaughtyString)
  Types::Registry.register("regex", Types::Regex)
  Types::Registry.register("repeating_element", Types::RepeatingElement)
  Types::Registry.register("scenario", Types::Scenario)
  Types::Registry.register("template", Types::Template)
end

.register_behavior(name, klass = nil) {|result, context, value| ... } ⇒ void Originally defined in module API

This method returns an undefined value.

Register a custom behavior

Parameters:

  • name (Symbol)

    the behavior name

  • klass (Class, nil) (defaults to: nil)

    optional class inheriting from Behaviors::Base

Yields:

  • (result, context, value)

    block for applying behavior

.register_builtin_types!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Registers all built-in types

This method is called automatically when the gem loads.



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/synthra/type_definitions.rb', line 18

def self.register_builtin_types!
  register_core_types!
  register_personal_types!
  register_commerce_types!
  register_finance_types!
  register_address_types!
  register_technology_types!
  register_text_types!
  register_media_types!
  register_advanced_types!
end

.register_commerce_types!Object (private)



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/synthra/type_definitions.rb', line 102

def register_commerce_types!
  Types::Registry.register("job_title", Types::CommerceProducts::JobTitle)
  Types::Registry.register("company_name", Types::CommerceProducts::CompanyName)
  Types::Registry.register("product_name", Types::CommerceProducts::ProductName)
  Types::Registry.register("product_category", Types::CommerceProducts::ProductCategory)
  Types::Registry.register("sku", Types::CommerceProducts::Sku)
  Types::Registry.register("discount", Types::CommerceProducts::Discount)
  Types::Registry.register("tax_rate", Types::CommerceProducts::TaxRate)
  Types::Registry.register("construction_heavy_equipment", Types::CommerceProducts::ConstructionHeavyEquipment)
  Types::Registry.register("construction_material", Types::CommerceProducts::ConstructionMaterial)
  Types::Registry.register("construction_role", Types::CommerceProducts::ConstructionRole)
  Types::Registry.register("construction_standard_cost_code", Types::CommerceProducts::ConstructionStandardCostCode)
  Types::Registry.register("construction_subcontract_category", Types::CommerceProducts::ConstructionSubcontractCategory)
  Types::Registry.register("construction_trade", Types::CommerceProducts::ConstructionTrade)
  Types::Registry.register("product_grocery", Types::CommerceProducts::ProductGrocery)
  Types::Registry.register("product_description", Types::CommerceProducts::ProductDescription)
  Types::Registry.register("product_price", Types::CommerceProducts::ProductPrice)
  Types::Registry.register("product_subcategory", Types::CommerceProducts::ProductSubcategory)
  Types::Registry.register("shirt_size", Types::CommerceProducts::ShirtSize)
end

.register_core_types!Object (private)



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/synthra/type_definitions.rb', line 33

def register_core_types!
  # Require core type files
  require_relative "types/core/identifiers"
  require_relative "types/core/primitives"
  require_relative "types/core/collections"
  require_relative "types/core/references"
  require_relative "types/core/sequences"
  require_relative "types/core/defaults"
  require_relative "types/core/enums"

  # Identifiers
  Types::Registry.register("uuid", Types::Core::Uuid)
  Types::Registry.register("ulid", Types::Core::Ulid)
  Types::Registry.register("id_sequence", Types::Core::IdSequence)
  Types::Registry.register("snowflake_id", Types::Core::SnowflakeId)
  Types::Registry.register("unix_timestamp_ms", Types::Core::UnixTimestampMs)
  Types::Registry.register("numeric_string_id", Types::Core::NumericStringId)
  Types::Registry.register("alphanumeric_id", Types::Core::AlphanumericId)
  Types::Registry.register("locale", Types::Core::Locale)
  Types::Registry.register("token", Types::Core::Token)

  # Primitives
  Types::Registry.register("text", Types::Core::Text)
  Types::Registry.register("string", Types::Core::Text) # alias for OpenAPI/contract compatibility
  Types::Registry.register("number", Types::Core::Number)
  Types::Registry.register("boolean", Types::Core::Boolean)
  Types::Registry.register("const", Types::Core::Const)

  # Collections
  Types::Registry.register("array", Types::Core::ArrayType)
  Types::Registry.register("object", Types::Core::ObjectType)
  Types::Registry.register("map_by_field", Types::Core::MapByField)
  Types::Registry.register("one_of", Types::Core::OneOf)
  Types::Registry.register("enum", Types::Core::Enum)

  # References and sequences
  Types::Registry.register("sequence", Types::Core::Sequence)
  Types::Registry.register("default_value", Types::Core::DefaultValue)
  Types::Registry.register("reference", Types::Core::Reference)
  Types::Registry.register("custom", Types::Core::Custom)
  Types::Registry.register("copy", Types::Core::Copy)
  Types::Registry.register("shared", Types::Core::Shared)
  Types::Registry.register("character_sequence", Types::Core::CharacterSequence)
  Types::Registry.register("digit_sequence", Types::Core::DigitSequence)

  # Simulyra DSL schema reference type
  Types::Registry.register("schema_ref", Types::Core::SchemaRef)
end

.register_datetime_types!Object (private)



249
250
251
252
253
254
255
256
257
258
# File 'lib/synthra/type_definitions.rb', line 249

def register_datetime_types!
  Types::Registry.register("date", Types::DateTime::DateType)
  Types::Registry.register("past_date", Types::DateTime::PastDate)
  Types::Registry.register("future_date", Types::DateTime::FutureDate)
  Types::Registry.register("now", Types::DateTime::Now)
  Types::Registry.register("timestamp", Types::DateTime::Timestamp)
  Types::Registry.register("time", Types::DateTime::TimeType)
  Types::Registry.register("datetime", Types::DateTime::DatetimeType)
  Types::Registry.register("date_between", Types::DateTime::DateBetween)
end

.register_finance_types!Object (private)



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/synthra/type_definitions.rb', line 123

def register_finance_types!
  Types::Registry.register("money", Types::FinanceBanking::Money)
  Types::Registry.register("currency", Types::FinanceBanking::Currency)
  Types::Registry.register("currency_code", Types::FinanceBanking::Currency)
  Types::Registry.register("credit_card", Types::FinanceBanking::CreditCard)
  Types::Registry.register("bank_name", Types::FinanceBanking::BankName)
  Types::Registry.register("account_number", Types::FinanceBanking::AccountNumber)
  Types::Registry.register("iban", Types::FinanceBanking::Iban)
  Types::Registry.register("transaction_amount", Types::FinanceBanking::TransactionAmount)
  Types::Registry.register("ssn", Types::FinanceBanking::Ssn)
  Types::Registry.register("ein", Types::FinanceBanking::Ein)
  Types::Registry.register("bank_routing_number", Types::FinanceBanking::BankRoutingNumber)
  Types::Registry.register("bank_swift_bic", Types::FinanceBanking::BankSwiftBic)
  Types::Registry.register("bank_lei", Types::FinanceBanking::BankLei)
  Types::Registry.register("bank_riad_code", Types::FinanceBanking::BankRiadCode)
  Types::Registry.register("credit_card_type", Types::FinanceBanking::CreditCardType)
  Types::Registry.register("duns_number", Types::FinanceBanking::DunsNumber)
  Types::Registry.register("medicare_beneficiary_id", Types::FinanceBanking::MedicareBeneficiaryId)
  Types::Registry.register("nhs_number", Types::FinanceBanking::NhsNumber)
end

.register_function(name, force: false) {|context| ... } ⇒ void Originally defined in module API

This method returns an undefined value.

Register a custom function for computed fields

Parameters:

  • name (Symbol)

    the function name

  • force (Boolean) (defaults to: false)

    if true, overwrites existing function

Yields:

  • (context)

    block that computes the value

.register_media_types!Object (private)



244
245
246
247
# File 'lib/synthra/type_definitions.rb', line 244

def register_media_types!
  Types::Registry.register("movie_genres", Types::MediaEntertainment::MovieGenres)
  Types::Registry.register("movie_title", Types::MediaEntertainment::MovieTitle)
end

.register_personal_types!Object (private)



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/synthra/type_definitions.rb', line 82

def register_personal_types!
  Types::Registry.register("name", Types::PersonalNames::Name)
  Types::Registry.register("first_name", Types::PersonalNames::FirstName)
  Types::Registry.register("last_name", Types::PersonalNames::LastName)
  Types::Registry.register("full_name", Types::PersonalNames::FullName)
  Types::Registry.register("gender", Types::PersonalNames::Gender)
  Types::Registry.register("age", Types::PersonalNames::Age)
  Types::Registry.register("username", Types::PersonalNames::Username)
  Types::Registry.register("family_name_chinese", Types::PersonalNames::FamilyNameChinese)
  Types::Registry.register("given_name_chinese", Types::PersonalNames::GivenNameChinese)
  Types::Registry.register("first_name_european", Types::PersonalNames::FirstNameEuropean)
  Types::Registry.register("first_name_female", Types::PersonalNames::FirstNameFemale)
  Types::Registry.register("first_name_male", Types::PersonalNames::FirstNameMale)
  Types::Registry.register("gender_abbrev", Types::PersonalNames::GenderAbbrev)
  Types::Registry.register("gender_binary", Types::PersonalNames::GenderBinary)
  Types::Registry.register("gender_facebook", Types::PersonalNames::GenderFacebook)
  Types::Registry.register("suffix", Types::PersonalNames::Suffix)
  Types::Registry.register("title", Types::PersonalNames::Title)
end

.register_technology_types!Object (private)



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/synthra/type_definitions.rb', line 179

def register_technology_types!
  Types::Registry.register("email", Types::TechnologyInternet::Email)
  Types::Registry.register("phone", Types::TechnologyInternet::Phone)
  Types::Registry.register("url", Types::TechnologyInternet::Url)
  Types::Registry.register("ip", Types::TechnologyInternet::Ip)
  Types::Registry.register("ip_address", Types::TechnologyInternet::Ip)
  Types::Registry.register("ipv6", Types::TechnologyInternet::Ipv6)
  Types::Registry.register("mac_address", Types::TechnologyInternet::MacAddress)
  Types::Registry.register("domain", Types::TechnologyInternet::Domain)
  Types::Registry.register("user_agent", Types::TechnologyInternet::UserAgent)
  Types::Registry.register("app_bundle_id", Types::TechnologyInternet::AppBundleId)
  Types::Registry.register("app_name", Types::TechnologyInternet::AppName)
  Types::Registry.register("app_version", Types::TechnologyInternet::AppVersion)
  Types::Registry.register("base64_image_url", Types::TechnologyInternet::Base64ImageUrl)
  Types::Registry.register("dummy_image_url", Types::TechnologyInternet::DummyImageUrl)
  Types::Registry.register("ip_v4_cidr", Types::TechnologyInternet::IpV4Cidr)
  Types::Registry.register("ip_v6_cidr", Types::TechnologyInternet::IpV6Cidr)
  Types::Registry.register("language", Types::TechnologyInternet::Language)
  Types::Registry.register("language_code", Types::TechnologyInternet::LanguageCode)
  Types::Registry.register("mime_type", Types::TechnologyInternet::MimeType)
  Types::Registry.register("mobile_device_brand", Types::TechnologyInternet::MobileDeviceBrand)
  Types::Registry.register("mobile_device_model", Types::TechnologyInternet::MobileDeviceModel)
  Types::Registry.register("mobile_device_os", Types::TechnologyInternet::MobileDeviceOs)
  Types::Registry.register("mobile_device_release_date", Types::TechnologyInternet::MobileDeviceReleaseDate)
  Types::Registry.register("mongodb_object_id", Types::TechnologyInternet::MongodbObjectId)
  Types::Registry.register("top_level_domain", Types::TechnologyInternet::TopLevelDomain)
end

.register_text_types!Object (private)



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/synthra/type_definitions.rb', line 207

def register_text_types!
  Types::Registry.register("avatar", Types::TextContent::Avatar)
  Types::Registry.register("buzzword", Types::TextContent::Buzzword)
  Types::Registry.register("catch_phrase", Types::TextContent::CatchPhrase)
  Types::Registry.register("color", Types::TextContent::Color)
  Types::Registry.register("hex_color", Types::TextContent::HexColor)
  Types::Registry.register("short_hex_color", Types::TextContent::ShortHexColor)
  Types::Registry.register("encrypt", Types::TextContent::Encrypt)
  Types::Registry.register("file_name", Types::TextContent::FileName)
  Types::Registry.register("frequency", Types::TextContent::Frequency)
  Types::Registry.register("linkedin_skill", Types::TextContent::LinkedInSkill)
  Types::Registry.register("md5", Types::TextContent::Md5)
  Types::Registry.register("sha1", Types::TextContent::Sha1)
  Types::Registry.register("sha256", Types::TextContent::Sha256)
  Types::Registry.register("nato_phonetic", Types::TextContent::NatoPhonetic)
  Types::Registry.register("paragraphs", Types::TextContent::Paragraphs)
  Types::Registry.register("password", Types::TextContent::Password)
  Types::Registry.register("password_hash", Types::TextContent::PasswordHash)
  Types::Registry.register("row_number", Types::TextContent::RowNumber)
  Types::Registry.register("sentences", Types::TextContent::Sentences)
  Types::Registry.register("slogan", Types::TextContent::Slogan)
  Types::Registry.register("sql_expression", Types::TextContent::SqlExpression)
  Types::Registry.register("words", Types::TextContent::Words)
  Types::Registry.register("slug", Types::TextContent::Slug)
  Types::Registry.register("university", Types::TextContent::University)
  Types::Registry.register("blank", Types::TextContent::Blank)
  Types::Registry.register("race", Types::TextContent::Race)
  Types::Registry.register("department_corporate", Types::TextContent::DepartmentCorporate)
  Types::Registry.register("department_retail", Types::TextContent::DepartmentRetail)
  Types::Registry.register("fake_company_name", Types::TextContent::FakeCompanyName)
  Types::Registry.register("message_text", Types::TextContent::MessageText)
  Types::Registry.register("empty_array", Types::TextContent::EmptyArray)
  Types::Registry.register("hashtag_text", Types::TextContent::HashtagText)
  Types::Registry.register("social_handle", Types::TextContent::SocialHandle)
  Types::Registry.register("indices_pair", Types::TextContent::IndicesPair)
end

.register_type(name, klass = nil) {|rng, context, args, mode| ... } ⇒ void Originally defined in module API

This method returns an undefined value.

Register a custom type generator

Parameters:

  • name (String, Symbol)

    the type name to use in DSL files

  • klass (Class, nil) (defaults to: nil)

    optional class inheriting from Types::Base

Yields:

  • (rng, context, args, mode)

    block for generating values

.registryRegistry Originally defined in module API

Access the default registry

Returns:

  • (Registry)

    the default schema registry

.reset_configuration!void Originally defined in module API

This method returns an undefined value.

Reset configuration to default values

.schema_export_formatsObject Originally defined in module API

List schema export formats

.seed_database(**options) { ... } ⇒ Hash

Convenience method for database seeding

Parameters:

  • options (Hash)

    seeder options

Yields:

  • seeding DSL

Returns:

  • (Hash)

    created records by model



263
264
265
266
# File 'lib/synthra/database_seeder.rb', line 263

def seed_database(**options, &block)
  seeder = DatabaseSeeder.new(**options)
  seeder.seed(&block)
end

.to_csv(schema, registry: nil, count: 10, seed: nil, mode: :random) ⇒ Object Originally defined in module API

Export generated data as CSV

.to_graphql(schema, registry: nil) ⇒ Object Originally defined in module API

Export schema to GraphQL

.to_graphql_all(registry) ⇒ Object Originally defined in module API

Export all schemas to GraphQL

.to_graphviz(schema = nil, registry: nil, direction: "LR", group: false) ⇒ Object Originally defined in module API

Export schema to GraphViz DOT format

.to_javascript(schema, registry: nil) ⇒ Object Originally defined in module API

Export schema to JavaScript with JSDoc

.to_javascript_all(registry) ⇒ Object Originally defined in module API

Export all schemas to JavaScript

.to_json(schema, registry: nil, count: 10, seed: nil, mode: :random, pretty: true, envelope: nil) ⇒ Object Originally defined in module API

Export generated data as JSON

.to_json_schema(schema, registry: nil) ⇒ Object Originally defined in module API

Export schema to JSON Schema format

.to_python(schema, registry: nil, style: :pydantic) ⇒ Object Originally defined in module API

Export schema to Python

.to_python_all(registry, style: :pydantic) ⇒ Object Originally defined in module API

Export all schemas to Python

.to_sql(schema, registry: nil, dialect: :postgresql) ⇒ Object Originally defined in module API

Export schema to SQL CREATE TABLE

.to_sql_all(registry, dialect: :postgresql) ⇒ Object Originally defined in module API

Export all schemas to SQL

.to_sql_insert(schema, registry: nil, count: 10, seed: nil, dialect: :postgresql, batch_insert: false) ⇒ Object Originally defined in module API

Export generated data as SQL INSERT statements

.to_typescript(schema, registry: nil, comments: false) ⇒ Object Originally defined in module API

Export schema to TypeScript interface

.to_typescript_all(registry) ⇒ Object Originally defined in module API

Export all schemas to TypeScript

.to_xml(schema, registry: nil, count: 10, seed: nil, root: nil, item: nil) ⇒ Object Originally defined in module API

Export generated data as XML

.to_yaml(schema, registry: nil, count: 10, seed: nil, root_key: nil) ⇒ Object Originally defined in module API

Export generated data as YAML