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,27 @@
1
+ require 'has_many_polymorphic'
2
+ require 'attr_encrypted'
3
+ require 'awesome_nested_set'
4
+ require 'data_migrator'
5
+
6
+ module ErpBaseErpSvcs
7
+ class Engine < Rails::Engine
8
+ isolate_namespace ErpBaseErpSvcs
9
+
10
+ config.erp_base_erp_svcs = ErpBaseErpSvcs::Config
11
+
12
+ ActiveSupport.on_load(:active_record) do
13
+ include ErpBaseErpSvcs::Extensions::ActiveRecord::IsDescribable
14
+ include ErpBaseErpSvcs::Extensions::ActiveRecord::HasNotes
15
+ include ErpBaseErpSvcs::Extensions::ActiveRecord::ActsAsNoteType
16
+ include ErpBaseErpSvcs::Extensions::ActiveRecord::ActsAsErpType
17
+ include ErpBaseErpSvcs::Extensions::ActiveRecord::ActsAsCategory
18
+ include ErpBaseErpSvcs::Extensions::ActiveRecord::HasContact
19
+ extend ErpBaseErpSvcs::Extensions::ActiveRecord::StiInstantiation::ActMacro
20
+ end
21
+
22
+ config.to_prepare do
23
+ Rails::Engine.load_extensions
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,50 @@
1
+ module ErpBaseErpSvcs
2
+ module Extensions
3
+ module ActiveRecord
4
+ module ActsAsCategory
5
+ def self.included(base)
6
+ base.extend(ClassMethods)
7
+ end
8
+
9
+ module ClassMethods
10
+ def acts_as_category
11
+ extend ActsAsCategory::SingletonMethods
12
+ include ActsAsCategory::InstanceMethods
13
+
14
+ after_initialize :initialize_category
15
+ after_create :save_category
16
+ after_update :save_category
17
+ after_destroy :destroy_category
18
+
19
+ has_one :category, :as => :category_record
20
+ end
21
+ end
22
+
23
+ module SingletonMethods
24
+ end
25
+
26
+ module InstanceMethods
27
+ def method_missing(name, *args)
28
+ self.category.respond_to?(name) ? self.category.send(name, *args) : super
29
+ end
30
+
31
+ def save_category
32
+ self.category.save
33
+ end
34
+
35
+ def destroy_category
36
+ self.category.destroy
37
+ end
38
+
39
+ def initialize_category
40
+ if (self.category.nil?)
41
+ category = Category.new
42
+ self.category = category
43
+ category.category_record = self
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,148 @@
1
+ module ErpBaseErpSvcs
2
+ module Extensions
3
+ module ActiveRecord
4
+ module ActsAsErpType
5
+ def self.included(base)
6
+ base.extend(ClassMethods)
7
+ end
8
+
9
+ # declare the class level helper methods which
10
+ # will load the relevant instance methods
11
+ # defined below when invoked
12
+ module ClassMethods
13
+
14
+ def acts_as_erp_type
15
+
16
+ # this is at the class level
17
+ # add any class level manipulations you need here, like has_many, etc.
18
+ extend ActsAsErpType::ActsAsSingletonMethods
19
+ include ActsAsErpType::ActsAsInstanceMethods
20
+
21
+ if ::ActiveRecord::Base.connection.tables.include?(self.table_name)
22
+ # find each valid value for the domain type (erp_type) in question
23
+ # we will then create a class method with the name of the internal idenfifier
24
+ # for that type
25
+ valid_values = self.all
26
+
27
+ # the class method will return a populated instance of the correct type
28
+ valid_values.each do | vv |
29
+ (class << self; self; end).instance_eval { define_method vv.internal_identifier, Proc.new{vv} } unless vv.internal_identifier.nil?
30
+ end
31
+ end
32
+ end
33
+
34
+ def belongs_to_erp_type(model_id = nil, options = {})
35
+
36
+ @model_id = model_id
37
+ self.belongs_to model_id, options
38
+ extend ActsAsErpType::BelongsToSingletonMethods
39
+ include ActsAsErpType::BelongsToInstanceMethods
40
+
41
+ end
42
+
43
+ end
44
+
45
+ # Adds singleton methods.
46
+ module ActsAsSingletonMethods
47
+
48
+ def valid_types
49
+ self.all.collect{ |type| type.internal_identifier.to_sym }
50
+ end
51
+
52
+ def valid_type?( type_name_string )
53
+ sym_list = self.all.collect{ |type| type.internal_identifier.to_sym }
54
+ sym_list.include?(type_name_string.to_sym)
55
+ end
56
+
57
+ def eid( external_identifier_string )
58
+ where('external_identifier = ?', external_identifier_string.to_s).first
59
+ end
60
+
61
+ def iid( internal_identifier_string )
62
+ where('internal_identifier = ?', internal_identifier_string.to_s).first
63
+ end
64
+
65
+ end
66
+
67
+ module BelongsToSingletonMethods
68
+
69
+ def fbet( domain_value, options = {})
70
+ find_by_erp_type( domain_value, options )
71
+ end
72
+
73
+ def find_by_erp_type(domain_value, options = {})
74
+
75
+ # puts "options...."
76
+ # puts options[:class]
77
+ # puts options[:foreign_key]
78
+
79
+ erp_type = options[:class] || @model_id
80
+ fk_str = options[:foreign_key] || erp_type.to_s + '_id'
81
+
82
+ #***************************************************************
83
+ # uncomment these lines for a variety of debugging information
84
+ #***************************************************************
85
+ # klass = self.to_s.underscore + '_type'
86
+ # puts "default class name"
87
+ # puts klass
88
+
89
+ # puts "model id"
90
+ # puts @model_id
91
+ #
92
+ # puts "finding by erp type"
93
+ # puts "self is: #{self}"
94
+ # puts "type is: #{erp_type}"
95
+
96
+ # puts "fk_str for in clause..."
97
+ # puts fk_str
98
+
99
+ type_klass = Kernel.const_get( erp_type.to_s.camelcase )
100
+ in_clause_array = type_klass.send( domain_value.to_sym )
101
+
102
+ where(fk_str + ' in (?)', in_clause_array)
103
+
104
+ end
105
+
106
+ def fabet( domain_value, options = {} )
107
+ find_all_by_erp_type( domain_value, options )
108
+ end
109
+
110
+ def find_all_by_erp_type( domain_value, options = {} )
111
+
112
+ erp_type = options[:class] || @model_id
113
+ fk_str = options[:foreign_key] || erp_type.to_s + '_id'
114
+
115
+ type_klass = Kernel.const_get( erp_type.to_s.camelcase )
116
+ in_clause_array = type_klass.send( domain_value.to_sym ).full_set
117
+
118
+ #puts "id for in clause..."
119
+ #id_str = erp_type.to_s + '_id'
120
+
121
+ where(fk_str + ' in (?)', in_clause_array)
122
+
123
+ end
124
+ end
125
+
126
+
127
+ # Adds instance methods.
128
+ module ActsAsInstanceMethods
129
+
130
+ # def instance_method_for_acts_as
131
+ # puts "Instance with ID #{self.id}"
132
+ # end
133
+
134
+ end
135
+
136
+ # Adds instance methods.
137
+ module BelongsToInstanceMethods
138
+
139
+ # def instance_method_for_belongs_to
140
+ # puts "Instance with ID #{self.id}"
141
+ # end
142
+
143
+ end
144
+ end
145
+ end
146
+ end
147
+ end
148
+
@@ -0,0 +1,47 @@
1
+ module ErpBaseErpSvcs
2
+ module Extensions
3
+ module ActiveRecord
4
+ module ActsAsNoteType
5
+ def self.included(base)
6
+ base.extend(ClassMethods)
7
+ end
8
+
9
+ module ClassMethods
10
+ def acts_as_note_type
11
+ extend ActsAsNoteType::SingletonMethods
12
+ include ActsAsNoteType::InstanceMethods
13
+
14
+ after_initialize :initialize_note_type
15
+ after_create :save_note_type
16
+ after_update :save_note_type
17
+ after_destroy :destroy_note_type
18
+
19
+ has_one :note_type_record, :as => :note_type_record, :class_name => 'NoteType'
20
+ end
21
+ end
22
+
23
+ module SingletonMethods
24
+ end
25
+
26
+ module InstanceMethods
27
+ def save_note_type
28
+ self.note_type_record.save
29
+ end
30
+
31
+ def destroy_note_type
32
+ self.note_type_record.destroy
33
+ end
34
+
35
+ def initialize_note_type
36
+ if (self.note_type_record.nil?)
37
+ note_type_record = NoteType.new
38
+ self.note_type_record = note_type_record
39
+ self.note_type_record.note_type_record = self
40
+ end
41
+ end
42
+
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,46 @@
1
+ module RussellEdge
2
+ class DataMigrator
3
+
4
+ class << self
5
+ def prepare_upgrade_migrations
6
+ dirs = Rails::Application::Railties.engines.map{|p| p.config.root.to_s}
7
+ dirs.each do |dir|
8
+ if File.directory? File.join(dir,'db/data_migrations/upgrade')
9
+ target = File.join(dir,'db/data_migrations/')
10
+ files = Dir["#{target}*.rb"]
11
+ unless files.empty?
12
+ FileUtils.mkdir_p "#{target}app/"
13
+ FileUtils.cp files, "#{target}app/"
14
+ puts "copied #{files.size} upgrade data migrations to #{target}app"
15
+ end
16
+
17
+ files = Dir["#{File.join(dir,'db/data_migrations/upgrade')}/*.rb"]
18
+ FileUtils.cp files, File.join(dir,'db/data_migrations/')
19
+ end
20
+ end
21
+ end
22
+
23
+ def cleanup_upgrade_migrations
24
+ dirs = Rails::Application::Railties.engines.map{|p| p.config.root.to_s}
25
+ dirs.each do |dir|
26
+ if File.directory? File.join(dir,'db/data_migrations/app')
27
+ target = File.join(dir,'db/data_migrations/')
28
+ files = Dir["#{target}/*.rb"]
29
+ unless files.empty?
30
+ FileUtils.rm files
31
+ puts "removed #{files.size} data migrations from #{target}"
32
+ end
33
+
34
+ files = Dir["#{target}/app/*.rb"]
35
+ unless files.empty?
36
+ FileUtils.cp files, target
37
+ puts "copied #{files.size} data migrations back to #{target}"
38
+ end
39
+ FileUtils.rm_rf "#{target}/app"
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ end#DataMigrator
46
+ end#RussellEdge
@@ -0,0 +1,56 @@
1
+ module ErpBaseErpSvcs
2
+ module Extensions
3
+ module ActiveRecord
4
+ module HasContact
5
+ def self.included(base)
6
+ base.extend(ClassMethods)
7
+ end
8
+
9
+ module ClassMethods
10
+ def has_contact
11
+ extend HasContact::SingletonMethods
12
+ include HasContact::InstanceMethods
13
+
14
+ after_initialize :initialize_contact
15
+ after_create :save_contact
16
+ after_update :save_contact
17
+ after_destroy :destroy_contact
18
+
19
+ has_one :contact, :as => :contact_mechanism
20
+ end
21
+ end
22
+
23
+ module SingletonMethods
24
+ end
25
+
26
+ module InstanceMethods
27
+ # return first contact purpose
28
+ def contact_purpose
29
+ contact.contact_purposes.count == 0 ? nil : contact.contact_purposes.first
30
+ end
31
+
32
+ # return all contact purposes
33
+ def contact_purposes
34
+ contact.contact_purposes
35
+ end
36
+
37
+ def save_contact
38
+ self.contact.save
39
+ end
40
+
41
+ def destroy_contact
42
+ self.contact.destroy
43
+ end
44
+
45
+ def initialize_contact
46
+ if self.new_record? and self.contact.nil?
47
+ self.contact = Contact.new
48
+ self.contact.description = self.description
49
+ end
50
+ end
51
+
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,32 @@
1
+ module ErpBaseErpSvcs
2
+ module Extensions
3
+ module ActiveRecord
4
+ module HasNotes
5
+ def self.included(base)
6
+ base.extend(ClassMethods)
7
+ end
8
+
9
+ module ClassMethods
10
+ def has_notes
11
+
12
+ has_many :notes, :as => :noted_record, :dependent => :delete_all do
13
+ def by_type(note_type)
14
+ find_by_note_type_id(note_type.id)
15
+ end
16
+ end
17
+
18
+ extend ErpBaseErpSvcs::Extensions::ActiveRecord::HasNotes
19
+ include ErpBaseErpSvcs::Extensions::ActiveRecord::HasNotes
20
+
21
+ end
22
+ end
23
+
24
+ module SingletonMethods
25
+ end
26
+
27
+ module InstanceMethods
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,44 @@
1
+ module ErpBaseErpSvcs
2
+ module Extensions
3
+ module ActiveRecord
4
+ module IsDescribable
5
+
6
+ def self.included(base)
7
+ base.extend(ClassMethods)
8
+ end
9
+
10
+ module ClassMethods
11
+
12
+ def is_describable
13
+ has_many :descriptions, :class_name => 'DescriptiveAsset', :as => :described_record, :dependent => :destroy
14
+
15
+ extend IsDescribable::SingletonMethods
16
+ include IsDescribable::InstanceMethods
17
+
18
+ end
19
+ end
20
+
21
+ module SingletonMethods
22
+ end
23
+
24
+ module InstanceMethods
25
+ def find_descriptions_by_view_type(view_iid)
26
+ self.descriptions.where('view_type_id = ?', ViewType.find_by_internal_identifier(view_iid).id)
27
+ end
28
+
29
+ def find_description_by_iid(iid)
30
+ self.descriptions.where('internal_identifier = ?', iid).first
31
+ end
32
+
33
+ def add_description(view_type, description)
34
+ descriptive_asset = DescriptiveAsset.create(
35
+ :view_type => view_type,
36
+ :description => description)
37
+ descriptive_asset.described_record = self
38
+ self.descriptions << descriptive_asset
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,76 @@
1
+ ActiveRecord::Migrator.instance_eval do
2
+ def prepare_migrations
3
+ target = "#{Rails.root}/db/migrate/"
4
+ # first copy all app migrations away
5
+ files = Dir["#{target}*.rb"]
6
+
7
+ unless files.empty?
8
+ FileUtils.mkdir_p "#{target}app/"
9
+ FileUtils.cp files, "#{target}app/"
10
+ puts "copied #{files.size} migrations to db/migrate/app"
11
+ end
12
+
13
+ dirs = Rails::Application::Railties.engines.map{|p| p.config.root.to_s}
14
+ files = Dir["{#{dirs.join(',')}}/db/migrate/*.rb"]
15
+
16
+ unless files.empty?
17
+ FileUtils.mkdir_p target
18
+ FileUtils.cp files, target
19
+ puts "copied #{files.size} migrations to db/migrate"
20
+ end
21
+ end
22
+
23
+ def cleanup_migrations
24
+ target = "#{Rails.root}/db/migrate"
25
+ files = Dir["#{target}/*.rb"]
26
+ unless files.empty?
27
+ FileUtils.rm files
28
+ puts "removed #{files.size} migrations from db/migrate"
29
+ end
30
+ files = Dir["#{target}/app/*.rb"]
31
+ unless files.empty?
32
+ FileUtils.cp files, target
33
+ puts "copied #{files.size} migrations back to db/migrate"
34
+ end
35
+ FileUtils.rm_rf "#{target}/app"
36
+ end
37
+
38
+ def prepare_upgrade_migrations
39
+ dirs = Rails::Application::Railties.engines.map{|p| p.config.root.to_s}
40
+ dirs.each do |dir|
41
+ if File.directory? File.join(dir,'db/migrate/upgrade')
42
+ target = File.join(dir,'db/migrate/')
43
+ files = Dir["#{target}*.rb"]
44
+ unless files.empty?
45
+ FileUtils.mkdir_p "#{target}app/"
46
+ FileUtils.cp files, "#{target}app/"
47
+ puts "copied #{files.size} upgrade migrations to #{target}app"
48
+ end
49
+
50
+ files = Dir["#{File.join(dir,'db/migrate/upgrade')}/*.rb"]
51
+ FileUtils.cp files, File.join(dir,'db/migrate/')
52
+ end
53
+ end
54
+ end
55
+
56
+ def cleanup_upgrade_migrations
57
+ dirs = Rails::Application::Railties.engines.map{|p| p.config.root.to_s}
58
+ dirs.each do |dir|
59
+ if File.directory? File.join(dir,'db/migrate/app')
60
+ target = File.join(dir,'db/migrate/')
61
+ files = Dir["#{target}/*.rb"]
62
+ unless files.empty?
63
+ FileUtils.rm files
64
+ puts "removed #{files.size} migrations from #{target}"
65
+ end
66
+
67
+ files = Dir["#{target}/app/*.rb"]
68
+ unless files.empty?
69
+ FileUtils.cp files, target
70
+ puts "copied #{files.size} migrations back to #{target}"
71
+ end
72
+ FileUtils.rm_rf "#{target}/app"
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,37 @@
1
+ module ErpBaseErpSvcs
2
+ module Extensions
3
+ module ActiveRecord
4
+ module StiInstantiation
5
+ module ActMacro
6
+ def instantiates_with_sti
7
+ include InstanceMethods
8
+ extend ClassMethods
9
+ instantiates_with_sti?
10
+ end
11
+
12
+ def instantiates_with_sti?
13
+ included_modules.include?(ErpBaseErpSvcs::Extensions::ActiveRecord::StiInstantiation::InstanceMethods)
14
+ end
15
+ end
16
+
17
+ module InstanceMethods
18
+ end
19
+
20
+ module ClassMethods
21
+ def new(*args, &block)
22
+ options = args.first.is_a?(Hash) ? args.first : {}
23
+ type = options[:type] || options['type']
24
+ klass = type.is_a?(Class) ? type : type.constantize if type
25
+
26
+ if type and klass != self
27
+ raise "STI instantiation error: class #{klass.name} should be a descendant of #{self.name}" unless klass < self
28
+ klass.new(*args, &block)
29
+ else
30
+ super
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,20 @@
1
+ Array.class_eval do
2
+
3
+ #convert all elements of array to symbols
4
+ #throw exception if all elements are not of class String
5
+ def to_sym
6
+ new_ary = []
7
+ old_ary = to_ary
8
+
9
+ old_ary.each do |item|
10
+ if item.class == String
11
+ new_ary << item.to_sym
12
+ else
13
+ throw "All array elements must be of class String to use to_sym"
14
+ end
15
+ end
16
+
17
+ new_ary
18
+ end
19
+
20
+ end
@@ -0,0 +1,19 @@
1
+ Hash.class_eval do
2
+ #take keys of hash and transform those to a symbols
3
+ def self.symbolize_keys(item)
4
+ if item.class == Hash
5
+ item.to_options!
6
+ item.each do |key, value|
7
+ self.symbolize_keys(value)
8
+ end
9
+ elsif item.class == Array
10
+ item.each do |array_val|
11
+ self.symbolize_keys(array_val)
12
+ end
13
+ end
14
+
15
+ item
16
+ end
17
+
18
+ end
19
+
@@ -0,0 +1,27 @@
1
+ module ErpBaseErpSvcs
2
+ module Extensions
3
+ module Core
4
+ module Commas
5
+ def commas
6
+ self.to_s =~ /([^\.]*)(\..*)?/
7
+ int, dec = $1.reverse, $2 ? $2 : ""
8
+ while int.gsub!(/(,|\.|^)(\d{3})(\d)/, '\1\2,\3')
9
+ end
10
+ int.reverse + dec
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ class Bignum
18
+ include ErpBaseErpSvcs::Extensions::Core::Commas
19
+ end
20
+
21
+ class Float
22
+ include ErpBaseErpSvcs::Extensions::Core::Commas
23
+ end
24
+
25
+ class Fixnum
26
+ include ErpBaseErpSvcs::Extensions::Core::Commas
27
+ end
@@ -0,0 +1,6 @@
1
+ Object.instance_eval do
2
+ def all_subclasses
3
+ klasses = self.subclasses
4
+ (klasses | klasses.collect do |klass| klass.all_subclasses end).flatten.uniq
5
+ end
6
+ end