erp_base_erp_svcs 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. data/GPL-3-LICENSE +674 -0
  2. data/README.rdoc +2 -0
  3. data/Rakefile +31 -0
  4. data/app/assets/javascripts/erp_base_erp_svcs/application.js +9 -0
  5. data/app/assets/stylesheets/erp_base_erp_svcs/application.css +7 -0
  6. data/app/controllers/erp_base_erp_svcs/application_controller.rb +4 -0
  7. data/app/helpers/erp_base_erp_svcs/application_helper.rb +4 -0
  8. data/app/models/category.rb +11 -0
  9. data/app/models/category_classification.rb +4 -0
  10. data/app/models/compass_ae_instance.rb +11 -0
  11. data/app/models/contact.rb +42 -0
  12. data/app/models/contact_purpose.rb +6 -0
  13. data/app/models/contact_type.rb +3 -0
  14. data/app/models/currency.rb +16 -0
  15. data/app/models/descriptive_asset.rb +4 -0
  16. data/app/models/email_address.rb +15 -0
  17. data/app/models/geo_country.rb +8 -0
  18. data/app/models/geo_zone.rb +8 -0
  19. data/app/models/individual.rb +76 -0
  20. data/app/models/iso_country_code.rb +10 -0
  21. data/app/models/money.rb +19 -0
  22. data/app/models/note.rb +14 -0
  23. data/app/models/note_type.rb +7 -0
  24. data/app/models/organization.rb +32 -0
  25. data/app/models/party.rb +191 -0
  26. data/app/models/party_relationship.rb +9 -0
  27. data/app/models/party_role.rb +8 -0
  28. data/app/models/phone_number.rb +16 -0
  29. data/app/models/postal_address.rb +19 -0
  30. data/app/models/relationship_type.rb +7 -0
  31. data/app/models/role_type.rb +7 -0
  32. data/app/models/valid_note_type.rb +4 -0
  33. data/app/models/view_type.rb +3 -0
  34. data/app/views/layouts/erp_base_erp_svcs/application.html.erb +14 -0
  35. data/config/initializers/erp_base_erp_svcs.rb +4 -0
  36. data/config/routes.rb +2 -0
  37. data/db/data_migrations/20110525001935_add_usd_currency.rb +11 -0
  38. data/db/data_migrations/20110609150135_add_iso_codes.rb +18 -0
  39. data/db/data_migrations/20110913145838_setup_compass_ae_instance.rb +11 -0
  40. data/db/data_sets/geo_countries.yml +2952 -0
  41. data/db/data_sets/geo_zones.yml +1233 -0
  42. data/db/migrate/20080805000020_base_erp_services.rb +461 -0
  43. data/db/migrate/20110913145329_create_compass_ae_instance.rb +15 -0
  44. data/db/migrate/upgrade/20110907171257_add_notes.rb +63 -0
  45. data/lib/erp_base_erp_svcs/ar_fixtures.rb +103 -0
  46. data/lib/erp_base_erp_svcs/command.rb +37 -0
  47. data/lib/erp_base_erp_svcs/config.rb +27 -0
  48. data/lib/erp_base_erp_svcs/engine.rb +27 -0
  49. data/lib/erp_base_erp_svcs/extensions/active_record/acts_as_category.rb +50 -0
  50. data/lib/erp_base_erp_svcs/extensions/active_record/acts_as_erp_type.rb +148 -0
  51. data/lib/erp_base_erp_svcs/extensions/active_record/acts_as_note_type.rb +47 -0
  52. data/lib/erp_base_erp_svcs/extensions/active_record/data_migrator.rb +46 -0
  53. data/lib/erp_base_erp_svcs/extensions/active_record/has_contact.rb +56 -0
  54. data/lib/erp_base_erp_svcs/extensions/active_record/has_notes.rb +32 -0
  55. data/lib/erp_base_erp_svcs/extensions/active_record/is_describable.rb +44 -0
  56. data/lib/erp_base_erp_svcs/extensions/active_record/migrator.rb +76 -0
  57. data/lib/erp_base_erp_svcs/extensions/active_record/sti_instantiation.rb +37 -0
  58. data/lib/erp_base_erp_svcs/extensions/core/array.rb +20 -0
  59. data/lib/erp_base_erp_svcs/extensions/core/hash.rb +19 -0
  60. data/lib/erp_base_erp_svcs/extensions/core/numbers.rb +27 -0
  61. data/lib/erp_base_erp_svcs/extensions/core/object.rb +6 -0
  62. data/lib/erp_base_erp_svcs/extensions/railties/engine.rb +85 -0
  63. data/lib/erp_base_erp_svcs/extensions.rb +19 -0
  64. data/lib/erp_base_erp_svcs/non_escape_json_string.rb +5 -0
  65. data/lib/erp_base_erp_svcs/rails_template.rb +93 -0
  66. data/lib/erp_base_erp_svcs/version.rb +3 -0
  67. data/lib/erp_base_erp_svcs.rb +17 -0
  68. data/lib/tasks/compass_backup.rake +87 -0
  69. data/lib/tasks/erp_base_erp_svcs_tasks.rake +59 -0
  70. data/lib/tasks/release_notes/NOTES +21 -0
  71. data/spec/dummy/Rakefile +7 -0
  72. data/spec/dummy/app/assets/javascripts/application.js +9 -0
  73. data/spec/dummy/app/assets/stylesheets/application.css +7 -0
  74. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  75. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  76. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  77. data/spec/dummy/config/application.rb +42 -0
  78. data/spec/dummy/config/boot.rb +10 -0
  79. data/spec/dummy/config/database.yml +8 -0
  80. data/spec/dummy/config/environment.rb +5 -0
  81. data/spec/dummy/config/environments/spec.rb +27 -0
  82. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  83. data/spec/dummy/config/initializers/inflections.rb +10 -0
  84. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  85. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  86. data/spec/dummy/config/initializers/session_store.rb +8 -0
  87. data/spec/dummy/config/initializers/wrap_parameters.rb +12 -0
  88. data/spec/dummy/config/locales/en.yml +5 -0
  89. data/spec/dummy/config/routes.rb +4 -0
  90. data/spec/dummy/config.ru +4 -0
  91. data/spec/dummy/db/spec.sqlite3 +0 -0
  92. data/spec/dummy/log/spec.log +4820 -0
  93. data/spec/dummy/public/404.html +26 -0
  94. data/spec/dummy/public/422.html +26 -0
  95. data/spec/dummy/public/500.html +26 -0
  96. data/spec/dummy/public/favicon.ico +0 -0
  97. data/spec/dummy/script/rails +6 -0
  98. data/spec/factories/business_party.rb +21 -0
  99. data/spec/factories/contact_purpose.rb +8 -0
  100. data/spec/factories/party.rb +16 -0
  101. data/spec/factories/party_relationship.rb +10 -0
  102. data/spec/factories/party_role.rb +7 -0
  103. data/spec/factories/phone_number.rb +7 -0
  104. data/spec/factories/relationship_type.rb +8 -0
  105. data/spec/factories/role_type.rb +8 -0
  106. data/spec/models/category_classification_spec.rb +11 -0
  107. data/spec/models/category_spec.rb +18 -0
  108. data/spec/models/contact_purpose_spec.rb +12 -0
  109. data/spec/models/contact_spec.rb +12 -0
  110. data/spec/models/contact_type_spec.rb +12 -0
  111. data/spec/models/currency_spec.rb +12 -0
  112. data/spec/models/descriptive_asset_spec.rb +12 -0
  113. data/spec/models/email_address_spec.rb +12 -0
  114. data/spec/models/geo_country_spec.rb +13 -0
  115. data/spec/models/geo_zone_spec.rb +12 -0
  116. data/spec/models/individual_spec.rb +40 -0
  117. data/spec/models/money_spec.rb +12 -0
  118. data/spec/models/note_spec.rb +26 -0
  119. data/spec/models/note_type_spec.rb +12 -0
  120. data/spec/models/organization_spec.rb +33 -0
  121. data/spec/models/party_relationship_spec.rb +12 -0
  122. data/spec/models/party_role_spec.rb +12 -0
  123. data/spec/models/party_spec.rb +98 -0
  124. data/spec/models/phone_number_spec.rb +12 -0
  125. data/spec/models/postal_address_spec.rb +12 -0
  126. data/spec/models/relationship_type_spec.rb +11 -0
  127. data/spec/models/role_type_spec.rb +12 -0
  128. data/spec/models/view_type_spec.rb +12 -0
  129. data/spec/spec_helper.rb +57 -0
  130. metadata +391 -0
