magic_model_generator 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (300) hide show
  1. data/CHANGELOG +0 -0
  2. data/README +3 -0
  3. data/Rakefile +96 -0
  4. data/examples/singleview/account.rb +94 -0
  5. data/examples/singleview/account_history.rb +21 -0
  6. data/examples/singleview/account_reservation.rb +26 -0
  7. data/examples/singleview/account_type.rb +54 -0
  8. data/examples/singleview/account_type_aging.rb +17 -0
  9. data/examples/singleview/account_type_variable.rb +8 -0
  10. data/examples/singleview/address.rb +8 -0
  11. data/examples/singleview/address_format.rb +49 -0
  12. data/examples/singleview/address_history.rb +28 -0
  13. data/examples/singleview/adjustment.rb +97 -0
  14. data/examples/singleview/adjustment_batch.rb +42 -0
  15. data/examples/singleview/adjustment_invoice.rb +17 -0
  16. data/examples/singleview/adjustment_type.rb +54 -0
  17. data/examples/singleview/adjustment_type_variable.rb +8 -0
  18. data/examples/singleview/archive_lock_t.rb +11 -0
  19. data/examples/singleview/archive_result.rb +15 -0
  20. data/examples/singleview/archive_type.rb +31 -0
  21. data/examples/singleview/archive_type_table_list.rb +15 -0
  22. data/examples/singleview/atai_error_name.rb +7 -0
  23. data/examples/singleview/atlanta_form.rb +23 -0
  24. data/examples/singleview/atlanta_form_field.rb +12 -0
  25. data/examples/singleview/atlanta_group.rb +285 -0
  26. data/examples/singleview/atlanta_help_entry.rb +32 -0
  27. data/examples/singleview/atlanta_operator.rb +356 -0
  28. data/examples/singleview/atlanta_profile.rb +47 -0
  29. data/examples/singleview/atlanta_profile_func_map.rb +8 -0
  30. data/examples/singleview/atlanta_profile_group_map.rb +10 -0
  31. data/examples/singleview/atlanta_profile_role_map.rb +8 -0
  32. data/examples/singleview/atlanta_profile_wf_map.rb +10 -0
  33. data/examples/singleview/atlanta_role.rb +23 -0
  34. data/examples/singleview/atlanta_table_partition.rb +39 -0
  35. data/examples/singleview/attribute_type.rb +75 -0
  36. data/examples/singleview/attribute_type_variable.rb +8 -0
  37. data/examples/singleview/bill_run.rb +93 -0
  38. data/examples/singleview/bill_run_operation.rb +54 -0
  39. data/examples/singleview/bill_run_type.rb +39 -0
  40. data/examples/singleview/bill_run_type_status.rb +12 -0
  41. data/examples/singleview/bill_run_type_task.rb +12 -0
  42. data/examples/singleview/cache.rb +23 -0
  43. data/examples/singleview/cache_field.rb +13 -0
  44. data/examples/singleview/can_act_charge.rb +16 -0
  45. data/examples/singleview/charge.rb +67 -0
  46. data/examples/singleview/charge_category.rb +45 -0
  47. data/examples/singleview/charge_output_defn.rb +13 -0
  48. data/examples/singleview/charge_output_defn_history.rb +22 -0
  49. data/examples/singleview/charge_output_defn_var.rb +10 -0
  50. data/examples/singleview/configuration_attr_type.rb +22 -0
  51. data/examples/singleview/configuration_attribute.rb +11 -0
  52. data/examples/singleview/configuration_item.rb +26 -0
  53. data/examples/singleview/configuration_item_type.rb +29 -0
  54. data/examples/singleview/contract.rb +35 -0
  55. data/examples/singleview/contract_history.rb +48 -0
  56. data/examples/singleview/contract_type.rb +58 -0
  57. data/examples/singleview/contract_type_product.rb +11 -0
  58. data/examples/singleview/conversion_rate.rb +14 -0
  59. data/examples/singleview/currency.rb +118 -0
  60. data/examples/singleview/currency_history.rb +28 -0
  61. data/examples/singleview/customer_contact.rb +12 -0
  62. data/examples/singleview/customer_node.rb +166 -0
  63. data/examples/singleview/customer_node_bill_run.rb +12 -0
  64. data/examples/singleview/customer_node_charge_cat.rb +22 -0
  65. data/examples/singleview/customer_node_correspond.rb +12 -0
  66. data/examples/singleview/customer_node_da.rb +11 -0
  67. data/examples/singleview/customer_node_da_array.rb +35 -0
  68. data/examples/singleview/customer_node_history.rb +86 -0
  69. data/examples/singleview/customer_node_inv_format.rb +33 -0
  70. data/examples/singleview/customer_node_type.rb +89 -0
  71. data/examples/singleview/customer_node_type_cc.rb +18 -0
  72. data/examples/singleview/customer_node_type_da.rb +8 -0
  73. data/examples/singleview/customer_node_type_var.rb +8 -0
  74. data/examples/singleview/customer_query.rb +80 -0
  75. data/examples/singleview/customer_query_progress.rb +20 -0
  76. data/examples/singleview/customer_query_type.rb +49 -0
  77. data/examples/singleview/customer_query_type_var.rb +8 -0
  78. data/examples/singleview/delete_cascade.rb +13 -0
  79. data/examples/singleview/delete_cascade_group.rb +21 -0
  80. data/examples/singleview/delete_constraint.rb +9 -0
  81. data/examples/singleview/derived_attribute.rb +32 -0
  82. data/examples/singleview/derived_attribute_array.rb +32 -0
  83. data/examples/singleview/derived_attribute_history.rb +41 -0
  84. data/examples/singleview/derived_attribute_index.rb +13 -0
  85. data/examples/singleview/derived_attribute_value.rb +19 -0
  86. data/examples/singleview/dil.rb +18 -0
  87. data/examples/singleview/dil_history.rb +24 -0
  88. data/examples/singleview/dil_reference.rb +9 -0
  89. data/examples/singleview/dil_validation_t.rb +6 -0
  90. data/examples/singleview/dil_variable.rb +10 -0
  91. data/examples/singleview/dunning_t.rb +14 -0
  92. data/examples/singleview/entity_mapping.rb +11 -0
  93. data/examples/singleview/entity_remap.rb +22 -0
  94. data/examples/singleview/entity_validation.rb +70 -0
  95. data/examples/singleview/entity_validation_list.rb +15 -0
  96. data/examples/singleview/entity_validation_variable.rb +8 -0
  97. data/examples/singleview/equipment.rb +28 -0
  98. data/examples/singleview/equipment_history.rb +62 -0
  99. data/examples/singleview/equipment_type.rb +57 -0
  100. data/examples/singleview/equipment_type_variable.rb +8 -0
  101. data/examples/singleview/error_group.rb +18 -0
  102. data/examples/singleview/error_message.rb +65 -0
  103. data/examples/singleview/evs_address_equiv.rb +17 -0
  104. data/examples/singleview/evs_alias.rb +12 -0
  105. data/examples/singleview/evs_attribute_type_key.rb +7 -0
  106. data/examples/singleview/evt_equipment_changeover.rb +9 -0
  107. data/examples/singleview/expression_list.rb +27 -0
  108. data/examples/singleview/expression_list_value.rb +17 -0
  109. data/examples/singleview/fac_group_compatibility.rb +11 -0
  110. data/examples/singleview/fac_group_instance.rb +19 -0
  111. data/examples/singleview/fac_group_instance_hist.rb +16 -0
  112. data/examples/singleview/facility.rb +9 -0
  113. data/examples/singleview/facility_group.rb +21 -0
  114. data/examples/singleview/facility_group_history.rb +21 -0
  115. data/examples/singleview/foreign_key.rb +9 -0
  116. data/examples/singleview/function_defn.rb +16 -0
  117. data/examples/singleview/function_defn_history.rb +35 -0
  118. data/examples/singleview/function_role.rb +24 -0
  119. data/examples/singleview/function_role_map.rb +10 -0
  120. data/examples/singleview/gl_code.rb +65 -0
  121. data/examples/singleview/gl_code_history.rb +20 -0
  122. data/examples/singleview/gl_upload.rb +10 -0
  123. data/examples/singleview/icon.rb +64 -0
  124. data/examples/singleview/inv_loop_t.rb +4 -0
  125. data/examples/singleview/inv_report_accounts_t.rb +25 -0
  126. data/examples/singleview/invoice.rb +134 -0
  127. data/examples/singleview/invoice_contents.rb +14 -0
  128. data/examples/singleview/invoice_format.rb +31 -0
  129. data/examples/singleview/invoice_format_history.rb +29 -0
  130. data/examples/singleview/invoice_message.rb +17 -0
  131. data/examples/singleview/invoice_message_history.rb +31 -0
  132. data/examples/singleview/invoice_message_variable.rb +10 -0
  133. data/examples/singleview/invoice_receivable_type.rb +13 -0
  134. data/examples/singleview/invoice_type.rb +23 -0
  135. data/examples/singleview/invoice_type_history.rb +26 -0
  136. data/examples/singleview/invoice_type_variable.rb +10 -0
  137. data/examples/singleview/isp_email_address.rb +17 -0
  138. data/examples/singleview/licence_current_values.rb +12 -0
  139. data/examples/singleview/menu_role_map.rb +10 -0
  140. data/examples/singleview/normalised_event.rb +119 -0
  141. data/examples/singleview/normalised_event_error.rb +91 -0
  142. data/examples/singleview/normalised_event_file.rb +75 -0
  143. data/examples/singleview/normalised_event_ft.rb +18 -0
  144. data/examples/singleview/normalised_event_ft_hist.rb +25 -0
  145. data/examples/singleview/normalised_event_ft_var.rb +10 -0
  146. data/examples/singleview/normalised_event_type.rb +54 -0
  147. data/examples/singleview/output_device.rb +37 -0
  148. data/examples/singleview/output_method.rb +32 -0
  149. data/examples/singleview/output_method_type.rb +38 -0
  150. data/examples/singleview/output_select.rb +17 -0
  151. data/examples/singleview/payment.rb +102 -0
  152. data/examples/singleview/payment_batch.rb +43 -0
  153. data/examples/singleview/payment_invoice.rb +17 -0
  154. data/examples/singleview/payment_item.rb +15 -0
  155. data/examples/singleview/payment_type.rb +57 -0
  156. data/examples/singleview/payment_type_variable.rb +8 -0
  157. data/examples/singleview/person.rb +60 -0
  158. data/examples/singleview/person_history.rb +69 -0
  159. data/examples/singleview/person_type.rb +39 -0
  160. data/examples/singleview/plan_table.rb +27 -0
  161. data/examples/singleview/product.rb +45 -0
  162. data/examples/singleview/product_compatibility.rb +13 -0
  163. data/examples/singleview/product_derived_attribute.rb +10 -0
  164. data/examples/singleview/product_facility_group.rb +16 -0
  165. data/examples/singleview/product_group.rb +12 -0
  166. data/examples/singleview/product_group_history.rb +20 -0
  167. data/examples/singleview/product_history.rb +35 -0
  168. data/examples/singleview/product_in_product_group.rb +12 -0
  169. data/examples/singleview/product_instance.rb +41 -0
  170. data/examples/singleview/product_instance_equip.rb +21 -0
  171. data/examples/singleview/product_instance_history.rb +37 -0
  172. data/examples/singleview/product_instance_service.rb +17 -0
  173. data/examples/singleview/product_payment_item.rb +19 -0
  174. data/examples/singleview/product_service_type.rb +32 -0
  175. data/examples/singleview/product_service_type_equip.rb +20 -0
  176. data/examples/singleview/product_subtotal.rb +14 -0
  177. data/examples/singleview/product_tariff.rb +16 -0
  178. data/examples/singleview/racr_clec_t1.rb +12 -0
  179. data/examples/singleview/racr_clec_t2.rb +12 -0
  180. data/examples/singleview/racr_clec_t3.rb +28 -0
  181. data/examples/singleview/racr_t.rb +29 -0
  182. data/examples/singleview/ragd_clec_t.rb +47 -0
  183. data/examples/singleview/ragd_t.rb +28 -0
  184. data/examples/singleview/rapc_t.rb +27 -0
  185. data/examples/singleview/rdfd_cmn_t.rb +17 -0
  186. data/examples/singleview/rdfd_t.rb +16 -0
  187. data/examples/singleview/receivable_type.rb +49 -0
  188. data/examples/singleview/receivable_type_history.rb +25 -0
  189. data/examples/singleview/reference_code.rb +17 -0
  190. data/examples/singleview/reference_type.rb +32 -0
  191. data/examples/singleview/release_info.rb +10 -0
  192. data/examples/singleview/report_reference_type.rb +14 -0
  193. data/examples/singleview/report_reference_type_defs.rb +12 -0
  194. data/examples/singleview/reprocessed_file.rb +32 -0
  195. data/examples/singleview/rgp_file.rb +22 -0
  196. data/examples/singleview/rgp_normalised_event.rb +78 -0
  197. data/examples/singleview/rmag_t.rb +32 -0
  198. data/examples/singleview/rpmr_t.rb +27 -0
  199. data/examples/singleview/rpsi_t.rb +24 -0
  200. data/examples/singleview/rser_t.rb +13 -0
  201. data/examples/singleview/rshu_cmn_t.rb +31 -0
  202. data/examples/singleview/schedule.rb +91 -0
  203. data/examples/singleview/schedule_task_type.rb +43 -0
  204. data/examples/singleview/service.rb +88 -0
  205. data/examples/singleview/service_bill_run_t.rb +12 -0
  206. data/examples/singleview/service_charge_category.rb +22 -0
  207. data/examples/singleview/service_da.rb +11 -0
  208. data/examples/singleview/service_da_array.rb +35 -0
  209. data/examples/singleview/service_duplicate.rb +4 -0
  210. data/examples/singleview/service_history.rb +59 -0
  211. data/examples/singleview/service_type.rb +54 -0
  212. data/examples/singleview/service_type_cc.rb +18 -0
  213. data/examples/singleview/service_type_da.rb +8 -0
  214. data/examples/singleview/service_type_equip_type.rb +11 -0
  215. data/examples/singleview/subtotal.rb +48 -0
  216. data/examples/singleview/subtotal_history.rb +59 -0
  217. data/examples/singleview/subtotal_rating_delta.rb +20 -0
  218. data/examples/singleview/subtotal_rating_value.rb +21 -0
  219. data/examples/singleview/subtotal_term.rb +16 -0
  220. data/examples/singleview/subtotal_value.rb +18 -0
  221. data/examples/singleview/summary_of_change.rb +31 -0
  222. data/examples/singleview/summary_of_change_ev.rb +18 -0
  223. data/examples/singleview/summary_of_change_view.rb +22 -0
  224. data/examples/singleview/t2_anumber_france.rb +22 -0
  225. data/examples/singleview/t2_anumber_italy.rb +22 -0
  226. data/examples/singleview/t2_anumber_netherlands.rb +24 -0
  227. data/examples/singleview/t2_anumber_portugal.rb +22 -0
  228. data/examples/singleview/t2_anumber_spain.rb +22 -0
  229. data/examples/singleview/t2_anumber_switzerland.rb +24 -0
  230. data/examples/singleview/t2_bankreference_austria.rb +7 -0
  231. data/examples/singleview/t2_bankreference_belgium.rb +6 -0
  232. data/examples/singleview/t2_bankreference_france.rb +7 -0
  233. data/examples/singleview/t2_bankreference_germany.rb +7 -0
  234. data/examples/singleview/t2_bankreference_italy.rb +7 -0
  235. data/examples/singleview/t2_bankreference_portugal.rb +7 -0
  236. data/examples/singleview/t2_cc_provrequests.rb +19 -0
  237. data/examples/singleview/t2_emf_info.rb +12 -0
  238. data/examples/singleview/t2_ev_column_label_mapping.rb +9 -0
  239. data/examples/singleview/t2_historytable.rb +26 -0
  240. data/examples/singleview/t2_inv_revoked_invoice.rb +11 -0
  241. data/examples/singleview/t2_inv_suppress_invoice.rb +13 -0
  242. data/examples/singleview/t2_national_number_plan.rb +8 -0
  243. data/examples/singleview/t2_pay_statement.rb +28 -0
  244. data/examples/singleview/t2_prov_req_action.rb +22 -0
  245. data/examples/singleview/t2_prov_request.rb +32 -0
  246. data/examples/singleview/t2_rep_brr_t.rb +19 -0
  247. data/examples/singleview/t2_rep_trr_t.rb +19 -0
  248. data/examples/singleview/t2_rep_ubr_t.rb +19 -0
  249. data/examples/singleview/t2_taxclass.rb +8 -0
  250. data/examples/singleview/t2_zipcode_austria.rb +8 -0
  251. data/examples/singleview/t2_zipcode_france.rb +8 -0
  252. data/examples/singleview/t2_zipcode_germany.rb +8 -0
  253. data/examples/singleview/t2_zipcode_hungary.rb +8 -0
  254. data/examples/singleview/t2_zipcode_luxembourg.rb +8 -0
  255. data/examples/singleview/t2_zipcode_netherlands.rb +8 -0
  256. data/examples/singleview/t2_zipcode_portugal.rb +9 -0
  257. data/examples/singleview/t2_zipcode_spain.rb +8 -0
  258. data/examples/singleview/t2_zipcode_switzerland.rb +8 -0
  259. data/examples/singleview/table_import_order.rb +6 -0
  260. data/examples/singleview/tariff.rb +51 -0
  261. data/examples/singleview/tariff_charge.rb +33 -0
  262. data/examples/singleview/tariff_charge_defn.rb +18 -0
  263. data/examples/singleview/tariff_condition_defn.rb +19 -0
  264. data/examples/singleview/tariff_history.rb +70 -0
  265. data/examples/singleview/tariff_recurring.rb +36 -0
  266. data/examples/singleview/task_queue.rb +130 -0
  267. data/examples/singleview/task_queue_result.rb +10 -0
  268. data/examples/singleview/template.rb +18 -0
  269. data/examples/singleview/template_history.rb +30 -0
  270. data/examples/singleview/template_reference.rb +9 -0
  271. data/examples/singleview/template_variable.rb +10 -0
  272. data/examples/singleview/trt_clec_treatment.rb +13 -0
  273. data/examples/singleview/variable_defn.rb +48 -0
  274. data/examples/singleview/variable_defn_dependency.rb +11 -0
  275. data/examples/singleview/variable_defn_direct.rb +15 -0
  276. data/examples/singleview/variable_defn_history.rb +22 -0
  277. data/examples/singleview/work_force.rb +25 -0
  278. data/examples/singleview/xpsi_addr_val_commtax21.rb +24 -0
  279. data/examples/singleview/xpsi_addr_val_msag.rb +24 -0
  280. data/examples/singleview/xpsi_addr_val_zip.rb +14 -0
  281. data/examples/singleview/xpsi_ne_batch.rb +20 -0
  282. data/examples/singleview/xpsi_product_batch.rb +18 -0
  283. data/examples/singleview/xpsi_product_status.rb +14 -0
  284. data/examples/singleview/xpsi_tax_error.rb +34 -0
  285. data/examples/singleview/xpsi_trt_revoke.rb +68 -0
  286. data/examples/singleview/xpsi_trt_revoke_prod_inst.rb +12 -0
  287. data/examples/singleview/xpsi_update_capture.rb +35 -0
  288. data/lib/activerecord/base.rb +12 -0
  289. data/lib/hash_tricks.rb +21 -0
  290. data/lib/magic_model_generator.rb +8 -0
  291. data/lib/magic_model_generator/schema.rb +205 -0
  292. data/lib/magic_model_generator/validations.rb +48 -0
  293. data/lib/magic_model_generator/version.rb +9 -0
  294. data/lib/rails/generator/dynamic_named_base.rb +99 -0
  295. data/lib/rails/generator/manifest.rb +8 -0
  296. data/magic_model_generator.rb +88 -0
  297. data/templates/model.rb +3 -0
  298. data/test/magic_model_generator_test.rb +11 -0
  299. data/test/test_helper.rb +2 -0
  300. metadata +366 -0
