Class: Greenhouse::Resources::ProjectsFile
- Inherits:
-
Object
- Object
- Greenhouse::Resources::ProjectsFile
- Includes:
- FileResource
- Defined in:
- lib/greenhouse/resources/projects_file.rb
Instance Method Summary collapse
-
#initialize(path) ⇒ ProjectsFile
constructor
A new instance of ProjectsFile.
- #projects(refresh = false) ⇒ Object
- #reload ⇒ Object
- #unlink ⇒ Object
- #write ⇒ Object (also: #save)
Methods included from FileResource
Constructor Details
#initialize(path) ⇒ ProjectsFile
Returns a new instance of ProjectsFile.
39 40 41 |
# File 'lib/greenhouse/resources/projects_file.rb', line 39 def initialize(path) super end |
Instance Method Details
#projects(refresh = false) ⇒ Object
8 9 10 11 |
# File 'lib/greenhouse/resources/projects_file.rb', line 8 def projects(refresh=false) return @projects unless refresh || @projects.nil? || @projects.empty? reload end |
#reload ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/greenhouse/resources/projects_file.rb', line 26 def reload @projects = {} return @projects unless exists? @projects = YAML::load_file(path) @projects ||= {} @projects end |
#unlink ⇒ Object
34 35 36 37 |
# File 'lib/greenhouse/resources/projects_file.rb', line 34 def unlink super reload end |
#write ⇒ Object Also known as: save
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/greenhouse/resources/projects_file.rb', line 13 def write open('w') do |pfile| #pfile.write @projects.to_yaml.gsub("!ruby/symbol ", ":").sub("---","").split("\n").map(&:rstrip).join("\n").strip @projects.each do |name,project| pfile.write "#{name}:\n" project.each do |key,val| pfile.write " #{key}: #{val.to_s}\n" end end end end |