Sha256: e053e47e5201463c8e987b21a1cad5d6affe0fb5668c831dd9a697c808c196c8

Contents?: true

Size: 1.96 KB

Versions: 19

Compression:

Stored size: 1.96 KB

Contents

module Boxes
  # For creating and managing the environment which boxes uses.
  class Environment
    def initialize
      FileUtils.mkdir_p(Boxes.config.working_dir)

      copy_templates
      copy_scripts
    end

    def available_templates
      t = Dir.glob("#{Boxes.config.working_dir}/templates/*/**")
      a = t.collect { |c| c.include?('preseed.cfg') ? next : c }.compact

      a.collect do |c|
        c = c.gsub(Boxes.config.working_dir.to_s + '/templates/', '')
        c.gsub('.erb', '')
      end
    end

    def hidden_templates
      t = Dir.glob("#{Boxes.config.working_dir}/templates/*/**")
      a = t.collect { |c| c.include?('preseed.cfg') ? c : next }.compact

      a.collect do |c|
        c.gsub(Boxes.config.working_dir.to_s + '/templates/', '')
      end
    end

    def available_scripts
      t = Dir.glob("#{Boxes.config.working_dir}/scripts/*")
      a = t.collect { |c| c.include?('purge.sh') ? next : c }.compact

      a.collect do |c|
        c.gsub(Boxes.config.working_dir.to_s + '/scripts/', '')
      end
    end

    def hidden_scripts
      t = Dir.glob("#{Boxes.config.working_dir}/scripts/*")
      a = t.collect { |c| c.include?('purge.sh') ? c : next }.compact

      a.collect do |c|
        c.gsub(Boxes.config.working_dir.to_s + '/scripts/', '')
      end
    end

    private

    def copy_templates
      templates_dir = Boxes.config.working_dir + 'templates'

      FileUtils.mkdir_p(templates_dir)

      Boxes.config.template_paths.each do |template_path|
        Dir.glob("#{template_path}/*").each do |src_template|
          FileUtils.cp_r(src_template, templates_dir)
        end
      end
    end

    def copy_scripts
      scripts_dir = Boxes.config.working_dir + 'scripts'

      FileUtils.mkdir_p(Boxes.config.working_dir + 'scripts')

      Boxes.config.script_paths.each do |script_path|
        Dir.glob("#{script_path}/*").each do |src_script|
          FileUtils.cp_r(src_script, scripts_dir)
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
boxes-3.7.0 lib/boxes/environment.rb
boxes-3.6.1 lib/boxes/environment.rb
boxes-3.6.0 lib/boxes/environment.rb
boxes-3.5.0 lib/boxes/environment.rb
boxes-3.4.0 lib/boxes/environment.rb
boxes-3.3.1 lib/boxes/environment.rb
boxes-3.3.0 lib/boxes/environment.rb
boxes-3.2.0 lib/boxes/environment.rb
boxes-3.1.0 lib/boxes/environment.rb
boxes-3.0.0 lib/boxes/environment.rb
boxes-2.5.0 lib/boxes/environment.rb
boxes-2.4.0 lib/boxes/environment.rb
boxes-2.3.0 lib/boxes/environment.rb
boxes-2.2.0 lib/boxes/environment.rb
boxes-2.1.1 lib/boxes/environment.rb
boxes-2.1.0 lib/boxes/environment.rb
boxes-2.0.2 lib/boxes/environment.rb
boxes-2.0.1 lib/boxes/environment.rb
boxes-2.0.0 lib/boxes/environment.rb