erp_base_erp_svcs 3.0.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ #ErpBaseErpSvcs
2
+
3
+ Contains an implementation of the ubiquitous 'party model' for managing people, organizations, roles, relationships and contact information. The models in this library are designed to be useful in a variety of circumstances, including headless SOA implementations and batch operations.
@@ -1,6 +1,7 @@
1
1
  class Category < ActiveRecord::Base
2
2
  acts_as_nested_set
3
-
3
+ include ErpTechSvcs::Utils::DefaultNestedSetMethods
4
+
4
5
  belongs_to :category_record, :polymorphic => true
5
6
  has_many :category_classifications, :dependent => :destroy
6
7
 
@@ -2,10 +2,10 @@ class CompassAeInstance < ActiveRecord::Base
2
2
  has_file_assets
3
3
 
4
4
  def installed_engines
5
- Rails::Application::Railties.engines.map{|e|
6
- name = e.railtie_name.camelize
7
- ErpBaseErpSvcs::ENGINES.include?(name) ? {:name => name, :version => ("#{name}::VERSION".constantize rescue 'N/A')} : nil
8
- }.delete_if {|x| x == nil}
5
+ Rails.application.config.erp_base_erp_svcs.compass_ae_engines.map do |compass_ae_engine|
6
+ klass_name = compass_ae_engine.railtie_name.camelize
7
+ {:name => klass_name, :version => ("#{klass_name}::VERSION::STRING".constantize rescue 'N/A')}
8
+ end
9
9
  end
10
10
 
11
11
  end
@@ -1,7 +1,7 @@
1
1
  class Contact < ActiveRecord::Base
2
2
  has_and_belongs_to_many :contact_purposes
3
3
  belongs_to :party
4
- belongs_to :contact_mechanism, :polymorphic => true, :dependent => :destroy
4
+ belongs_to :contact_mechanism, :polymorphic => true
5
5
 
6
6
  #rather than carry our own description for the abstract -contact-, we'll
7
7
  #delegate that call to the implementor of the -contact_mechanism- interface
@@ -2,7 +2,8 @@ class GeoCountry < ActiveRecord::Base
2
2
  has_many :postal_addresses
3
3
  has_many :geo_zones
4
4
 
5
- validates_presence_of :name
6
- validates_presence_of :iso_code_2
7
- validates_presence_of :iso_code_3
5
+ validates :name, :presence => {:message => 'Name cannot be blank'}
6
+ validates :iso_code_2, :presence => {:message => 'ISO code 2 cannot be blank'}
7
+ validates :iso_code_3, :presence => {:message => 'ISO code 3 cannot be blank'}
8
+
8
9
  end
@@ -2,7 +2,7 @@ class GeoZone < ActiveRecord::Base
2
2
  belongs_to :geo_country
3
3
  has_many :postal_addresses
4
4
 
5
- validates_presence_of :geo_country_id
6
- validates_presence_of :zone_code
7
- validates_presence_of :zone_name
5
+ validates :geo_country_id, :presence => {:message => 'Geo country id cannot be blank'}
6
+ validates :zone_code, :presence => {:message => 'Zone code cannot be blank'}
7
+ validates :zone_name, :presence => {:message => 'Zone name cannot be blank'}
8
8
  end
@@ -407,7 +407,6 @@ class BaseErpServices < ActiveRecord::Migration
407
407
  add_index :notes, [:noted_record_id, :noted_record_type]
408
408
  add_index :notes, :note_type_id
409
409
  add_index :notes, :created_by_id
410
- add_index :notes, :content
411
410
  end
412
411
 
413
412
  unless table_exists?(:note_types)
@@ -1,10 +1,12 @@
1
1
  module ErpBaseErpSvcs
2
2
  module Config
3
3
  class << self
4
- attr_accessor :compass_ae_extensions_directory
4
+ attr_accessor :compass_ae_engines
5
5
 
6
6
  def init!
7
- @defaults = {:@compass_ae_extensions_directory => nil}
7
+ @defaults = {
8
+ :@compass_ae_engines => []
9
+ }
8
10
  end
9
11
 
10
12
  def reset!
@@ -19,8 +19,10 @@ module ErpBaseErpSvcs
19
19
  extend ErpBaseErpSvcs::Extensions::ActiveRecord::StiInstantiation::ActMacro
20
20
  end
21
21
 
22
+ engine = self
22
23
  config.to_prepare do
23
- Rails::Engine.load_extensions
24
+ ErpBaseErpSvcs.register_compass_ae_engine(engine)
25
+ ErpBaseErpSvcs.load_root_compass_ae_framework_extensions
24
26
  end
