Class: Project
- Inherits:
-
Object
- Object
- Project
- Defined in:
- lib/project.rb
Instance Attribute Summary collapse
-
#project_name ⇒ Object
readonly
Returns the value of attribute project_name.
Instance Method Summary collapse
- #add_permission(username, action) ⇒ Object
- #create ⇒ Object
- #description=(description) ⇒ Object
-
#initialize(project_name) ⇒ Project
constructor
A new instance of Project.
- #lock ⇒ Object
- #permissions ⇒ Object
- #remove_permission(username) ⇒ Object
- #visibility=(visibility) ⇒ Object
Constructor Details
#initialize(project_name) ⇒ Project
Returns a new instance of Project.
4 5 6 7 |
# File 'lib/project.rb', line 4 def initialize(project_name) @project_name = project_name @dir = find_project_dir project_name end |
Instance Attribute Details
#project_name ⇒ Object (readonly)
Returns the value of attribute project_name.
2 3 4 |
# File 'lib/project.rb', line 2 def project_name @project_name end |
Instance Method Details
#add_permission(username, action) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/project.rb', line 49 def (username,action) = .select { || [:user] != username } if username != 'admin' << { :user => username, :access => action } end File.open(, "w") do |file| .each { || file << [:user] << '=' << [:access] << "\n" } end end |
#create ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/project.rb', line 9 def create if File.exist?(@dir) error 4, "Project already exists with that name" end unless Dir.mkdir(@dir) error 1, "Unable to create directory: #{dir}" end end |
#description=(description) ⇒ Object
34 35 36 |
# File 'lib/project.rb', line 34 def description=(description) File.open(File.join(@dir, ".description"), "w") { |f| f << "#{description}\n" } end |
#lock ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/project.rb', line 19 def lock File.open(File.join(@dir, ".lock"), "w+") do |lock| lock.flock(File::LOCK_EX) begin yield ensure lock.flock(File::LOCK_UN) end end end |
#permissions ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/project.rb', line 38 def if File.exists?() File.read().split("\n").map do |line| = line.strip.split('=') { :user => .first, :access => .last } end else [] end end |
#remove_permission(username) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/project.rb', line 59 def (username) = .select { || [:user] != username } File.open(, "w") do |file| .each { || file << [:user] << '=' << [:access] << "\n" } end end |
#visibility=(visibility) ⇒ Object
30 31 32 |
# File 'lib/project.rb', line 30 def visibility=(visibility) File.open(File.join(@dir, ".visibility"), "w") { |f| f << "#{visibility}\n" } end |