Class: Megam::WorkArea

Inherits:
Object
  • Object
show all
Defined in:
lib/megam/workarea.rb

Overview

a class which manages the work area, ie find the files in workarea, packaging script in it.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ WorkArea

Returns a new instance of WorkArea.



26
27
28
29
30
31
# File 'lib/megam/workarea.rb', line 26

def initialize (options)
  @del_if_exists = false
  @directory      = options[:directory] if options[:directory]
  @del_if_exists  = options[:del_if_exists] if options[:del_if_exists]
  @msg            = options[:message] if options[:message]
end

Instance Attribute Details

#del_if_existsObject

Returns the value of attribute del_if_exists.



22
23
24
# File 'lib/megam/workarea.rb', line 22

def del_if_exists
  @del_if_exists
end

#dir_glob_filesObject

Returns the value of attribute dir_glob_files.



25
26
27
# File 'lib/megam/workarea.rb', line 25

def dir_glob_files
  @dir_glob_files
end

#directoryObject

Returns the value of attribute directory.



23
24
25
# File 'lib/megam/workarea.rb', line 23

def directory
  @directory
end

#msgObject

Returns the value of attribute msg.



24
25
26
# File 'lib/megam/workarea.rb', line 24

def msg
  @msg
end

Class Method Details

.workarea_install_directoryObject



54
55
56
# File 'lib/megam/workarea.rb', line 54

def self.workarea_install_directory
  File.dirname(Megam::Config[:install_file])
end

Instance Method Details

#directory_avail?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/megam/workarea.rb', line 33

def directory_avail?
  directory
end

#find_files_via_dirglob(i_dir) ⇒ Object

Lists all the files under the dir



45
46
47
48
49
50
51
52
# File 'lib/megam/workarea.rb', line 45

def find_files_via_dirglob(i_dir)
  dir_files = {}
  Megam::Birr.text.info(Megam::Birr.text.color("GLOB :", :green, :bold) + "#{i_dir}")
  if Dir.exists?(i_dir)
    dir_files[i_dir] = Dir.glob("#{i_dir}/**/*")
  end
  dir_files
end

#find_package_script(dir, package_words) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/megam/workarea.rb', line 77

def find_package_script(dir,package_words)
  adir = dir.dup
  adir = adir.gsub(".", File.path("/"))
  package_script_files = {}
  matching_dir = nil

  while ( package_script_files.empty? ) && ( !package_words.empty? )
    if (!matching_dir) && (!package_words.empty?)
      package_script ||= package_words.pop
      matching_dir ||= Megam::Install.workarea_loader[File.join(adir.strip)]
      package_script_files[matching_dir] = Dir.glob("#{matching_dir}/**"+ package_script)
    end
  end
  package_script_files
end

#list_directory(i_dir) ⇒ Object

Lists all the files under the workarea_installer/<directory> using a helper



39
40
41
42
# File 'lib/megam/workarea.rb', line 39

def list_directory(i_dir)
  @dir_glob_files = {}
  @dir_glob_files ||= (find_files_via_dirglob(i_dir).values).flatten
end

#to_sObject



93
94
95
# File 'lib/megam/workarea.rb', line 93

def to_s
  "workarea[:directory =>"+directory+"]"
end

#workarea_install(i_dir) ⇒ Object



58
59
60
61
62
# File 'lib/megam/workarea.rb', line 58

def workarea_install(i_dir)
  unless workarea_install_not_found!(i_dir)
    File.join(workarea_install_directory,i_dir)
  end
end

#workarea_install_not_found!(i_dir) ⇒ Object

:nodoc: Error out and print usage. probably becuase the arguments given by the user could not be resolved to a subcommand.



67
68
69
70
71
72
73
74
75
# File 'lib/megam/workarea.rb', line 67

def workarea_install_not_found!(i_dir)
  missing_install_dir = nil

  if missing_install_dir = !(WORKAREA_PRECONFIG_DIRS.find {|wai| wai == i_dir} )
    Megam::Birr.text.fatal("Cannot find workarea install dir  for: '#{i_dir}'")
    exit 10
  end
  missing_install_dir
end