25
27
 
26
28
  end
@@ -0,0 +1,39 @@
1
+ ActiveRecord::Base.class_eval do
2
+
3
+ #takes array of method names and returns hash with key/value pairs of methods
4
+ def to_hash(options={})
5
+ {}.tap do |hash|
6
+ #check for only option to get only attributes specified
7
+ if options[:only]
8
+ options[:only].each do |attribute|
9
+ attribute = attribute.to_sym
10
+ hash[attribute] = self.send(attribute)
11
+ end
12
+ else
13
+ hash.merge!(self.attributes)
14
+ end
15
+
16
+ #check for methods option
17
+ if options[:methods]
18
+ options[:methods].each do |method|
19
+ if method.is_a?(Hash)
20
+ method.each do |k,v|
21
+ k = k.to_sym
22
+ v = v.to_sym
23
+ hash[v] = self.send(k)
24
+ end
25
+ else
26
+ method = method.to_sym
27
+ hash[method] = self.send(method)
28
+ end
29
+ end
30
+ end
31
+
32
+ #check for additional values
33
+ options[:additional_values].each{|k, v| hash[k] = v} if options[:additional_values]
34
+
35
+ end#end hash tap
36
+ end
37
+ end
38
+
39
+
@@ -4,9 +4,6 @@ require 'erp_base_erp_svcs/extensions/core/hash'
4
4
  require 'erp_base_erp_svcs/extensions/core/numbers'
5
5
  require 'erp_base_erp_svcs/extensions/core/object'
6
6
 
7
- #railties
8
- require 'erp_base_erp_svcs/extensions/railties/engine'
9
-
10
7
  #active record extensions
11
8
  require 'erp_base_erp_svcs/extensions/active_record/acts_as_category'
12
9
  require 'erp_base_erp_svcs/extensions/active_record/acts_as_erp_type'
@@ -17,3 +14,5 @@ require 'erp_base_erp_svcs/extensions/active_record/has_contact'
17
14
  require 'erp_base_erp_svcs/extensions/active_record/migrator'
18
15
  require 'erp_base_erp_svcs/extensions/active_record/data_migrator'
19
16
  require 'erp_base_erp_svcs/extensions/active_record/sti_instantiation'
17
+ require 'erp_base_erp_svcs/extensions/active_record/to_hash'
18
+
@@ -1,3 +1,9 @@
1
1
  module ErpBaseErpSvcs
2
- VERSION = "3.0.0"
2
+ module VERSION #:nodoc:
3
+ MAJOR = 3
4
+ MINOR = 0
5
+ TINY = 1
6
+
7
+ STRING = [MAJOR, MINOR, TINY].compact.join('.')
8
+ end
3
9
  end
@@ -1,3 +1,4 @@
1
+ require "erp_base_erp_svcs/version"
1
2
  require "erp_base_erp_svcs/extensions"
2
3
  require "erp_base_erp_svcs/ar_fixtures"
3
4
  require "erp_base_erp_svcs/config"
@@ -5,13 +6,94 @@ require "erp_base_erp_svcs/engine"
5
6
  require "erp_base_erp_svcs/non_escape_json_string"
6
7
 
7
8
  module ErpBaseErpSvcs