@@ -0,0 +1,48 @@
1
+ module MagicModelsGenerator
2
+ module Validations
3
+
4
+ # Returns an array of strings describing validations for this class
5
+ def self.generate_validations(klass)
6
+
7
+ logger = MagicModelsGenerator.logger
8
+
9
+ # Code reworked from http://www.redhillconsulting.com.au/rails_plugins.html
10
+ # Thanks Red Hill Consulting for using an MIT licence :o)
11
+
12
+ validations = []
13
+ klass.columns.
14
+ reject { |column| column.name =~ /(?i)^(((created|updated)_(at|on))|position|type|id)$/ }.
15
+ each do |column|
16
+
17
+ # Active record seems to interpolate booleans anyway to either true, false or nil...
18
+ if column.type == :boolean
19
+ validations << "validates_inclusion_of :#{column.name}, :in => [true, false], :allow_nil => #{column.null}, :message => ActiveRecord::Errors.default_error_messages[:blank]"
20
+ logger.debug validations.last
21
+ elsif !column.null
22
+ validations << "validates_presence_of :#{column.name}"
23
+ logger.debug validations.last
24
+ end
25
+
26
+ if column.type == :integer
27
+ validations << "validates_numericality_of :#{column.name}, :allow_nil => #{column.null.inspect}, :only_integer => true"
28
+ logger.debug validations.last
29
+ elsif column.number?
30
+ validations << "validates_numericality_of :#{column.name}, :allow_nil => #{column.null.inspect}"
31
+ logger.debug validations.last
32
+ elsif column.text? && column.limit
33
+ validations << "validates_length_of :#{column.name}, :allow_nil => #{column.null.inspect}, :maximum => #{column.limit}"
34
+ logger.debug validations.last
35
+ end
36
+
37
+ end
38
+
39
+ # Single-column UNIQUE indexes
40
+ klass.get_unique_index_columns.each do |col|
41
+ validations << "validates_uniqueness_of :#{col}"
42
+ logger.debug validations.last
43
+ end
44
+
45
+ validations
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,9 @@
1
+ module MagicModelsGenerator #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 3
5
+ TINY = 0
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
@@ -0,0 +1,99 @@
1
+ #require 'rails/generator/base'
2
+
3
+ module Rails
4
+ module Generator
5
+ class DynamicNamedBase < Rails::Generator::Base
6
+ attr_reader :all_attrs,
7
+ :name, :class_name, :singular_name, :plural_name, :table_name,
8
+ :class_path, :file_path, :class_nesting, :class_nesting_depth
9
+ attr_accessor :superklass, :class_contents
10
+ alias_method :file_name, :singular_name
11
+ attr_reader :controller_name,
12
+ :controller_class_path,
13
+ :controller_file_path,
14
+ :controller_class_nesting,
15
+ :controller_class_nesting_depth,
16
+ :controller_class_name,
17
+ :controller_singular_name,
18
+ :controller_plural_name
19
+ alias_method :controller_file_name, :controller_singular_name
20
+ alias_method :controller_table_name, :controller_plural_name
21
+ #alias_method :base_controller_file_path, :controller_file_path
22
+
23
+ @@model_attrs = %w(name class_name singular_name plural_name
24
+ table_name class_path file_path class_nesting
25
+ class_nesting_depth file_name singular_name
26
+ superklass class_contents)
27
+ @@controller_attrs = %w(controller_name controller_class_path
28
+ controller_file_path controller_class_nesting
29
+ controller_class_nesting_depth controller_class_name
30
+ controller_singular_name controller_plural_name)
31
+
32
+ def initialize(runtime_args, runtime_options = {})
33
+ super
34
+
35
+ # No arguments are required.
36
+ usage if runtime_args.length > 0
37
+
38
+ @all_attrs = {}
39
+ end
40
+
41
+ protected
42
+ def load_attrs(key)
43
+ all_attrs[key] = {} if not all_attrs[key]
44
+ @@model_attrs.concat(@@controller_attrs).each do |attr|
45
+ instance_variable_set "@#{attr.to_s}", all_attrs[key][attr]
46
+ end
47
+ all_attrs[key]
48
+ end
49
+
50
+ def store_attrs(key)
51
+ all_attrs[key] = instance_values.pass(@@model_attrs.concat(@@controller_attrs))
52
+ end
53
+
54
+ def assign_names!(name)
55
+ @superklass ||= ActiveRecord::Base
56
+ @name = name
57
+ base_name, @class_path, @file_path, @class_nesting, @class_nesting_depth = extract_modules(@name)
58
+ @class_name_without_nesting, @singular_name, @plural_name = inflect_names(base_name)
59
+ @table_name = ActiveRecord::Base.pluralize_table_names ? plural_name : singular_name
60
+ if @class_nesting.empty?
61
+ @class_name = @class_name_without_nesting
62
+ else
63
+ @class_name = "#{@class_nesting}::#{@class_name_without_nesting}"
64
+ end
65
+
66
+ @controller_name ||= ActiveRecord::Base.pluralize_table_names ? @name.pluralize : @name
67
+
68
+ base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name)
69
+ @controller_class_name_without_nesting, @controller_singular_name, @controller_plural_name = inflect_names(base_name)
70
+
71
+ if @controller_class_nesting.empty?
72
+ @controller_class_name = @controller_class_name_without_nesting
73
+ else
74
+ @controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
75
+ end
76
+ end
77
+
78
+ # Extract modules from filesystem-style or ruby-style path:
79
+ # good/fun/stuff
80
+ # Good::Fun::Stuff
81
+ # produce the same results.
82
+ def extract_modules(name)
83
+ modules = name.include?('/') ? name.split('/') : name.split('::')
84
+ name = modules.pop
85
+ path = modules.map { |m| m.underscore }
86
+ file_path = (path + [name.underscore]).join('/')
87
+ nesting = modules.map { |m| m.camelize }.join('::')
88
+ [name, path, file_path, nesting, modules.size]
89
+ end
90
+
91
+ def inflect_names(name)
92
+ camel = name.camelize
93
+ under = camel.underscore
94
+ plural = under.pluralize
95
+ [camel, under, plural]
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,8 @@
1
+ class Rails::Generator::Manifest
2
+ attr_reader :actions
3
+
4
+ def copy_actions(manifest)
5
+ @actions.concat(manifest.actions)
6
+ end
7
+ end
8
+
@@ -0,0 +1,88 @@
1
+ require 'rubygems'
2
+ require 'pp'
3
+ require 'dr_nic_magic_models'
4
+ require 'rails/generator/dynamic_named_base'
5
+ require 'rails/generator/manifest'
6
+
7
+ class MagicModelGenerator < Rails::Generator::DynamicNamedBase
8
+ default_options :skip_migration => true
9
+
10
+ attr_reader :models
11
+
12
+ def initialize(runtime_args, runtime_options = {})
13
+ super
14
+ begin
15
+ require destination_root + '/config/boot'
16
+
17
+ require 'magic_model_generator'
18
+ superklass ||= ActiveRecord::Base
19
+ MagicModelsGenerator::Schema.superklass = superklass
20
+ @models = MagicModelsGenerator::Schema.models.keys.sort
21
+
22
+ @models.each do |base_name|
23
+ puts "Preparing #{base_name}..."
24
+ load_attrs(base_name)
25
+ assign_names!(base_name)
26
+ store_attrs(base_name)
27
+ end
28
+ rescue
29
+ puts $!
30
+ puts $@
31
+ end
32
+ end
33
+
34
+ def manifest
35
+ record do |m|
36
+ load_attrs(@models.first)
37
+
38
+ # Model, test, and fixture directories.
39
+ m.directory File.join('app/models', class_path)
40
+ #m.directory File.join('test/unit', class_path)
41
+ #m.directory File.join('test/fixtures', class_path)
42
+
43
+ @models.each do |model_name|
44
+ begin
45
+ attrs = load_attrs(model_name)
46
+
47
+ begin
48
+ klass = class_name.constantize
49
+ rescue
50
+ puts $!
51
+ puts $@
52
+ next
53
+ end
54
+ puts "Building model #{model_name}..."
55
+ commands = MagicModelsGenerator::Schema.associations(klass)
56
+ commands += MagicModelsGenerator::Validations.generate_validations(klass)
57
+ attrs['class_contents'] = commands.join("\n ")
58
+
59
+ # Check for class naming collisions.
60
+ m.class_collisions class_path, class_name, "#{class_name}Test"
61
+
62
+ # Model class, unit test, and fixtures.
63
+ m.template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb"), :assigns => attrs
64
+ #m.template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb"), :assigns => attrs
65
+ #m.template 'fixtures.yml', File.join('test/fixtures', class_path, "#{table_name}.yml"), :assigns => attrs
66
+ rescue
67
+ puts $!
68
+ puts $@
69
+ end
70
+ end
71
+
72
+ @models.each {|model| Object.send(:remove_const, model) rescue nil }
73
+ end
74
+ end
75
+
76
+ protected
77
+ def banner
78
+ "Usage: #{$0} magic_model"
79
+ end
80
+
81
+ def add_options!(opt)
82
+ opt.separator ''
83
+ opt.separator 'Options:'
84
+ opt.on("--no-throughs",
85
+ "Don't generate has_many :though relations") { |v| options[:no_throughs] = v }
86
+ end
87
+
88
+ end
@@ -0,0 +1,3 @@
1
+ class <%= class_name %> < <%= superklass %>
2
+ <%= class_contents %>
3
+ end
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class MagicModelGeneratorTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def test_truth
9
+ assert true
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/magic_model_generator'
metadata ADDED
@@ -0,0 +1,366 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.11
3
+ specification_version: 1
4
+ name: magic_model_generator
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.3.0
7
+ date: 2006-11-14 00:00:00 +01:00
8
+ summary: Generates Rails models from the target database... magically! Validations and associations included.
9
+ require_paths:
10
+ - lib
11
+ email: drnicwilliams@gmail.com
12
+ homepage: http://magicmodels.rubyforge.org
13
+ rubyforge_project: magicmodels
14
+ description: Generates Rails models from the target database... magically! Validations and associations included.
15
+ autorequire: magic_model_generator
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.8.4
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ authors:
29
+ - Dr Nic Williams
30
+ files:
31
+ - README
32
+ - CHANGELOG
33
+ - Rakefile
34
+ - magic_model_generator.rb
35
+ - test/test_helper.rb
36
+ - test/magic_model_generator_test.rb
37
+ - lib/magic_model_generator.rb
38
+ - lib/hash_tricks.rb
39
+ - lib/rails
40
+ - lib/activerecord
41
+ - lib/magic_model_generator
42
+ - lib/rails/generator
43
+ - lib/rails/generator/manifest.rb
44
+ - lib/rails/generator/dynamic_named_base.rb
45
+ - lib/activerecord/base.rb
46
+ - lib/magic_model_generator/version.rb
47
+ - lib/magic_model_generator/validations.rb
48
+ - lib/magic_model_generator/schema.rb
49
+ - templates/model.rb
50
+ - examples/singleview/payment.rb
51
+ - examples/singleview/adjustment.rb
52
+ - examples/singleview/product.rb
53
+ - examples/singleview/t2_inv_suppress_invoice.rb
54
+ - examples/singleview/trt_clec_treatment.rb
55
+ - examples/singleview/payment_type_variable.rb
56
+ - examples/singleview/tariff_charge.rb
57
+ - examples/singleview/customer_query_type.rb
58
+ - examples/singleview/dil_history.rb
59
+ - examples/singleview/tariff_recurring.rb
60
+ - examples/singleview/gl_code.rb
61
+ - examples/singleview/tariff_history.rb
62
+ - examples/singleview/configuration_attr_type.rb
63
+ - examples/singleview/function_defn_history.rb
64
+ - examples/singleview/attribute_type.rb
65
+ - examples/singleview/invoice_contents.rb
66
+ - examples/singleview/atlanta_profile_group_map.rb
67
+ - examples/singleview/adjustment_batch.rb
68
+ - examples/singleview/summary_of_change_ev.rb
69
+ - examples/singleview/atlanta_table_partition.rb
70
+ - examples/singleview/t2_anumber_netherlands.rb
71
+ - examples/singleview/summary_of_change.rb
72
+ - examples/singleview/xpsi_trt_revoke.rb
73
+ - examples/singleview/t2_zipcode_netherlands.rb
74
+ - examples/singleview/atlanta_operator.rb
75
+ - examples/singleview/rpsi_t.rb
76
+ - examples/singleview/atlanta_role.rb
77
+ - examples/singleview/delete_cascade.rb
78
+ - examples/singleview/isp_email_address.rb
79
+ - examples/singleview/charge_output_defn_var.rb
80
+ - examples/singleview/dil_variable.rb
81
+ - examples/singleview/equipment_type_variable.rb
82
+ - examples/singleview/output_device.rb
83
+ - examples/singleview/racr_clec_t1.rb
84
+ - examples/singleview/t2_taxclass.rb
85
+ - examples/singleview/equipment_history.rb
86
+ - examples/singleview/t2_inv_revoked_invoice.rb
87
+ - examples/singleview/normalised_event.rb
88
+ - examples/singleview/t2_prov_request.rb
89
+ - examples/singleview/service_type_equip_type.rb
90
+ - examples/singleview/evs_alias.rb
91
+ - examples/singleview/attribute_type_variable.rb
92
+ - examples/singleview/customer_node_da.rb
93
+ - examples/singleview/t2_zipcode_luxembourg.rb
94
+ - examples/singleview/product_group_history.rb
95
+ - examples/singleview/facility_group.rb
96
+ - examples/singleview/entity_validation_list.rb
97
+ - examples/singleview/product_in_product_group.rb
98
+ - examples/singleview/t2_zipcode_germany.rb
99
+ - examples/singleview/product_instance_history.rb
100
+ - examples/singleview/t2_rep_ubr_t.rb
101
+ - examples/singleview/charge_category.rb
102
+ - examples/singleview/person_history.rb
103
+ - examples/singleview/customer_node_bill_run.rb
104
+ - examples/singleview/rdfd_cmn_t.rb
105
+ - examples/singleview/account_type_aging.rb
106
+ - examples/singleview/product_derived_attribute.rb
107
+ - examples/singleview/normalised_event_error.rb
108
+ - examples/singleview/tariff.rb
109
+ - examples/singleview/payment_type.rb
110
+ - examples/singleview/function_defn.rb
111
+ - examples/singleview/product_instance_service.rb
112
+ - examples/singleview/evt_equipment_changeover.rb
113
+ - examples/singleview/expression_list_value.rb
114
+ - examples/singleview/xpsi_product_status.rb
115
+ - examples/singleview/entity_mapping.rb
116
+ - examples/singleview/charge.rb
117
+ - examples/singleview/payment_item.rb
118
+ - examples/singleview/t2_prov_req_action.rb
119
+ - examples/singleview/product_history.rb
120
+ - examples/singleview/derived_attribute_array.rb
121
+ - examples/singleview/service_da.rb
122
+ - examples/singleview/invoice_message_variable.rb
123
+ - examples/singleview/xpsi_update_capture.rb
124
+ - examples/singleview/racr_t.rb
125
+ - examples/singleview/variable_defn_direct.rb
126
+ - examples/singleview/table_import_order.rb
127
+ - examples/singleview/archive_lock_t.rb
128
+ - examples/singleview/gl_code_history.rb
129
+ - examples/singleview/variable_defn_dependency.rb
130
+ - examples/singleview/tariff_charge_defn.rb
131
+ - examples/singleview/racr_clec_t2.rb
132
+ - examples/singleview/t2_anumber_switzerland.rb
133
+ - examples/singleview/derived_attribute_history.rb
134
+ - examples/singleview/t2_zipcode_switzerland.rb
135
+ - examples/singleview/currency.rb
136
+ - examples/singleview/adjustment_invoice.rb
137
+ - examples/singleview/t2_zipcode_spain.rb
138
+ - examples/singleview/conversion_rate.rb
139
+ - examples/singleview/plan_table.rb
140
+ - examples/singleview/rdfd_t.rb
141
+ - examples/singleview/customer_node_charge_cat.rb
142
+ - examples/singleview/equipment.rb
143
+ - examples/singleview/rmag_t.rb
144
+ - examples/singleview/t2_anumber_portugal.rb
145
+ - examples/singleview/tariff_condition_defn.rb
146
+ - examples/singleview/invoice_type_history.rb
147
+ - examples/singleview/archive_result.rb
148
+ - examples/singleview/reference_code.rb
149
+ - examples/singleview/configuration_attribute.rb
150
+ - examples/singleview/template_history.rb
151
+ - examples/singleview/normalised_event_file.rb
152
+ - examples/singleview/error_message.rb
153
+ - examples/singleview/ragd_t.rb
154
+ - examples/singleview/output_method.rb
155
+ - examples/singleview/invoice_message.rb
156
+ - examples/singleview/rshu_cmn_t.rb
157
+ - examples/singleview/product_service_type_equip.rb
158
+ - examples/singleview/customer_node_correspond.rb
159
+ - examples/singleview/task_queue_result.rb
160
+ - examples/singleview/error_group.rb
161
+ - examples/singleview/customer_node.rb
162
+ - examples/singleview/cache_field.rb
163
+ - examples/singleview/customer_query_progress.rb
164
+ - examples/singleview/customer_node_type_da.rb
165
+ - examples/singleview/atlanta_profile_func_map.rb
166
+ - examples/singleview/customer_node_type_var.rb
167
+ - examples/singleview/t2_zipcode_france.rb
168
+ - examples/singleview/t2_bankreference_germany.rb
169
+ - examples/singleview/archive_type.rb
170
+ - examples/singleview/atlanta_profile_role_map.rb
171
+ - examples/singleview/charge_output_defn_history.rb
172
+ - examples/singleview/t2_zipcode_austria.rb
173
+ - examples/singleview/expression_list.rb
174
+ - examples/singleview/contract_history.rb
175
+ - examples/singleview/output_select.rb
176
+ - examples/singleview/normalised_event_ft_var.rb
177
+ - examples/singleview/derived_attribute_value.rb
178
+ - examples/singleview/facility_group_history.rb
179
+ - examples/singleview/function_role.rb
180
+ - examples/singleview/customer_node_type.rb
181
+ - examples/singleview/rapc_t.rb
182
+ - examples/singleview/product_compatibility.rb
183
+ - examples/singleview/subtotal_rating_delta.rb
184
+ - examples/singleview/xpsi_addr_val_commtax21.rb
185
+ - examples/singleview/summary_of_change_view.rb
186
+ - examples/singleview/racr_clec_t3.rb
187
+ - examples/singleview/archive_type_table_list.rb
188
+ - examples/singleview/normalised_event_ft.rb
189
+ - examples/singleview/bill_run_type_task.rb
190
+ - examples/singleview/release_info.rb
191
+ - examples/singleview/t2_national_number_plan.rb
192
+ - examples/singleview/work_force.rb
193
+ - examples/singleview/product_service_type.rb
194
+ - examples/singleview/derived_attribute.rb
195
+ - examples/singleview/dil_validation_t.rb
196
+ - examples/singleview/t2_ev_column_label_mapping.rb
197
+ - examples/singleview/service_charge_category.rb
198
+ - examples/singleview/address_history.rb
199
+ - examples/singleview/customer_node_type_cc.rb
200
+ - examples/singleview/adjustment_type.rb
201
+ - examples/singleview/configuration_item_type.rb
202
+ - examples/singleview/entity_validation.rb
203
+ - examples/singleview/template_reference.rb
204
+ - examples/singleview/product_subtotal.rb
205
+ - examples/singleview/invoice_type.rb
206
+ - examples/singleview/account_type.rb
207
+ - examples/singleview/output_method_type.rb
208
+ - examples/singleview/receivable_type.rb
209
+ - examples/singleview/variable_defn_history.rb
210
+ - examples/singleview/invoice_format.rb
211
+ - examples/singleview/atlanta_form.rb
212
+ - examples/singleview/xpsi_tax_error.rb
213
+ - examples/singleview/atlanta_form_field.rb
214
+ - examples/singleview/currency_history.rb
215
+ - examples/singleview/template.rb
216
+ - examples/singleview/contract_type_product.rb
217
+ - examples/singleview/t2_zipcode_portugal.rb
218
+ - examples/singleview/schedule_task_type.rb
219
+ - examples/singleview/t2_emf_info.rb
220
+ - examples/singleview/atai_error_name.rb
221
+ - examples/singleview/fac_group_instance.rb
222
+ - examples/singleview/customer_node_inv_format.rb
223
+ - examples/singleview/account.rb
224
+ - examples/singleview/invoice.rb
225
+ - examples/singleview/address_format.rb
226
+ - examples/singleview/service.rb
227
+ - examples/singleview/xpsi_addr_val_zip.rb
228
+ - examples/singleview/service_da_array.rb
229
+ - examples/singleview/rpmr_t.rb
230
+ - examples/singleview/atlanta_profile.rb
231
+ - examples/singleview/service_type_da.rb
232
+ - examples/singleview/charge_output_defn.rb
233
+ - examples/singleview/delete_constraint.rb
234
+ - examples/singleview/gl_upload.rb
235
+ - examples/singleview/t2_bankreference_portugal.rb
236
+ - examples/singleview/t2_anumber_france.rb
237
+ - examples/singleview/contract.rb
238
+ - examples/singleview/subtotal_history.rb
239
+ - examples/singleview/payment_batch.rb
240
+ - examples/singleview/fac_group_instance_hist.rb
241
+ - examples/singleview/template_variable.rb
242
+ - examples/singleview/invoice_message_history.rb
243
+ - examples/singleview/t2_pay_statement.rb
244
+ - examples/singleview/bill_run_operation.rb
245
+ - examples/singleview/t2_bankreference_austria.rb
246
+ - examples/singleview/customer_node_history.rb
247
+ - examples/singleview/t2_cc_provrequests.rb
248
+ - examples/singleview/derived_attribute_index.rb
249
+ - examples/singleview/normalised_event_type.rb
250
+ - examples/singleview/t2_bankreference_belgium.rb
251
+ - examples/singleview/rgp_normalised_event.rb
252
+ - examples/singleview/bill_run.rb
253
+ - examples/singleview/dil.rb
254
+ - examples/singleview/equipment_type.rb
255
+ - examples/singleview/inv_loop_t.rb
256
+ - examples/singleview/reprocessed_file.rb
257
+ - examples/singleview/t2_historytable.rb
258
+ - examples/singleview/address.rb
259
+ - examples/singleview/ragd_clec_t.rb
260
+ - examples/singleview/xpsi_addr_val_msag.rb
261
+ - examples/singleview/rgp_file.rb
262
+ - examples/singleview/service_duplicate.rb
263
+ - examples/singleview/report_reference_type.rb
264
+ - examples/singleview/schedule.rb
265
+ - examples/singleview/atlanta_profile_wf_map.rb
266
+ - examples/singleview/fac_group_compatibility.rb
267
+ - examples/singleview/t2_zipcode_hungary.rb
268
+ - examples/singleview/t2_anumber_italy.rb
269
+ - examples/singleview/invoice_type_variable.rb
270
+ - examples/singleview/account_type_variable.rb
271
+ - examples/singleview/facility.rb
272
+ - examples/singleview/t2_rep_trr_t.rb
273
+ - examples/singleview/service_type_cc.rb
274
+ - examples/singleview/task_queue.rb
275
+ - examples/singleview/bill_run_type.rb
276
+ - examples/singleview/customer_node_da_array.rb
277
+ - examples/singleview/atlanta_help_entry.rb
278
+ - examples/singleview/variable_defn.rb
279
+ - examples/singleview/xpsi_product_batch.rb
280
+ - examples/singleview/configuration_item.rb
281
+ - examples/singleview/dil_reference.rb
282
+ - examples/singleview/t2_anumber_spain.rb
283
+ - examples/singleview/subtotal_value.rb
284
+ - examples/singleview/payment_invoice.rb
285
+ - examples/singleview/entity_validation_variable.rb
286
+ - examples/singleview/service_type.rb
287
+ - examples/singleview/xpsi_ne_batch.rb
288
+ - examples/singleview/service_bill_run_t.rb
289
+ - examples/singleview/inv_report_accounts_t.rb
290
+ - examples/singleview/t2_bankreference_france.rb
291
+ - examples/singleview/account_reservation.rb
292
+ - examples/singleview/product_facility_group.rb
293
+ - examples/singleview/delete_cascade_group.rb
294
+ - examples/singleview/menu_role_map.rb
295
+ - examples/singleview/t2_rep_brr_t.rb
296
+ - examples/singleview/receivable_type_history.rb
297
+ - examples/singleview/licence_current_values.rb
298
+ - examples/singleview/subtotal_term.rb
299
+ - examples/singleview/adjustment_type_variable.rb
300
+ - examples/singleview/dunning_t.rb
301
+ - examples/singleview/invoice_format_history.rb
302
+ - examples/singleview/icon.rb
303
+ - examples/singleview/evs_attribute_type_key.rb
304
+ - examples/singleview/report_reference_type_defs.rb
305
+ - examples/singleview/product_group.rb
306
+ - examples/singleview/subtotal_rating_value.rb
307
+ - examples/singleview/subtotal.rb
308
+ - examples/singleview/t2_bankreference_italy.rb
309
+ - examples/singleview/cache.rb
310
+ - examples/singleview/product_instance.rb
311
+ - examples/singleview/person.rb
312
+ - examples/singleview/product_instance_equip.rb
313
+ - examples/singleview/xpsi_trt_revoke_prod_inst.rb
314
+ - examples/singleview/bill_run_type_status.rb
315
+ - examples/singleview/product_tariff.rb
316
+ - examples/singleview/account_history.rb
317
+ - examples/singleview/normalised_event_ft_hist.rb
318
+ - examples/singleview/invoice_receivable_type.rb
319
+ - examples/singleview/contract_type.rb
320
+ - examples/singleview/service_history.rb
321
+ - examples/singleview/customer_query.rb
322
+ - examples/singleview/product_payment_item.rb
323
+ - examples/singleview/rser_t.rb
324
+ - examples/singleview/reference_type.rb
325
+ - examples/singleview/customer_query_type_var.rb
326
+ - examples/singleview/atlanta_group.rb
327
+ - examples/singleview/entity_remap.rb
328
+ - examples/singleview/can_act_charge.rb
329
+ - examples/singleview/foreign_key.rb
330
+ - examples/singleview/function_role_map.rb
331
+ - examples/singleview/person_type.rb
332
+ - examples/singleview/evs_address_equiv.rb
333
+ - examples/singleview/customer_contact.rb
334
+ test_files: []
335
+
336
+ rdoc_options:
337
+ - --quiet
338
+ - --title
339
+ - magic_model_generator documentation
340
+ - --opname
341
+ - index.html
342
+ - --line-numbers
343
+ - --main
344
+ - README
345
+ - --inline-source
346
+ - --exclude
347
+ - ^(examples|extras)/
348
+ extra_rdoc_files:
349
+ - README
350
+ - CHANGELOG
351
+ executables: []
352
+
353
+ extensions: []
354
+
355
+ requirements: []
356
+
357
+ dependencies:
358
+ - !ruby/object:Gem::Dependency
359
+ name: dr_nic_magic_models
360
+ version_requirement:
361
+ version_requirements: !ruby/object:Gem::Version::Requirement
362
+ requirements:
363
+ - - ">="
364
+ - !ruby/object:Gem::Version
365
+ version: 0.9.0
366
+ version: