synthra 0.1.0

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 (302) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +4 -0
  3. data/.rubocop.yml +40 -0
  4. data/.yardopts +18 -0
  5. data/ACCESS_DOCS.md +116 -0
  6. data/ADVANCED_FEATURES_SUMMARY.md +245 -0
  7. data/CHANGELOG.md +498 -0
  8. data/CODE_OF_CONDUCT.md +122 -0
  9. data/CONTRIBUTING.md +307 -0
  10. data/DOCUMENTATION.md +204 -0
  11. data/DOCUMENTATION_GUIDE.md +194 -0
  12. data/LICENSE +22 -0
  13. data/README.md +1458 -0
  14. data/Rakefile +128 -0
  15. data/benchmark/README.md +591 -0
  16. data/benchmark/batch_generation.rb +63 -0
  17. data/benchmark/engine_comparison.rb +295 -0
  18. data/benchmark/single_record.rb +108 -0
  19. data/benchmark/streaming.rb +74 -0
  20. data/docs/ACTIVERECORD_INFERENCE.md +524 -0
  21. data/docs/API_SERVER.md +278 -0
  22. data/docs/CONFIG_FILE.md +315 -0
  23. data/docs/DATA_CONTRACTS.md +312 -0
  24. data/docs/ENHANCED_REPL.md +304 -0
  25. data/docs/FACTORY_BOT.md +271 -0
  26. data/docs/GITHUB_ACTION.md +420 -0
  27. data/docs/GRAPHQL_EXPORT.md +303 -0
  28. data/docs/GRAPHQL_FEDERATION.md +651 -0
  29. data/docs/HOW_TO_GENERATE_DOCS.md +252 -0
  30. data/docs/LSP.md +189 -0
  31. data/docs/MIGRATION_GENERATOR.md +547 -0
  32. data/docs/MOCK_SERVER.md +280 -0
  33. data/docs/NATIVE_ENGINE.md +298 -0
  34. data/docs/OPENAPI_EXPORT.md +252 -0
  35. data/docs/PERFORMANCE_MODE.md +228 -0
  36. data/docs/PERSONAS.md +547 -0
  37. data/docs/PROPERTY_TESTING.md +284 -0
  38. data/docs/PROTOBUF_EXPORT.md +276 -0
  39. data/docs/QUALITY_METRICS.md +555 -0
  40. data/docs/QUICK_REFERENCE.md +88 -0
  41. data/docs/RAILS_ENGINE.md +404 -0
  42. data/docs/RAILS_INTEGRATION.md +454 -0
  43. data/docs/README.md +175 -0
  44. data/docs/REPL_QUICK_REFERENCE.md +149 -0
  45. data/docs/RUST_INTEGRATION_GUIDE.md +1376 -0
  46. data/docs/SCENARIOS.md +576 -0
  47. data/docs/SECURITY_TESTING.md +318 -0
  48. data/docs/SNAPSHOT_TESTING.md +308 -0
  49. data/docs/STRING_TEXT_TYPES_REFERENCE.md +512 -0
  50. data/docs/TERRAFORM_EXPORT.md +447 -0
  51. data/docs/TIME_TRAVEL.md +507 -0
  52. data/docs/USAGE_GUIDE.md +980 -0
  53. data/docs/WEBHOOK_SIMULATOR.md +579 -0
  54. data/docs/advanced_features.md +183 -0
  55. data/docs/api_reference.md +153 -0
  56. data/docs/behaviors.md +138 -0
  57. data/docs/best_practices.md +191 -0
  58. data/docs/dsl_reference.md +172 -0
  59. data/docs/examples.md +162 -0
  60. data/docs/generation_modes.md +125 -0
  61. data/docs/getting_started.md +92 -0
  62. data/docs/index.html +177 -0
  63. data/docs/strategic/CLOUD_REGISTRY_ARCHITECTURE.md +268 -0
  64. data/docs/strategic/SIMD_OPTIMIZATION_STRATEGY.md +153 -0
  65. data/docs/troubleshooting.md +215 -0
  66. data/docs/type_reference.md +224 -0
  67. data/examples/hostile_mode_demo.rb +64 -0
  68. data/exe/synthra +6 -0
  69. data/ext/synthra_native/Cargo.lock +972 -0
  70. data/ext/synthra_native/Cargo.toml +46 -0
  71. data/ext/synthra_native/extconf.rb +41 -0
  72. data/ext/synthra_native/src/generator.rs +397 -0
  73. data/ext/synthra_native/src/lib.rs +229 -0
  74. data/ext/synthra_native/src/types.rs +1485 -0
  75. data/lib/generators/synthra/install_generator.rb +86 -0
  76. data/lib/generators/synthra/templates/api_response.dsl +15 -0
  77. data/lib/generators/synthra/templates/fake_data.rake +116 -0
  78. data/lib/generators/synthra/templates/synthra.yml +31 -0
  79. data/lib/generators/synthra/templates/synthra_support.rb +19 -0
  80. data/lib/generators/synthra/templates/user.dsl +11 -0
  81. data/lib/synthra/activerecord_inference.rb +394 -0
  82. data/lib/synthra/api.rb +381 -0
  83. data/lib/synthra/api_server.rb +718 -0
  84. data/lib/synthra/behaviors/applicator.rb +165 -0
  85. data/lib/synthra/behaviors/base.rb +155 -0
  86. data/lib/synthra/behaviors/close_connection.rb +60 -0
  87. data/lib/synthra/behaviors/deprecated.rb +100 -0
  88. data/lib/synthra/behaviors/failure.rb +69 -0
  89. data/lib/synthra/behaviors/latency.rb +103 -0
  90. data/lib/synthra/behaviors/partial_data.rb +83 -0
  91. data/lib/synthra/behaviors/randomize_order.rb +74 -0
  92. data/lib/synthra/behaviors/registry.rb +238 -0
  93. data/lib/synthra/behaviors/simulate_error.rb +79 -0
  94. data/lib/synthra/cli/commands/base.rb +105 -0
  95. data/lib/synthra/cli/commands/diff.rb +227 -0
  96. data/lib/synthra/cli/commands/docs.rb +67 -0
  97. data/lib/synthra/cli/commands/export.rb +150 -0
  98. data/lib/synthra/cli/commands/generate.rb +72 -0
  99. data/lib/synthra/cli/commands/import.rb +80 -0
  100. data/lib/synthra/cli/commands/lint.rb +53 -0
  101. data/lib/synthra/cli/commands/live.rb +57 -0
  102. data/lib/synthra/cli/commands/seed.rb +99 -0
  103. data/lib/synthra/cli/commands/validate.rb +28 -0
  104. data/lib/synthra/cli.rb +2471 -0
  105. data/lib/synthra/config_file.rb +129 -0
  106. data/lib/synthra/configuration.rb +281 -0
  107. data/lib/synthra/contracts_registry.rb +408 -0
  108. data/lib/synthra/database_seeder.rb +268 -0
  109. data/lib/synthra/deterministic_ids.rb +218 -0
  110. data/lib/synthra/documentation_generator.rb +414 -0
  111. data/lib/synthra/engine.rb +251 -0
  112. data/lib/synthra/errors.rb +1169 -0
  113. data/lib/synthra/export/base.rb +85 -0
  114. data/lib/synthra/export/csv.rb +101 -0
  115. data/lib/synthra/export/graphql.rb +266 -0
  116. data/lib/synthra/export/graphql_federation.rb +377 -0
  117. data/lib/synthra/export/graphviz.rb +258 -0
  118. data/lib/synthra/export/javascript.rb +327 -0
  119. data/lib/synthra/export/json_data.rb +61 -0
  120. data/lib/synthra/export/json_schema.rb +290 -0
  121. data/lib/synthra/export/openapi.rb +514 -0
  122. data/lib/synthra/export/protobuf.rb +483 -0
  123. data/lib/synthra/export/python.rb +560 -0
  124. data/lib/synthra/export/sql.rb +381 -0
  125. data/lib/synthra/export/sql_insert.rb +152 -0
  126. data/lib/synthra/export/terraform.rb +501 -0
  127. data/lib/synthra/export/type_mapping.rb +389 -0
  128. data/lib/synthra/export/typescript.rb +300 -0
  129. data/lib/synthra/export/xml_data.rb +104 -0
  130. data/lib/synthra/export/yaml_data.rb +56 -0
  131. data/lib/synthra/export.rb +404 -0
  132. data/lib/synthra/factory_bot_integration.rb +157 -0
  133. data/lib/synthra/field.rb +440 -0
  134. data/lib/synthra/functions/registry.rb +104 -0
  135. data/lib/synthra/generator/context.rb +372 -0
  136. data/lib/synthra/generator/engine.rb +336 -0
  137. data/lib/synthra/generator/faker_adapter.rb +425 -0
  138. data/lib/synthra/generator/modes.rb +444 -0
  139. data/lib/synthra/generator/resolver.rb +256 -0
  140. data/lib/synthra/generator/rng.rb +273 -0
  141. data/lib/synthra/generator/streamer.rb +63 -0
  142. data/lib/synthra/generator/uniqueness.rb +118 -0
  143. data/lib/synthra/initializer.rb +97 -0
  144. data/lib/synthra/limits.rb +279 -0
  145. data/lib/synthra/live_preview.rb +518 -0
  146. data/lib/synthra/loader_config.rb +78 -0
  147. data/lib/synthra/lsp/server.rb +689 -0
  148. data/lib/synthra/migration_generator.rb +301 -0
  149. data/lib/synthra/mixin.rb +174 -0
  150. data/lib/synthra/mock_server.rb +458 -0
  151. data/lib/synthra/native_engine.rb +304 -0
  152. data/lib/synthra/openapi_importer.rb +228 -0
  153. data/lib/synthra/output/json_formatter.rb +40 -0
  154. data/lib/synthra/output/ndjson_formatter.rb +55 -0
  155. data/lib/synthra/parser/ast.rb +1287 -0
  156. data/lib/synthra/parser/lexer.rb +1152 -0
  157. data/lib/synthra/parser/parser.rb +1664 -0
  158. data/lib/synthra/parser/tokens.rb +461 -0
  159. data/lib/synthra/performance_mode.rb +364 -0
  160. data/lib/synthra/personas.rb +397 -0
  161. data/lib/synthra/property_testing.rb +172 -0
  162. data/lib/synthra/quality_metrics.rb +405 -0
  163. data/lib/synthra/rails_test_helper.rb +248 -0
  164. data/lib/synthra/registry.rb +533 -0
  165. data/lib/synthra/relationships.rb +193 -0
  166. data/lib/synthra/repl/enhanced_repl.rb +607 -0
  167. data/lib/synthra/repl/formatter.rb +191 -0
  168. data/lib/synthra/scenarios.rb +423 -0
  169. data/lib/synthra/schema.rb +605 -0
  170. data/lib/synthra/schema_inheritance.rb +104 -0
  171. data/lib/synthra/schema_versioning.rb +212 -0
  172. data/lib/synthra/snapshot_testing.rb +199 -0
  173. data/lib/synthra/time_travel.rb +338 -0
  174. data/lib/synthra/type_definitions.rb +274 -0
  175. data/lib/synthra/types/address_location/addresses.rb +125 -0
  176. data/lib/synthra/types/address_location/airports.rb +200 -0
  177. data/lib/synthra/types/address_location/banks_hospitals.rb +207 -0
  178. data/lib/synthra/types/address_location/locations.rb +406 -0
  179. data/lib/synthra/types/base.rb +48 -0
  180. data/lib/synthra/types/commerce_products/commerce.rb +119 -0
  181. data/lib/synthra/types/commerce_products/companies.rb +71 -0
  182. data/lib/synthra/types/commerce_products/construction.rb +126 -0
  183. data/lib/synthra/types/commerce_products/products.rb +205 -0
  184. data/lib/synthra/types/core/collections.rb +513 -0
  185. data/lib/synthra/types/core/defaults.rb +76 -0
  186. data/lib/synthra/types/core/enums.rb +102 -0
  187. data/lib/synthra/types/core/identifiers.rb +445 -0
  188. data/lib/synthra/types/core/primitives.rb +586 -0
  189. data/lib/synthra/types/core/references.rb +466 -0
  190. data/lib/synthra/types/core/sequences.rb +304 -0
  191. data/lib/synthra/types/crypto/crypto.rb +162 -0
  192. data/lib/synthra/types/date_time/dates.rb +387 -0
  193. data/lib/synthra/types/finance_banking/banking.rb +424 -0
  194. data/lib/synthra/types/finance_banking/credit_cards.rb +24 -0
  195. data/lib/synthra/types/finance_banking/identifiers.rb +93 -0
  196. data/lib/synthra/types/formula.rb +184 -0
  197. data/lib/synthra/types/health_medical/medical.rb +150 -0
  198. data/lib/synthra/types/hostile_payloads.rb +122 -0
  199. data/lib/synthra/types/json_array.rb +51 -0
  200. data/lib/synthra/types/media_entertainment/media.rb +62 -0
  201. data/lib/synthra/types/naughty_string.rb +30 -0
  202. data/lib/synthra/types/personal_names/chinese.rb +41 -0
  203. data/lib/synthra/types/personal_names/identifiers.rb +187 -0
  204. data/lib/synthra/types/personal_names/names.rb +246 -0
  205. data/lib/synthra/types/personal_names/national_id.rb +89 -0
  206. data/lib/synthra/types/personal_names/titles_suffixes.rb +41 -0
  207. data/lib/synthra/types/regex.rb +248 -0
  208. data/lib/synthra/types/registry.rb +182 -0
  209. data/lib/synthra/types/repeating_element.rb +50 -0
  210. data/lib/synthra/types/scenario.rb +29 -0
  211. data/lib/synthra/types/technology_internet/apps.rb +67 -0
  212. data/lib/synthra/types/technology_internet/communication.rb +162 -0
  213. data/lib/synthra/types/technology_internet/devices.rb +80 -0
  214. data/lib/synthra/types/technology_internet/formats.rb +139 -0
  215. data/lib/synthra/types/technology_internet/networking.rb +143 -0
  216. data/lib/synthra/types/template.rb +92 -0
  217. data/lib/synthra/types/text_content/business.rb +128 -0
  218. data/lib/synthra/types/text_content/colors.rb +70 -0
  219. data/lib/synthra/types/text_content/misc.rb +237 -0
  220. data/lib/synthra/types/text_content/security.rb +130 -0
  221. data/lib/synthra/types/text_content/text_generation.rb +532 -0
  222. data/lib/synthra/types/travel/travel.rb +150 -0
  223. data/lib/synthra/utils/string_distance.rb +133 -0
  224. data/lib/synthra/validator/dsl_validator.rb +339 -0
  225. data/lib/synthra/validator/path_validator.rb +615 -0
  226. data/lib/synthra/version.rb +35 -0
  227. data/lib/synthra/webhook_simulator.rb +341 -0
  228. data/lib/synthra.rb +259 -0
  229. data/schemas/address.dsl +16 -0
  230. data/schemas/api_response.dsl +8 -0
  231. data/schemas/error_payload.dsl +9 -0
  232. data/schemas/order.dsl +10 -0
  233. data/schemas/order_item.dsl +8 -0
  234. data/schemas/payment.dsl +11 -0
  235. data/schemas/social_post.dsl +13 -0
  236. data/schemas/user.dsl +10 -0
  237. data/scripts/batch_fix_all.rb +96 -0
  238. data/scripts/delete_old_files.rb +32 -0
  239. data/scripts/fix_all_grouped_files.rb +137 -0
  240. data/scripts/fix_all_indentation.rb +48 -0
  241. data/scripts/fix_all_syntax.rb +124 -0
  242. data/scripts/fix_grouped_files.rb +184 -0
  243. data/scripts/fix_syntax_errors.rb +108 -0
  244. data/scripts/group_domain_types.rb +112 -0
  245. data/scripts/group_domain_types_fixed.rb +150 -0
  246. data/scripts/merge_domains_to_one_file.rb +68 -0
  247. data/scripts/move_existing_types.rb +130 -0
  248. data/scripts/split_grouped_types.rb +142 -0
  249. data/tech_docs/README.md +134 -0
  250. data/tech_docs/advanced/streaming.md +405 -0
  251. data/tech_docs/advanced/thread_safety.md +253 -0
  252. data/tech_docs/api/overview.md +485 -0
  253. data/tech_docs/appendices/type_chart.md +193 -0
  254. data/tech_docs/basic_concepts.md +383 -0
  255. data/tech_docs/behaviors/overview.md +346 -0
  256. data/tech_docs/dsl/complex_types.md +790 -0
  257. data/tech_docs/dsl/core_types.md +464 -0
  258. data/tech_docs/dsl/datetime_types.md +325 -0
  259. data/tech_docs/dsl/field_modifiers.md +414 -0
  260. data/tech_docs/dsl/grammar.md +431 -0
  261. data/tech_docs/dsl/schema_definition.md +399 -0
  262. data/tech_docs/export/README.md +276 -0
  263. data/tech_docs/installation.md +273 -0
  264. data/tech_docs/integration/ci_cd.md +707 -0
  265. data/tech_docs/integration/ci_cd_guide.md +579 -0
  266. data/tech_docs/integration/factory_bot.md +485 -0
  267. data/tech_docs/integration/rails.md +630 -0
  268. data/tech_docs/integration/rspec.md +449 -0
  269. data/tech_docs/modes/overview.md +350 -0
  270. data/tech_docs/performance/NATIVE_RUST_EXTENSION.md +1270 -0
  271. data/tech_docs/performance/OPTIMIZATION_GUIDE.md +901 -0
  272. data/tech_docs/quick_start.md +256 -0
  273. data/tech_docs/templates/README.md +805 -0
  274. data/tech_docs/tutorials/advanced.md +371 -0
  275. data/tech_docs/tutorials/getting_started.md +189 -0
  276. data/tech_docs/tutorials/intermediate.md +231 -0
  277. data/tech_docs/tutorials/template_gallery.md +569 -0
  278. data/tech_example/01_basic_usage.rb +238 -0
  279. data/tech_example/02_types_demo.rb +336 -0
  280. data/tech_example/04_cli_usage.md +429 -0
  281. data/tech_example/05_database_seeding.rb +283 -0
  282. data/tech_example/07_rspec_integration.rb +359 -0
  283. data/tech_example/10_custom_types.rb +387 -0
  284. data/tech_example/12_behaviors.rb +372 -0
  285. data/tech_example/13_twitter_dm_example.rb +120 -0
  286. data/tech_example/14_exact_json_structure.rb +253 -0
  287. data/tech_example/16_lsp_server.rb +56 -0
  288. data/tech_example/17_property_testing.rb +92 -0
  289. data/tech_example/18_enhanced_repl.rb +120 -0
  290. data/tech_example/19_security_fuzzing.rb +145 -0
  291. data/tech_example/NEW_FEATURES.md +169 -0
  292. data/tech_example/README.md +118 -0
  293. data/tech_example/schemas/api_response.dsl +123 -0
  294. data/tech_example/schemas/ecommerce.dsl +121 -0
  295. data/tech_example/schemas/twitter_dm.dsl +109 -0
  296. data/tech_example/schemas/user.dsl +36 -0
  297. data/vscode-extension/README.md +246 -0
  298. data/vscode-extension/language-configuration.json +31 -0
  299. data/vscode-extension/package.json +55 -0
  300. data/vscode-extension/snippets/fakedatadsl.json +198 -0
  301. data/vscode-extension/syntaxes/fakedatadsl.tmLanguage.json +128 -0
  302. metadata +478 -0