8
- ENGINES = [
9
- "ErpBaseErpSvcs","ErpDevSvcs","ErpTechSvcs","ErpAgreements","ErpTxnsAndAccts","ErpInvoicing",
10
- "ErpCommerce","ErpCommunicationEvents","ErpFinancialAccounting","ErpInventory",
11
- "ErpOrders","ErpProducts","ErpWorkEffort","ErpApp","Knitkit","RailsDbAdmin",
12
- "ErpForms","Console","Tenancy",
13
- "ErpWorkflow"
14
- ]
9
+ class << self
10
+ def mount_compass_ae_engines(routes)
11
+ Rails.application.config.erp_base_erp_svcs.compass_ae_engines.each do |engine|
12
+ routes.mount engine => "/#{engine.name.split("::").first.underscore}"
13
+ end
14
+ end
15
+
16
+ def register_compass_ae_engine(engine)
17
+ Rails.application.config.erp_base_erp_svcs.compass_ae_engines << engine
18
+ load_compass_ae_extensions(engine)
19
+ load_root_compass_ae_framework_extensions()
20
+ end
21
+
22
+ #forces rails to reload model extensions and framework extensions
23
+ def load_compass_ae_extensions(engine)
24
+ load_compass_ae_model_extensions(engine)
25
+ load_compass_ae_framework_extensions(engine)
26
+ end
27
+
28
+ def load_compass_ae_model_extensions(engine)
29
+ root_models_path = "#{Rails.root}/app/models/"
30
+ engine_path = engine.root.to_s
31
+ engine_models_path = "#{engine_path}/app/models/"
32
+ engine_extensions_path = "#{engine_models_path}extensions/"
33
+
34
+ begin
35
+ #get all files from this engines app/model directory
36
+ model_extension_files = Dir.entries(engine_extensions_path).map{|directory| directory}
37
+ #remove any .svn or .data files
38
+ model_extension_files.delete_if{|name| name =~ /^\./}
39
+
40
+ #Must use eval to run each extension so rails picks up the extension
41
+ model_extension_files.each do |filename|
42
+ #check if table exists
43
+ content = File.open(engine_extensions_path + filename) { |f| f.read }
44
+ class_name = filename[0..-4]
45
+ #if tables.include?(class_name.tableize)
46
+ eval(IO.read(engine_extensions_path + filename), binding, engine_extensions_path + filename)
47
+ #end
48
+ end
49
+ end if File.directory? engine_extensions_path
50
+
51
+ begin
52
+ #get all files from this engines app/model directory
53
+ model_files = Dir.entries(engine_models_path).map{|directory| directory}
54
+ #remove any .svn or .data files
55
+ model_files.delete_if{|name| name =~ /^\./}
56
+ #exclude the extension directory
57
+ model_files.delete_if{|name| name == "extensions"}
58
+
59
+ model_files.each do |filename|
60
+
61
+ class_name = filename[0..-4]
62
+ klass = class_name.camelize
63
+
64
+ #if there is a model in {rails_root}/app/models, it's not going to load our engine models.
65
+ #load the engine model here and change it to a class_eval
66
+ if File.exists?(root_models_path + filename)
67
+ content = File.open(engine_models_path + filename) { |f| f.read }
68
+ #make sure this class extends ActiveRecord::Base
69
+ #we only want to do this for ActiveRecord models
70
+ if content.include? '< ActiveRecord::Base'
71
+ #if tables.include?(class_name.tableize)
72
+ content.gsub!("class #{klass} < ActiveRecord::Base", "#{klass}.class_eval do")
73
+ eval(content, binding)
74
+ #end
75
+ end
76
+ end
77
+ end
78
+ end if File.directory? engine_models_path
79
+
80
+ end
81
+
82
+ def load_compass_ae_framework_extensions(engine)
83
+ if File.directory? File.join(engine.root,"lib",engine.railtie_name,"extensions/compass_ae")
84
+ Dir.glob(File.join(engine.root,"lib",engine.railtie_name,"extensions/compass_ae/**/*.rb")).each do |file|
85
+ load file
86
+ end
87
+ end
88
+ end
89
+
90
+ def load_root_compass_ae_framework_extensions
91
+ Dir.glob(File.join(Rails.root,"lib/extensions/compass_ae/**/*.rb")).each do |file|
92
+ load file
93
+ end
94
+ end
95
+
96
+ end
15
97
  end
16
98
 
17
99
 
@@ -30,8 +30,13 @@ namespace :compass_ae do
30
30
  end
31
31
 
32
32
  namespace :postgres do
33
- task :purge_old do
34
- puts "Purging postgres dumps older than #{@purge_dumps_older_than}"
33
+ # age should be in days
34
+ task :purge_old, [:age] => :environment do |t,args|
35
+ age = (args.age.blank? ? @purge_dumps_older_than : args.age.to_i.days.ago)
36
+ puts "Purging postgres dumps older than #{age}"
37
+ puts green("Default is 2 weeks. You can pass in number of days if you want something different.") if args.age.blank?
38
+ puts green("Example: rake compass_ae:backup:postgres:purge_old[7]") if args.age.blank?
39
+
35
40
  chdir(PG_BACKUP_DIR)
36
41
 
37
42
  # get list of files and loop thru them
@@ -53,8 +58,8 @@ namespace :compass_ae do
53
58
  timeobject = Time.parse(timestamp)
54
59
 
55
60
  # compare time object with purge_dumps_older_than and delete if too old
56
- if timeobject < @purge_dumps_older_than
57
- puts red("Purging dump #{f}: Older than #{@purge_dumps_older_than}")
61
+ if timeobject < age
62
+ puts red("Purging dump #{f}: Older than #{age}")
58
63
  cmd = "rm -f #{f}"
59
64
  execute_command(cmd)
60
65
  end
@@ -0,0 +1,3 @@
1
+ FactoryGirl.define do
2
+ factory :money
3
+ end