Sha256: 31228c9b9eec99c06a3ab318f43dd481fcf6c425ebbc346e23d747c1c2fb2088

Contents?: true

Size: 1.42 KB

Versions: 2

Compression:

Stored size: 1.42 KB

Contents

module YeshuaCrm
  class AssetsManager
    def self.install_assets
      return unless Gem.loaded_specs['yeshua_crm']
      source = File.join(Gem.loaded_specs['yeshua_crm'].full_gem_path, 'vendor', 'assets')
      destination = File.join(Dir.pwd, 'public', 'plugin_assets', 'yeshua_crm')
      return unless File.directory?(source)

      source_files = Dir[source + '/**/*']
      source_dirs = source_files.select { |d| File.directory?(d) }
      source_files -= source_dirs

      unless source_files.empty?
        base_target_dir = File.join(destination, File.dirname(source_files.first).gsub(source, ''))
        begin
          FileUtils.mkdir_p(base_target_dir)
        rescue Exception => e
          raise "Could not create directory #{base_target_dir}: " + e.message
        end
      end

      source_dirs.each do |dir|
        target_dir = File.join(destination, dir.gsub(source, ''))
        begin
          FileUtils.mkdir_p(target_dir)
        rescue Exception => e
          raise "Could not create directory #{target_dir}: " + e.message
        end
      end

      source_files.each do |file|
        begin
          target = File.join(destination, file.gsub(source, ''))
          unless File.exist?(target) && FileUtils.identical?(file, target)
            FileUtils.cp(file, target)
          end
        rescue Exception => e
          raise "Could not copy #{file} to #{target}: " + e.message
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
yeshua_crm-1.0.1 lib/yeshua_crm/assets_manager.rb
yeshua_crm-1.0.0 lib/yeshua_crm/assets_manager.rb