class ErpDevSvcs::Commands::Helper

Constants

COMMERCIAL_ROOT
COMPASS_ROOT
KEY_ENGINES

Public Class Methods

compass_gem_names() click to toggle source
# File lib/erp_dev_svcs/commands/helper.rb, line 117
def self.compass_gem_names
   [:erp_base_erp_svcs,
               :erp_dev_svcs,
               :erp_tech_svcs,
               :erp_app,
               :erp_agreements,
               :erp_products,
               :erp_orders,
               :erp_txns_and_accts,
               :erp_commerce,
               :erp_inventory,
               :erp_communication_events,
               :erp_rules,
               :erp_work_effort,
               :erp_invoicing,
               :erp_financial_accounting,
               :compass_ae_console,
               :knitkit,
               :rails_db_admin,
               :compass_ae_starter_kit,
               :erp_search]
end
exec_in_dirs() { || ... } click to toggle source

This will cd into the COMPASS_ROOT and COMMERCIAL_DIR and execute the passed block; in COMMERCIAL_DIR, it will cd to the subdir and execute each command. The assumption here is that you're trying to perform a command on individual repos

# File lib/erp_dev_svcs/commands/helper.rb, line 92
def self.exec_in_dirs
  begin
    find_rails_root!
    Dir.chdir(COMPASS_ROOT)
    puts "Operating on compass root dir..."
    yield

    find_rails_root!
    Dir.chdir(COMMERCIAL_ROOT)
    root_dir = Dir.pwd
    puts "Now operating on commercial repos..."
    Dir.foreach(".") do |dir_item|
      next if dir_item == '..' || dir_item == '.'
      if File.directory?(dir_item)
        Dir.chdir(dir_item)
        puts "\nChanging to #{dir_item}...\n"
        yield
        Dir.chdir(root_dir)
      end
    end
  rescue Errno::ENOENT => e
    puts "#{e.message} does not exist; skipping..."
  end
end
exec_in_engines(only_in_these_gems = nil) { |engine_name| ... } click to toggle source

Will set the cwd to each engine under compass/lib and execute the block passed in. Will return cwd to lib/compass.

This method also accepts an alternate parameter of an array with engine names in it. If present,the block will only be executed on the engines listed in that array

# File lib/erp_dev_svcs/commands/helper.rb, line 51
def self.exec_in_engines(only_in_these_gems = nil)

  code_dirs = [COMPASS_ROOT]
  code_dirs.each do |code_dir|
    begin
      find_rails_root!
      Dir.chdir(code_dir)
      root_dir = Dir.pwd

      #we're using gemspecs to know that we have
      #a mountable engine located there
      gemspecs = Dir.glob("**/*.gemspec")
      gemspecs = sort_gems(gemspecs) if code_dir == COMPASS_ROOT
      gemspecs.each do |gem|
        #XXX:we're skipping compass_ae since all it does is
        #help install compass
        next if gem == "compass_ae.gemspec"
        gemspec = /(.*)\/(.*.gemspec)/.match(gem)
        #set engine name to the submatch via "[1]"
        engine_name = /(.*).gemspec/.match(gemspec[2])[1]


        if only_in_these_gems.nil? || only_in_these_gems.include?(engine_name)
          Dir.chdir(gemspec[1])
          #pass in the engine name
          yield engine_name
          Dir.chdir(root_dir)
        end
      end
    rescue Errno::ENOENT
      puts "#{code_dir} does not exist; skipping..."
    end
  end

end
find_rails_root!() click to toggle source
# File lib/erp_dev_svcs/commands/helper.rb, line 19
def self.find_rails_root!
  if in_rails_application?
    return
  else
    Dir.chdir("..")
    find_rails_root!
  end
end
in_rails_application?() click to toggle source
# File lib/erp_dev_svcs/commands/helper.rb, line 28
def self.in_rails_application?
  File.exists?(File.join('config', 'boot.rb'))
end
sort_gems(gemspecs) click to toggle source
# File lib/erp_dev_svcs/commands/helper.rb, line 32
def self.sort_gems gemspecs
  KEY_ENGINES.each do |key, val|
    gemspecs.delete(val)
  end
  KEY_ENGINES.each do |key, val|
    gemspecs.insert(key, val)
  end
  gemspecs
end