Class: AimsProject::Project
- Inherits:
-
Object
- Object
- AimsProject::Project
- Defined in:
- lib/aims_project/project.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
The name of this project.
Class Method Summary collapse
-
.create(name) ⇒ Object
Create a new Project with the given name This will also create the directory structure for the project.
-
.load(filename) ⇒ Object
Load a Project from the serialized yaml file.
Instance Method Summary collapse
-
#calculations ⇒ Object
Retreive the calcluations managed by this project.
-
#full_path ⇒ Object
The full path to this project locally.
-
#geometries ⇒ Object
Retreive the geometries managed by this project.
-
#get_binding ⇒ Object
Return the binding for this project.
-
#initialize(name) ⇒ Project
constructor
Initialize a new project object with the given name.
-
#relative_path ⇒ Object
The path of this project relative to project_root_dir.
-
#save(dir = ".") ⇒ Object
Serialize this project to a yaml file named after this project in the given directory.
-
#serialized_filename ⇒ Object
The filename of the serialized yaml file representing this project.
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
#name ⇒ Object
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
#calculations ⇒ Object
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_path ⇒ Object
The full path to this project locally
72 73 74 |
# File 'lib/aims_project/project.rb', line 72 def full_path File.dirname(File.(serialized_filename)) end |
#geometries ⇒ Object
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_binding ⇒ Object
Return the binding for this project
57 58 59 |
# File 'lib/aims_project/project.rb', line 57 def get_binding binding end |
#relative_path ⇒ Object
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_filename ⇒ Object
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 |