@@ -0,0 +1,461 @@
1
+ class BaseErpServices < ActiveRecord::Migration
2
+ def self.up
3
+
4
+ unless table_exists?(:compass_ae_instances)
5
+ create_table :compass_ae_instances do |t|
6
+ t.decimal :version
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+
12
+ # Create parties table
13
+ unless table_exists?(:parties)
14
+ create_table :parties do |t|
15
+ t.column :description, :string
16
+ t.column :business_party_id, :integer
17
+ t.column :business_party_type, :string
18
+ t.column :list_view_image_id, :integer
19
+
20
+ #This field is here to provide a direct way to map CompassERP
21
+ #business parties to unified idenfiers in organizations if they
22
+ #have been implemented in an enterprise.
23
+ t.column :enterprise_identifier, :string
24
+ t.timestamps
25
+ end
26
+ add_index :parties, [:business_party_id, :business_party_type], :name => "besi_1"
27
+ end
28
+
29
+ # Create party_roles table
30
+ unless table_exists?(:party_roles)
31
+ create_table :party_roles do |t|
32
+ #this column holds the class name of the
33
+ #subtype of party-to-role_type relatsionship
34
+ t.column :type, :string
35
+ #xref between party and role_type
36
+ t.column :party_id, :integer
37
+ t.column :role_type_id, :integer
38
+ t.timestamps
39
+ end
40
+ add_index :party_roles, :party_id
41
+ add_index :party_roles, :role_type_id
42
+ end
43
+
44
+
45
+ # Create role_types table
46
+ unless table_exists?(:role_types)
47
+ create_table :role_types do |t|
48
+ #these columns are required to support the behavior of the plugin 'awesome_nested_set'
49
+ t.column :parent_id, :integer
50
+ t.column :lft, :integer
51
+ t.column :rgt, :integer
52
+
53
+ #custom columns go here
54
+ t.column :description, :string
55
+ t.column :comments, :string
56
+ t.column :internal_identifier, :string
57
+ t.column :external_identifier, :string
58
+ t.column :external_id_source, :string
59
+ t.timestamps
60
+ end
61
+ end
62
+
63
+ # Create relationship_types table
64
+ unless table_exists?(:relationship_types)
65
+ create_table :relationship_types do |t|
66
+ t.column :parent_id, :integer
67
+ t.column :lft, :integer
68
+ t.column :rgt, :integer
69
+
70
+ #custom columns go here
71
+ t.column :valid_from_role_type_id, :integer
72
+ t.column :valid_to_role_type_id, :integer
73
+ t.column :name, :string
74
+ t.column :description, :string
75
+
76
+ t.column :internal_identifier, :string
77
+ t.column :external_identifier, :string
78
+ t.column :external_id_source, :string
79
+ t.timestamps
80
+ end
81
+ add_index :relationship_types, :valid_from_role_type_id
82
+ add_index :relationship_types, :valid_to_role_type_id
83
+ end
84
+
85
+ # Create party_relationships table
86
+ unless table_exists?(:party_relationships)
87
+ create_table :party_relationships do |t|
88
+ t.column :description, :string
89
+ t.column :party_id_from, :integer
90
+ t.column :party_id_to, :integer
91
+ t.column :role_type_id_from, :integer
92
+ t.column :role_type_id_to, :integer
93
+ t.column :status_type_id, :integer
94
+ t.column :priority_type_id, :integer
95
+ t.column :relationship_type_id, :integer
96
+ t.column :from_date, :date
97
+ t.column :thru_date, :date
98
+ t.column :external_identifier, :string
99
+ t.column :external_id_source, :string
100
+ t.timestamps
101
+ end
102
+ add_index :party_relationships, :status_type_id
103
+ add_index :party_relationships, :priority_type_id
104
+ add_index :party_relationships, :relationship_type_id
105
+ end
106
+
107
+ # Create organizations table
108
+ unless table_exists?(:organizations)
109
+ create_table :organizations do |t|
110
+ t.column :description, :string
111
+ t.column :tax_id_number, :string
112
+ t.timestamps
113
+ end
114
+ end
115
+
116
+ # Create individuals table
117
+ unless table_exists?(:individuals)
118
+ create_table :individuals do |t|
119
+ t.column :party_id, :integer
120
+ t.column :current_last_name, :string
121
+ t.column :current_first_name, :string
122
+ t.column :current_middle_name, :string
123
+ t.column :current_personal_title, :string
124
+ t.column :current_suffix, :string
125
+ t.column :current_nickname, :string
126
+ t.column :gender, :string, :limit => 1
127
+ t.column :birth_date, :date
128
+ t.column :height, :decimal, :precision => 5, :scale => 2
129
+ t.column :weight, :integer
130
+ t.column :mothers_maiden_name, :string
131
+ t.column :marital_status, :string, :limit => 1
132
+ t.column :social_security_number, :string
133
+ t.column :current_passport_number, :integer
134
+
135
+ t.column :current_passport_expire_date, :date
136
+ t.column :total_years_work_experience, :integer
137
+ t.column :comments, :string
138
+ t.column :encrypted_ssn, :string
139
+ t.column :temp_ssn, :string
140
+ t.column :salt, :string
141
+ t.column :ssn_last_four, :string
142
+ t.timestamps
143
+ end
144
+ add_index :individuals, :party_id
145
+ end
146
+
147
+ # Create contacts table
148
+ unless table_exists?(:contacts)
149
+ create_table :contacts do |t|
150
+ t.column :party_id, :integer
151
+ t.column :contact_mechanism_id, :integer
152
+ t.column :contact_mechanism_type, :string
153
+
154
+ t.column :external_identifier, :string
155
+ t.column :external_id_source, :string
156
+
157
+ t.timestamps
158
+ end
159
+ add_index :contacts, :party_id
160
+ add_index :contacts, [:contact_mechanism_id, :contact_mechanism_type], :name => "besi_2"
161
+ end
162
+
163
+ # Create contact_types
164
+ unless table_exists?(:contact_types)
165
+ create_table :contact_types do |t|
166
+ t.column :parent_id, :integer
167
+ t.column :lft, :integer
168
+ t.column :rgt, :integer
169
+
170
+ #custom columns go here
171
+
172
+ t.column :description, :string
173
+ t.column :comments, :string
174
+
175
+ t.column :internal_identifier, :string
176
+ t.column :external_identifier, :string
177
+ t.column :external_id_source, :string
178
+
179
+ t.timestamps
180
+ end
181
+ add_index :contact_types, :parent_id
182
+ end
183
+
184
+ # Create contact_purposes
185
+ unless table_exists?(:contact_purposes)
186
+ create_table :contact_purposes do |t|
187
+
188
+ t.column :parent_id, :integer
189
+ t.column :lft, :integer
190
+ t.column :rgt, :integer
191
+
192
+ #custom columns go here
193
+
194
+ t.column :description, :string
195
+ t.column :comments, :string
196
+
197
+ t.column :internal_identifier, :string
198
+ t.column :external_identifier, :string
199
+ t.column :external_id_source, :string
200
+
201
+ t.timestamps
202
+ end
203
+ add_index :contact_purposes, :parent_id
204
+
205
+ end
206
+
207
+ unless table_exists?(:contact_purposes_contacts)
208
+ create_table :contact_purposes_contacts, {:id => false} do |t|
209
+ t.column :contact_id, :integer
210
+ t.column :contact_purpose_id, :integer
211
+ end
212
+ add_index :contact_purposes_contacts, [:contact_id, :contact_purpose_id], :name => "contact_purposes_contacts_index"
213
+ end
214
+
215
+ # Create postal_addresses (a contact_mechanism)
216
+ unless table_exists?(:postal_addresses)
217
+ create_table :postal_addresses do |t|
218
+ t.column :address_line_1, :string
219
+ t.column :address_line_2, :string
220
+ t.column :city, :string
221
+ t.column :state, :string
222
+ t.column :zip, :string
223
+ t.column :country, :string
224
+ t.column :description, :string
225
+ t.column :geo_country_id, :integer
226
+ t.column :geo_zone_id, :integer
227
+ t.timestamps
228
+ end
229
+ add_index :postal_addresses, :geo_country_id
230
+ add_index :postal_addresses, :geo_zone_id
231
+ end
232
+
233
+ # Create email_addresses (a contact_mechanism)
234
+ unless table_exists?(:email_addresses)
235
+ create_table :email_addresses do |t|
236
+ t.column :email_address, :string
237
+ t.column :description, :string
238
+
239
+ t.timestamps
240
+ end
241
+ end
242
+
243
+ # Create phone_numbers table (A contact_mechanism)
244
+ unless table_exists?(:phone_numbers)
245
+ create_table :phone_numbers do |t|
246
+ t.column :phone_number, :string
247
+ t.column :description, :string
248
+
249
+ t.timestamps
250
+ end
251
+ end
252
+
253
+ unless table_exists?(:party_search_facts)
254
+ create_table :party_search_facts do |t|
255
+ t.column :party_id, :integer
256
+ t.column :eid, :string
257
+ t.column :type, :string
258
+ t.column :roles, :text
259
+ t.column :party_description, :string
260
+ t.column :party_business_party_type, :string
261
+ t.column :user_login, :string
262
+ t.column :individual_current_last_name, :string
263
+ t.column :individual_current_first_name, :string
264
+ t.column :individual_current_middle_name, :string
265
+ t.column :individual_birth_date, :string
266
+ t.column :individual_ssn, :string
267
+ t.column :party_phone_number, :string
268
+ t.column :party_email_address, :string
269
+ t.column :party_address_1, :string
270
+ t.column :party_address_2, :string
271
+ t.column :party_primary_address_city, :string
272
+ t.column :party_primary_address_state, :string
273
+ t.column :party_primary_address_zip, :string
274
+ t.column :party_primary_address_country, :string
275
+ t.column :user_enabled, :boolean
276
+ t.column :user_type, :string
277
+ t.column :reindex, :boolean
278
+ t.timestamps
279
+ end
280
+ end
281
+
282
+ unless table_exists?(:money)
283
+ create_table :money do |t|
284
+ t.string :description
285
+ t.float :amount
286
+ t.references :currency
287
+ t.timestamps
288
+ end
289
+ add_index :money, :currency_id
290
+ end
291
+
292
+ unless table_exists?(:currencies)
293
+ create_table :currencies do |t|
294
+ t.string :name
295
+ t.string :definition
296
+ t.string :internal_identifier # aka alphabetic_code
297
+ t.string :numeric_code
298
+ t.string :major_unit_symbol
299
+ t.string :minor_unit_symbol
300
+ t.string :ratio_of_minor_unit_to_major_unit
301
+ t.string :postfix_label
302
+ t.datetime :introduction_date
303
+ t.datetime :expiration_date
304
+ t.timestamps
305
+ end
306
+ add_index :currencies, :internal_identifier
307
+ end
308
+
309
+ ## categories
310
+ unless table_exists?(:categories)
311
+ create_table :categories do |t|
312
+ t.string :description
313
+ t.string :external_identifier
314
+ t.datetime :from_date
315
+ t.datetime :to_date
316
+ t.string :internal_identifier
317
+
318
+ # polymorphic assns
319
+ t.integer :category_record_id
320
+ t.string :category_record_type
321
+
322
+ # nested set cols
323
+ t.integer :parent_id
324
+ t.integer :lft
325
+ t.integer :rgt
326
+
327
+ t.timestamps
328
+ end
329
+ add_index :categories, [:category_record_id, :category_record_type], :name => "category_polymorphic"
330
+ end
331
+
332
+ ## category_classifications
333
+ unless table_exists?(:category_classifications)
334
+ create_table :category_classifications do |t|
335
+ t.integer :category_id
336
+ t.string :classification_type
337
+ t.integer :classification_id
338
+ t.datetime :from_date
339
+ t.datetime :to_date
340
+
341
+ t.timestamps
342
+ end
343
+ add_index :category_classifications, [:classification_id, :classification_type], :name => "classification_polymorphic"
344
+ end
345
+
346
+ ## descriptive_assets
347
+ unless table_exists?(:descriptive_assets)
348
+ create_table :descriptive_assets do |t|
349
+ t.references :view_type
350
+ t.string :internal_identifier
351
+ t.text :description
352
+ t.string :external_identifier
353
+ t.string :external_id_source
354
+ t.references :described_record, :polymorphic => true
355
+
356
+ t.timestamps
357
+ end
358
+
359
+ add_index :descriptive_assets, :view_type_id
360
+ add_index :descriptive_assets, [:described_record_id, :described_record_type], :name => 'described_record_idx'
361
+ end
362
+
363
+ unless table_exists?(:view_types)
364
+ create_table :view_types do |t|
365
+ t.string :internal_identifier
366
+ t.string :description
367
+
368
+ t.timestamps
369
+ end
370
+ end
371
+
372
+ unless table_exists?(:geo_countries)
373
+ create_table :geo_countries do |t|
374
+ t.column :name, :string
375
+ t.column :iso_code_2, :string, :length => 2
376
+ t.column :iso_code_3, :string, :length => 3
377
+ t.column :display, :boolean, :default => true
378
+ t.column :external_id, :integer
379
+ t.column :created_at, :datetime
380
+ end
381
+ add_index :geo_countries, :name
382
+ add_index :geo_countries, :iso_code_2
383
+ end
384
+
385
+ unless table_exists?(:geo_zones)
386
+ create_table :geo_zones do |t|
387
+ t.column :geo_country_id, :integer
388
+ t.column :zone_code, :string, :default => 2
389
+ t.column :zone_name, :string
390
+ t.column :created_at, :datetime
391
+ end
392
+ add_index :geo_zones, :geo_country_id
393
+ add_index :geo_zones, :zone_name
394
+ add_index :geo_zones, :zone_code
395
+ end
396
+
397
+ unless table_exists?(:notes)
398
+ create_table :notes do |t|
399
+ t.integer :created_by_id
400
+ t.text :content
401
+ t.references :noted_record, :polymorphic => true
402
+ t.references :note_type
403
+
404
+ t.timestamps
405
+ end
406
+
407
+ add_index :notes, [:noted_record_id, :noted_record_type]
408
+ add_index :notes, :note_type_id
409
+ add_index :notes, :created_by_id
410
+ add_index :notes, :content
411
+ end
412
+
413
+ unless table_exists?(:note_types)
414
+ create_table :note_types do |t|
415
+ #these columns are required to support the behavior of the plugin 'awesome_nested_set'
416
+ t.integer :parent_id
417
+ t.integer :lft
418
+ t.integer :rgt
419
+
420
+ t.string :description
421
+ t.string :internal_identifier
422
+ t.string :external_identifier
423
+ t.references :note_type_record, :polymorphic => true
424
+
425
+ t.timestamps
426
+ end
427
+
428
+ add_index :note_types, [:note_type_record_id, :note_type_record_type], :name => "note_type_record_idx"
429
+ end
430
+
431
+ unless table_exists?(:valid_note_types)
432
+ create_table :valid_note_types do |t|
433
+ t.references :valid_note_type_record, :polymorphic => true
434
+ t.references :note_type
435
+
436
+ t.timestamps
437
+ end
438
+
439
+ add_index :valid_note_types, [:valid_note_type_record_id, :valid_note_type_record_type], :name => "valid_note_type_record_idx"
440
+ add_index :valid_note_types, :note_type_id
441
+ end
442
+
443
+ end
444
+
445
+ def self.down
446
+ [
447
+ :currencies, :money,
448
+ :party_search_facts, :phone_numbers, :email_addresses,
449
+ :postal_addresses, :contact_purposes, :contact_types,
450
+ :contacts, :individuals, :organizations,
451
+ :party_relationships, :relationship_types, :role_types,
452
+ :party_roles, :parties, :categories, :category_classifications,
453
+ :descriptive_assets, :view_types, :notes, :note_types, :valid_note_types, :compass_ae_instances
454
+ ].each do |tbl|
455
+ if table_exists?(tbl)
456
+ drop_table tbl
457
+ end
458
+ end
459
+
460
+ end
461
+ end
@@ -0,0 +1,15 @@
1
+ class CreateCompassAeInstance < ActiveRecord::Migration
2
+ def self.up
3
+ unless table_exists?(:compass_ae_instances)
4
+ create_table :compass_ae_instances do |t|
5
+ t.decimal :version
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
11
+
12
+ def self.down
13
+ drop_table :compass_ae_instances
14
+ end
15
+ end
@@ -0,0 +1,63 @@
1
+ class AddNotes < ActiveRecord::Migration
2
+ def self.up
3
+ unless table_exists?(:notes)
4
+ create_table :notes do |t|
5
+ t.integer :created_by_id
6
+ t.text :content
7
+ t.references :noted_record, :polymorphic => true
8
+ t.references :note_type
9
+
10
+ t.timestamps
11
+ end
12
+
13
+ add_index :notes, [:noted_record_id, :noted_record_type]
14
+ add_index :notes, :note_type_id
15
+ add_index :notes, :created_by_id
16
+ add_index :notes, :content
17
+ end
18
+
19
+ unless table_exists?(:note_types)
20
+ create_table :note_types do |t|
21
+ #these columns are required to support the behavior of the plugin 'awesome_nested_set'
22
+ t.integer :parent_id
23
+ t.integer :lft
24
+ t.integer :rgt
25
+
26
+ t.string :description
27
+ t.string :internal_identifier
28
+ t.string :external_identifier
29
+ t.references :note_type_record, :polymorphic => true
30
+
31
+ t.timestamps
32
+ end
33
+
34
+ add_index :note_types, [:note_type_record_id, :note_type_record_type], :name => "note_type_record_idx"
35
+ end
36
+
37
+ unless table_exists?(:valid_note_types)
38
+ create_table :valid_note_types do |t|
39
+ t.references :valid_note_type_record, :polymorphic => true
40
+ t.references :note_type
41
+
42
+ t.timestamps
43
+ end
44
+
45
+ add_index :valid_note_types, [:valid_note_type_record_id, :valid_note_type_record_type], :name => "valid_note_type_record_idx"
46
+ add_index :valid_note_types, :note_type_id
47
+ end
48
+ end
49
+
50
+ def self.down
51
+ if table_exists?(:valid_note_types)
52
+ drop_table :valid_note_types
53
+ end
54
+
55
+ if table_exists?(:note_types)
56
+ drop_table :note_types
57
+ end
58
+
59
+ if table_exists?(:notes)
60
+ drop_table :notes
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,103 @@
1
+ # Extension to make it easy to read and write data to a file.
2
+ class ActiveRecord::Base
3
+
4
+ class << self
5
+
6
+ # Writes content of this table to db/table_name.yml, or the specified file.
7
+ #
8
+ # Writes all content by default, but can be limited.
9
+ def dump_to_file(path=nil, limit=nil)
10
+ opts = {}
11
+ opts[:limit] = limit if limit
12
+ path ||= "db/#{table_name}.yml"
13
+ write_file(File.expand_path(path, Rails.root), self.find(:all, opts).to_yaml)
14
+ end
15
+
16
+ # Delete existing data in database and load fresh from file in db/table_name.yml
17
+ def load_from_file(path=nil)
18
+ path ||= "db/#{table_name}.yml"
19
+
20
+ self.destroy_all
21
+
22
+ if connection.respond_to?(:reset_pk_sequence!)
23
+ connection.reset_pk_sequence!(table_name)
24
+ end
25
+
26
+ records = YAML::load( File.open( File.expand_path(path, Rails.root) ) )
27
+ records.each do |record|
28
+ record_copy = self.new(record.attributes)
29
+ record_copy.id = record.id
30
+
31
+ # For Single Table Inheritance
32
+ klass_col = record.class.inheritance_column.to_sym
33
+ if record[klass_col]
34
+ record_copy.type = record[klass_col]
35
+ end
36
+
37
+ record_copy.save
38
+ end
39
+
40
+ if connection.respond_to?(:reset_pk_sequence!)
41
+ connection.reset_pk_sequence!(table_name)
42
+ end
43
+ end
44
+
45
+ # Write a file that can be loaded with +fixture :some_table+ in tests.
46
+ # Uses existing data in the database.
47
+ #
48
+ # Will be written to +test/fixtures/table_name.yml+. Can be restricted to some number of rows.
49
+ def to_fixture(limit=nil)
50
+ opts = {}
51
+ opts[:limit] = limit if limit
52
+
53
+ write_file(File.expand_path("test/fixtures/#{table_name}.yml", Rails.root),
54
+ self.find(:all, opts).inject({}) { |hsh, record|
55
+ hsh.merge("#{table_name.singularize}_#{'%05i' % record.id rescue record.id}" => record.attributes)
56
+ }.to_yaml(:SortKeys => true))
57
+ habtm_to_fixture
58
+ end
59
+
60
+ # Write the habtm association table
61
+ def habtm_to_fixture
62
+ joins = self.reflect_on_all_associations.select { |j|
63
+ j.macro == :has_and_belongs_to_many
64
+ }
65
+ joins.each do |join|
66
+ hsh = {}
67
+ connection.select_all("SELECT * FROM #{join.options[:join_table]}").each_with_index { |record, i|
68
+ hsh["join_#{'%05i' % i}"] = record
69
+ }
70
+ write_file(File.expand_path("test/fixtures/#{join.options[:join_table]}.yml", Rails.root), hsh.to_yaml(:SortKeys => true))
71
+ end
72
+ end
73
+
74
+ # Generates a basic fixture file in test/fixtures that lists the table's field names.
75
+ #
76
+ # You can use it as a starting point for your own fixtures.
77
+ #
78
+ # record_1:
79
+ # name:
80
+ # rating:
81
+ # record_2:
82
+ # name:
83
+ # rating:
84
+ #
85
+ # TODO Automatically add :id field if there is one.
86
+ def to_skeleton
87
+ record = {
88
+ "record_1" => self.new.attributes,
89
+ "record_2" => self.new.attributes
90
+ }
91
+ write_file(File.expand_path("test/fixtures/#{table_name}.yml", Rails.root),
92
+ record.to_yaml)
93
+ end
94
+
95
+ def write_file(path, content) # :nodoc:
96
+ f = File.new(path, "w+")
97
+ f.puts content
98
+ f.close
99
+ end
100
+
101
+ end
102
+
103
+ end
@@ -0,0 +1,37 @@
1
+ module ErpBaseErpSvcs
2
+ module Command
3
+ extend self
4
+
5
+ def banner
6
+ %(
7
+ Usage:
8
+ compass_ae new <app_name> [setup_opt] [rails_opt] Creates a new Rails Compass AE Application
9
+ setup_opt:
10
+ --skip-setup generate only the rails infrastructure
11
+ rails_opt: all the options accepted by the rails command
12
+
13
+ erp --help|-h This help screen)
14
+ end
15
+
16
+ def run
17
+ command = ARGV.shift
18
+ case command
19
+ when nil
20
+ raise "The command is missing!"
21
+ when 'skip'
22
+ app_name = ARGV.shift
23
+ raise "The application name is missing!" if app_name.nil?
24
+ puts 'Generating Rails infrastructure...'
25
+ system "rails new #{app_name} #{ARGV * ' '}"
26
+ when 'new'
27
+ template_path = File.join(File.dirname(__FILE__), 'rails_template.rb')
28
+ app_name = ARGV.shift
29
+ raise "The application name is missing!" if app_name.nil?
30
+ puts 'Generating Rails infrastructure...'
31
+ system "rails new #{app_name} #{ARGV * ' '} -m #{template_path}"
32
+ end
33
+
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,27 @@
1
+ module ErpBaseErpSvcs
2
+ module Config
3
+ class << self
4
+ attr_accessor :compass_ae_extensions_directory
5
+
6
+ def init!
7
+ @defaults = {:@compass_ae_extensions_directory => nil}
8
+ end
9
+
10
+ def reset!
11
+ @defaults.each do |k,v|
12
+ instance_variable_set(k,v)
13
+ end
14
+ end
15
+
16
+ def configure(&blk)
17
+ @configure_blk = blk
18
+ end
19
+
20
+ def configure!
21
+ @configure_blk.call(self) if @configure_blk
22
+ end
23
+ end
24
+ init!
25
+ reset!
26
+ end
27
+ end