@@ -0,0 +1,454 @@
1
+ # Rails Integration Guide
2
+
3
+ This guide shows how to integrate FakeDataDSL into your Rails application for frontend mocks, backend testing, and DevOps pipelines.
4
+
5
+ ## Installation
6
+
7
+ Add to your Gemfile:
8
+
9
+ ```ruby
10
+ # Gemfile
11
+ group :development, :test do
12
+ gem 'fake_data_dsl'
13
+ end
14
+ ```
15
+
16
+ ## Directory Structure
17
+
18
+ Create the standard schema directory:
19
+
20
+ ```
21
+ your_rails_app/
22
+ ├── app/
23
+ ├── config/
24
+ │ └── fake_data_dsl.yml # Configuration
25
+ ├── schemas/ # DSL schemas
26
+ │ ├── user.dsl
27
+ │ ├── product.dsl
28
+ │ ├── order.dsl
29
+ │ └── api_response.dsl
30
+ ├── generated/ # Generated outputs
31
+ │ ├── types/ # TypeScript types for frontend
32
+ │ ├── mocks/ # JSON mock data
33
+ │ └── docs/ # HTML documentation
34
+ └── spec/
35
+ └── schemas/ # Schema-specific tests
36
+ ```
37
+
38
+ ## Configuration
39
+
40
+ ```yaml
41
+ # config/fake_data_dsl.yml
42
+ default_mode: random
43
+ max_unique_retries: 1000
44
+
45
+ limits:
46
+ max_array_size: 100
47
+ max_recursion: 5
48
+
49
+ test:
50
+ default_mode: edge # Use edge cases in tests
51
+ seed: 42 # Deterministic in CI
52
+
53
+ development:
54
+ default_mode: random
55
+
56
+ production:
57
+ # Production shouldn't use this gem
58
+ ```
59
+
60
+ ## Schema Examples
61
+
62
+ ### User Schema
63
+ ```
64
+ # schemas/user.dsl
65
+ User:
66
+ id: uuid(unique: true)
67
+ email: email(unique: true)
68
+ name: name
69
+ role: enum(admin, user, guest)
70
+ created_at: timestamp
71
+ updated_at: timestamp
72
+ ```
73
+
74
+ ### API Response Schema
75
+ ```
76
+ # schemas/api_response.dsl
77
+ APIResponse:
78
+ @latency 50..200ms # Simulate network latency
79
+ @failure 2% # 2% chance of failure
80
+
81
+ success: boolean(true:95%)
82
+ data: object
83
+ meta:
84
+ page: number(1..100)
85
+ per_page: const(20)
86
+ total: number(0..10000)
87
+ timestamp: now
88
+ ```
89
+
90
+ ### E-Commerce Schemas
91
+ ```
92
+ # schemas/product.dsl
93
+ Product:
94
+ id: uuid(unique: true)
95
+ name: text(10..100)
96
+ description: text(50..500)
97
+ price: money(range: 9.99..999.99)
98
+ currency: enum(USD, EUR, GBP)
99
+ category: enum(electronics, clothing, home, sports)
100
+ in_stock: boolean(true:85%)
101
+ images: array(url, 1..5)
102
+
103
+ # schemas/order.dsl
104
+ Order:
105
+ id: uuid(unique: true)
106
+ user_id: Ref(User.id)
107
+ items: array(OrderItem, 1..10)
108
+ subtotal: money(range: 10..5000)
109
+ tax: custom(:calculate_tax)
110
+ total: custom(:calculate_total)
111
+ status: enum(pending, processing, shipped, delivered, cancelled)
112
+ created_at: timestamp
113
+
114
+ OrderItem:
115
+ product_id: Ref(Product.id)
116
+ quantity: number(1..10)
117
+ unit_price: money(range: 9.99..999.99)
118
+ ```
119
+
120
+ ---
121
+
122
+ ## Frontend Integration
123
+
124
+ ### Generate TypeScript Types
125
+
126
+ ```bash
127
+ # Generate all types
128
+ fake_data_dsl export --all -d schemas -f typescript -o frontend/src/types/api.ts
129
+ ```
130
+
131
+ Output:
132
+ ```typescript
133
+ // frontend/src/types/api.ts
134
+ export interface User {
135
+ id: string;
136
+ email: string;
137
+ name: string;
138
+ role: 'admin' | 'user' | 'guest';
139
+ created_at: string;
140
+ updated_at: string;
141
+ }
142
+
143
+ export interface Product {
144
+ id: string;
145
+ name: string;
146
+ description: string;
147
+ price: number;
148
+ currency: 'USD' | 'EUR' | 'GBP';
149
+ category: 'electronics' | 'clothing' | 'home' | 'sports';
150
+ in_stock: boolean;
151
+ images: string[];
152
+ }
153
+ ```
154
+
155
+ ### Generate Mock Data
156
+
157
+ ```bash
158
+ # Generate mock users
159
+ fake_data_dsl generate User -d schemas -c 50 --pretty > frontend/mocks/users.json
160
+
161
+ # Generate with seed for deterministic mocks
162
+ fake_data_dsl generate User -d schemas -c 50 --seed 42 --pretty > frontend/mocks/users.json
163
+ ```
164
+
165
+ ### Live Mock Server (Development)
166
+
167
+ ```bash
168
+ # Start live preview with hot reload
169
+ fake_data_dsl live schemas/ --port 4567
170
+ ```
171
+
172
+ Access `http://localhost:4567` for interactive mock generation.
173
+
174
+ ---
175
+
176
+ ## Backend Integration
177
+
178
+ ### RSpec Setup
179
+
180
+ ```ruby
181
+ # spec/support/fake_data_dsl.rb
182
+ require 'fake_data_dsl'
183
+ require 'fake_data_dsl/rails_test_helper'
184
+
185
+ RSpec.configure do |config|
186
+ config.include FakeDataDSL::RailsTestHelper
187
+
188
+ # Load schemas once
189
+ config.before(:suite) do
190
+ FakeDataDSL.configure_test_helper!
191
+ end
192
+ end
193
+ ```
194
+
195
+ ### Using in Tests
196
+
197
+ ```ruby
198
+ # spec/models/user_spec.rb
199
+ RSpec.describe User do
200
+ describe 'validations' do
201
+ it 'validates with generated data' do
202
+ user_data = generate_for_test(User)
203
+ user = User.new(user_data)
204
+ expect(user).to be_valid
205
+ end
206
+
207
+ it 'tests edge cases' do
208
+ user_data = generate_for_test(User, :edge)
209
+ # Edge cases like empty strings, boundary values, etc.
210
+ end
211
+
212
+ it 'handles invalid data gracefully' do
213
+ user_data = generate_for_test(User, :invalid)
214
+ user = User.new(user_data)
215
+ expect(user).not_to be_valid
216
+ end
217
+ end
218
+ end
219
+ ```
220
+
221
+ ### Snapshot Testing
222
+
223
+ ```ruby
224
+ # spec/schemas/user_schema_spec.rb
225
+ RSpec.describe 'User Schema' do
226
+ include FakeDataDSL::SnapshotTesting
227
+
228
+ it 'generates stable output' do
229
+ schema = FakeDataDSL.load('schemas/user.dsl')
230
+ expect_snapshot(schema, seed: 42)
231
+ end
232
+ end
233
+ ```
234
+
235
+ ### Database Seeding
236
+
237
+ ```ruby
238
+ # db/seeds.rb
239
+ require 'fake_data_dsl'
240
+
241
+ FakeDataDSL.seed_database do
242
+ create User, count: 100
243
+ create Product, count: 500
244
+ create Order, count: 1000
245
+ end
246
+ ```
247
+
248
+ Or with Rake task:
249
+
250
+ ```ruby
251
+ # lib/tasks/seed_fake_data.rake
252
+ namespace :db do
253
+ desc 'Seed database with fake data'
254
+ task seed_fake: :environment do
255
+ FakeDataDSL.seed_database(truncate: Rails.env.development?) do
256
+ create User, count: ENV.fetch('USER_COUNT', 100).to_i
257
+ create Product, count: ENV.fetch('PRODUCT_COUNT', 500).to_i
258
+ create Order, count: ENV.fetch('ORDER_COUNT', 1000).to_i
259
+ end
260
+ end
261
+ end
262
+ ```
263
+
264
+ ---
265
+
266
+ ## DevOps Integration
267
+
268
+ ### GitHub Actions CI
269
+
270
+ ```yaml
271
+ # .github/workflows/schema-ci.yml
272
+ name: Schema CI
273
+
274
+ on: [push, pull_request]
275
+
276
+ jobs:
277
+ validate:
278
+ runs-on: ubuntu-latest
279
+ steps:
280
+ - uses: actions/checkout@v4
281
+
282
+ - name: Set up Ruby
283
+ uses: ruby/setup-ruby@v1
284
+ with:
285
+ ruby-version: '3.2'
286
+ bundler-cache: true
287
+
288
+ - name: Validate schemas
289
+ run: bundle exec fake_data_dsl lint schemas/ --strict
290
+
291
+ - name: Check for breaking changes
292
+ if: github.event_name == 'pull_request'
293
+ run: |
294
+ git fetch origin ${{ github.base_ref }}
295
+ bundle exec fake_data_dsl diff \
296
+ schemas/ \
297
+ origin/${{ github.base_ref }}:schemas/ \
298
+ --breaking-only
299
+
300
+ - name: Generate documentation
301
+ run: bundle exec fake_data_dsl docs schemas/ --output docs/schemas/
302
+
303
+ - name: Upload docs artifact
304
+ uses: actions/upload-artifact@v3
305
+ with:
306
+ name: schema-docs
307
+ path: docs/schemas/
308
+ ```
309
+
310
+ ### Pre-commit Hook
311
+
312
+ ```bash
313
+ #!/bin/bash
314
+ # .git/hooks/pre-commit
315
+
316
+ # Validate schemas before commit
317
+ if ! bundle exec fake_data_dsl lint schemas/ --strict; then
318
+ echo "❌ Schema validation failed"
319
+ exit 1
320
+ fi
321
+
322
+ echo "✅ Schemas valid"
323
+ ```
324
+
325
+ ### Docker Integration
326
+
327
+ ```dockerfile
328
+ # Dockerfile.dev
329
+ FROM ruby:3.2
330
+
331
+ # Install fake_data_dsl globally for CLI access
332
+ RUN gem install fake_data_dsl
333
+
334
+ # Your app setup...
335
+ WORKDIR /app
336
+ COPY . .
337
+
338
+ # Generate mocks at build time
339
+ RUN fake_data_dsl generate User -d schemas -c 100 > mocks/users.json
340
+ ```
341
+
342
+ ---
343
+
344
+ ## API Mock Server
345
+
346
+ For a full mock API server, use the Live Preview or create a simple Sinatra app:
347
+
348
+ ```ruby
349
+ # mock_server.rb
350
+ require 'sinatra'
351
+ require 'fake_data_dsl'
352
+
353
+ registry = FakeDataDSL::Registry.new
354
+ registry.load_dir('schemas')
355
+
356
+ get '/api/users' do
357
+ content_type :json
358
+ schema = registry.schema('User')
359
+ count = params[:count]&.to_i || 10
360
+ schema.generate_many(count).to_json
361
+ end
362
+
363
+ get '/api/users/:id' do
364
+ content_type :json
365
+ schema = registry.schema('User')
366
+ schema.generate(overrides: { 'id' => params[:id] }).to_json
367
+ end
368
+
369
+ get '/api/products' do
370
+ content_type :json
371
+ schema = registry.schema('Product')
372
+ schema.generate_many(params[:count]&.to_i || 20).to_json
373
+ end
374
+
375
+ # Run: ruby mock_server.rb
376
+ ```
377
+
378
+ ---
379
+
380
+ ## Common Patterns
381
+
382
+ ### Pattern 1: Environment-specific Data
383
+
384
+ ```ruby
385
+ # Generate different data per environment
386
+ mode = case Rails.env
387
+ when 'test' then :edge
388
+ when 'development' then :random
389
+ else :random
390
+ end
391
+
392
+ schema.generate(mode: mode)
393
+ ```
394
+
395
+ ### Pattern 2: Factory Bot Bridge
396
+
397
+ ```ruby
398
+ # spec/factories.rb
399
+ FakeDataDSL.define_factory(:user, schema: 'User') do
400
+ trait(:admin) { role { 'admin' } }
401
+ trait(:guest) { role { 'guest' } }
402
+ end
403
+
404
+ # Usage
405
+ create(:user, :admin)
406
+ ```
407
+
408
+ ### Pattern 3: GraphQL Mocks
409
+
410
+ ```bash
411
+ # Generate GraphQL schema
412
+ fake_data_dsl export --all -d schemas -f graphql -o graphql/mocks.graphql
413
+ ```
414
+
415
+ ### Pattern 4: Import from OpenAPI
416
+
417
+ ```bash
418
+ # Convert existing OpenAPI spec to DSL
419
+ fake_data_dsl import swagger.yaml --output schemas/
420
+ ```
421
+
422
+ ---
423
+
424
+ ## Troubleshooting
425
+
426
+ ### Schema not found
427
+ ```bash
428
+ # Check available schemas
429
+ fake_data_dsl info schemas/
430
+ ```
431
+
432
+ ### Breaking change detected in CI
433
+ ```bash
434
+ # See detailed diff
435
+ fake_data_dsl diff schemas/old/ schemas/new/
436
+ ```
437
+
438
+ ### Slow generation
439
+ ```ruby
440
+ # Use native Rust engine for millions of records
441
+ schema.generate_many(1_000_000, engine: :native, threads: 4)
442
+ ```
443
+
444
+ ---
445
+
446
+ ## Next Steps
447
+
448
+ 1. **Create schemas** for your domain models
449
+ 2. **Set up CI** with schema validation
450
+ 3. **Generate TypeScript types** for frontend
451
+ 4. **Configure test helpers** for RSpec/Minitest
452
+ 5. **Set up mock server** for frontend development
453
+
454
+ For more examples, see the [tech_example/](../tech_example/) directory.
data/docs/README.md ADDED
@@ -0,0 +1,175 @@
1
+ # FakeDataDSL Documentation
2
+
3
+ Welcome to the FakeDataDSL documentation! This directory contains comprehensive guides and references for using the FakeDataDSL gem.
4
+
5
+ ## 📚 Quick Access
6
+
7
+ ### After Generating YARD Docs
8
+
9
+ Once you've run `bundle exec yard doc`, access documentation via:
10
+
11
+ 1. **Documentation Index** (Recommended):
12
+ ```bash
13
+ open docs/index.html
14
+ ```
15
+ Or if copied to doc folder:
16
+ ```bash
17
+ open doc/docs_index.html
18
+ ```
19
+
20
+ 2. **YARD File List**:
21
+ ```bash
22
+ open doc/file_list.html
23
+ ```
24
+ Then click on any guide (files starting with `file.`)
25
+
26
+ 3. **Direct Links**:
27
+ ```bash
28
+ open doc/file.getting_started.html
29
+ open doc/file.dsl_reference.html
30
+ open doc/file.type_reference.html
31
+ ```
32
+
33
+ ## 📖 Documentation Files
34
+
35
+ ### Getting Started
36
+ - **[Getting Started](getting_started.md)** - Quick start guide for new users
37
+ - **[Usage Guide](USAGE_GUIDE.md)** - Complete guide: DSL, types, formula, unique, options
38
+ - **[Quick Reference](QUICK_REFERENCE.md)** - Quick reference card
39
+
40
+ ### Reference Guides
41
+ - **[DSL Reference](dsl_reference.md)** - Complete DSL syntax reference
42
+ - **[Type Reference](type_reference.md)** - All available data types
43
+ - **[API Reference](api_reference.md)** - Programmatic API documentation
44
+
45
+ ### Feature Guides
46
+ - **[Behaviors Guide](behaviors.md)** - Using behaviors (latency, failure, etc.)
47
+ - **[Generation Modes](generation_modes.md)** - Random, edge, invalid, mixed modes
48
+ - **[Advanced Features](advanced_features.md)** - References, custom functions, streaming
49
+
50
+ ### Integration & Export
51
+ - **[Factory Bot Integration](FACTORY_BOT.md)** - Bridge to Factory Bot for test data
52
+ - **[Rails Integration](RAILS_INTEGRATION.md)** - Rails-specific features
53
+ - **[Config File Guide](CONFIG_FILE.md)** - YAML configuration reference
54
+ - **[LSP Server](LSP.md)** - IDE integration
55
+ - **[Native Engine](NATIVE_ENGINE.md)** - High-performance Rust engine
56
+
57
+ ### Export Formats
58
+ - **[GraphQL Export](GRAPHQL_EXPORT.md)** - Standard GraphQL SDL export
59
+ - **[OpenAPI Export](OPENAPI_EXPORT.md)** - Export to OpenAPI 3.0 specs
60
+ - **[Protobuf Export](PROTOBUF_EXPORT.md)** - Generate .proto files for microservices
61
+
62
+ ### Testing
63
+ - **[Property-Based Testing](PROPERTY_TESTING.md)** - RSpec property verification
64
+ - **[Snapshot Testing](SNAPSHOT_TESTING.md)** - Detect schema changes in CI
65
+ - **[Security Testing](SECURITY_TESTING.md)** - Hostile mode for security fuzzing
66
+ - **[Enhanced REPL](ENHANCED_REPL.md)** - Visual inspection and debugging
67
+ - **[REPL Quick Reference](REPL_QUICK_REFERENCE.md)** - REPL commands cheat sheet
68
+
69
+ ### Production Features
70
+ - **[API Server](API_SERVER.md)** - REST API for production use
71
+ - **[Mock Server](MOCK_SERVER.md)** - Record & replay mock responses
72
+ - **[Data Contracts](DATA_CONTRACTS.md)** - Schema versioning registry
73
+ - **[Performance Mode](PERFORMANCE_MODE.md)** - Generate millions of records
74
+
75
+ ### Rails-Level Features 🚀 NEW
76
+ - **[Rails Engine](RAILS_ENGINE.md)** - Zero-config Rails integration with auto-discovery
77
+ - **[ActiveRecord Inference](ACTIVERECORD_INFERENCE.md)** - Generate schemas from your ActiveRecord models
78
+ - **[Scenarios](SCENARIOS.md)** - Complex test data fixtures with relationships
79
+ - **[Time Travel](TIME_TRAVEL.md)** - Generate historical/time-series data
80
+ - **[Personas](PERSONAS.md)** - Named data profiles (happy_path, edge_cases, etc.)
81
+ - **[Quality Metrics](QUALITY_METRICS.md)** - Analyze data realism and distribution
82
+ - **[GraphQL Federation](GRAPHQL_FEDERATION.md)** - Apollo Federation v2 export
83
+ - **[Webhook Simulator](WEBHOOK_SIMULATOR.md)** - Test Stripe, GitHub, Twilio webhooks
84
+ - **[Migration Generator](MIGRATION_GENERATOR.md)** - Generate Rails migrations from schemas
85
+ - **[Terraform Export](TERRAFORM_EXPORT.md)** - Generate AWS/GCP infrastructure code
86
+ - **[GitHub Action](GITHUB_ACTION.md)** - CI/CD integration for schema validation
87
+
88
+ ### Examples & Best Practices
89
+ - **[Examples](examples.md)** - Real-world usage examples
90
+ - **[Best Practices](best_practices.md)** - Tips and recommendations
91
+ - **[Troubleshooting](troubleshooting.md)** - Common issues and solutions
92
+
93
+ ### Additional Resources
94
+ - **[How to Generate Docs](HOW_TO_GENERATE_DOCS.md)** - Documentation generation guide
95
+ - **[Rust Integration Guide](RUST_INTEGRATION_GUIDE.md)** - Native Rust engine details
96
+
97
+ ## 🔄 Generating Documentation
98
+
99
+ ```bash
100
+ # Generate YARD documentation (includes all markdown files)
101
+ bundle exec yard doc
102
+
103
+ # View documentation
104
+ open doc/index.html
105
+ ```
106
+
107
+ ## 📝 File Structure
108
+
109
+ ```
110
+ docs/
111
+ ├── README.md # This file
112
+ ├── getting_started.md # Quick start
113
+ ├── dsl_reference.md # DSL syntax
114
+ ├── type_reference.md # All types
115
+ ├── behaviors.md # Behaviors guide
116
+ ├── generation_modes.md # Generation modes
117
+ ├── advanced_features.md # Advanced topics
118
+ ├── examples.md # Usage examples
119
+ ├── api_reference.md # API docs
120
+ ├── best_practices.md # Best practices
121
+ ├── troubleshooting.md # Troubleshooting
122
+ ├── QUICK_REFERENCE.md # Quick reference
123
+ ├── HOW_TO_GENERATE_DOCS.md # Doc generation guide
124
+
125
+ ├── # Integration
126
+ ├── FACTORY_BOT.md # Factory Bot integration
127
+ ├── RAILS_INTEGRATION.md # Rails features
128
+ ├── CONFIG_FILE.md # YAML configuration
129
+ ├── LSP.md # IDE integration
130
+ ├── NATIVE_ENGINE.md # Rust engine
131
+
132
+ ├── # Export Formats
133
+ ├── GRAPHQL_EXPORT.md # GraphQL SDL
134
+ ├── OPENAPI_EXPORT.md # OpenAPI 3.0
135
+ ├── PROTOBUF_EXPORT.md # Protocol Buffers
136
+
137
+ ├── # Testing
138
+ ├── PROPERTY_TESTING.md # Property-based testing
139
+ ├── SNAPSHOT_TESTING.md # Snapshot testing
140
+ ├── SECURITY_TESTING.md # Security testing
141
+ ├── ENHANCED_REPL.md # REPL debugging
142
+ ├── REPL_QUICK_REFERENCE.md # REPL cheat sheet
143
+
144
+ ├── # Production
145
+ ├── API_SERVER.md # REST API server
146
+ ├── MOCK_SERVER.md # Mock server
147
+ ├── DATA_CONTRACTS.md # Schema versioning
148
+ ├── PERFORMANCE_MODE.md # High-performance generation
149
+
150
+ ├── # Rails-Level Features (NEW)
151
+ ├── RAILS_ENGINE.md # Rails Engine
152
+ ├── ACTIVERECORD_INFERENCE.md # Model inference
153
+ ├── SCENARIOS.md # Test scenarios
154
+ ├── TIME_TRAVEL.md # Time travel
155
+ ├── PERSONAS.md # Data personas
156
+ ├── QUALITY_METRICS.md # Quality analysis
157
+ ├── GRAPHQL_FEDERATION.md # GraphQL Federation
158
+ ├── WEBHOOK_SIMULATOR.md # Webhook simulation
159
+ ├── MIGRATION_GENERATOR.md # Migration generation
160
+ ├── TERRAFORM_EXPORT.md # Terraform/IaC
161
+ ├── GITHUB_ACTION.md # GitHub Action
162
+
163
+ └── index.html # Documentation hub (HTML)
164
+ ```
165
+
166
+ ## 🔗 Links
167
+
168
+ - [Project README](../README.md)
169
+ - [YARD API Documentation](../doc/index.html)
170
+ - [GitHub Repository](https://github.com/talaatmagdyx/fake_data_dsl)
171
+ - [Issue Tracker](https://github.com/talaatmagdyx/fake_data_dsl/issues)
172
+
173
+ ## Contributing
174
+
175
+ See [CONTRIBUTING.md](../CONTRIBUTING.md) for guidelines on contributing to FakeDataDSL.