Class: AimsProject::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/aims_project/project.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Project

Initialize a new project object with the given name. This does not create the project directory structure, use create for that.



52
53
54
# File 'lib/aims_project/project.rb', line 52

def initialize(name)
  self.name = name
end

Instance Attribute Details

#nameObject

The name of this project



11
12
13
# File 'lib/aims_project/project.rb', line 11

def name
  @name
end

Class Method Details

.create(name) ⇒ Object

Create a new Project with the given name This will also create the directory structure for the project. Returns true if successful, false otherwise



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/aims_project/project.rb', line 25

def Project.create(name)
  
    return nil unless name
    
      p = Project.new(name)
      
      # Create the project directory
      FileUtils.mkdir(p.relative_path)
      p.save(p.relative_path)
      # 
      # # Create the config directory
      # FileUtils.mkdir(File.join(p.relative_path, "config"))
      # 
      # # Create the geometry directory
      # FileUtils.mkdir(File.join(p.relative_path, AimsProject::GEOMETRY_DIR))
      # 
      # # Create the control directory
      # FileUtils.mkdir(File.join(p.relative_path, AimsProject::CONTROL_DIR))
      # 
      # # Create the calculations directory
      # FileUtils.mkdir(File.join(p.relative_path, AimsProject::CALCULATION_DIR))

      return p
end

.load(filename) ⇒ Object

Load a Project from the serialized yaml file



14
15
16
17
18
19
20
# File 'lib/aims_project/project.rb', line 14

def Project.load(filename)
  yamlfile = [filename, filename+".yaml"].find{|f| File.exists?(f)}
  
  File.open(yamlfile, 'r') do |f|
    YAML.load(f)
  end
end

Instance Method Details

#calculationsObject

Retreive the calcluations managed by this project. This array is loaded directly from serialized yaml files in each calculation directory



87
88
89
90
91
92
93
94
# File 'lib/aims_project/project.rb', line 87

def calculations
  calc_status_files = Dir.glob(File.join(AimsProject::CALCULATION_DIR, "*", AimsProject::CALC_STATUS_FILENAME))
  # pick up sub-calculations
  calc_status_files += Dir.glob(File.join(AimsProject::CALCULATION_DIR, "*", "*", AimsProject::CALC_STATUS_FILENAME))
  calc_status_files.collect{|f|
    Calculation.load(File.dirname(f))
  }
end

#full_pathObject

The full path to this project locally



72
73
74
# File 'lib/aims_project/project.rb', line 72

def full_path
  File.dirname(File.expand_path(serialized_filename))
end

#geometriesObject

Retreive the geometries managed by this project.



97
98
99
# File 'lib/aims_project/project.rb', line 97

def geometries
  Dir.glob(File.join(AimsProject::GEOMETRY_DIR, "*"))
end

#get_bindingObject

Return the binding for this project



57
58
59
# File 'lib/aims_project/project.rb', line 57

def get_binding
  binding
end

#relative_pathObject

The path of this project relative to project_root_dir



62
63
64
# File 'lib/aims_project/project.rb', line 62

def relative_path
  name
end

#save(dir = ".") ⇒ Object

Serialize this project to a yaml file named after this project in the given directory



78
79
80
81
82
# File 'lib/aims_project/project.rb', line 78

def save(dir = ".")
  File.open(File.join(dir, "#{name}.yaml"), 'w') do |f|
    f.print YAML.dump(self)
  end
end

#serialized_filenameObject

The filename of the serialized yaml file representing this project



67
68
69
# File 'lib/aims_project/project.rb', line 67

def serialized_filename
  "#{self.name}.yaml"
end