Class: GitSu::UserFile
- Inherits:
-
Object
- Object
- GitSu::UserFile
- Defined in:
- lib/gitsu/user_file.rb
Instance Method Summary collapse
-
#initialize(file_name) ⇒ UserFile
constructor
A new instance of UserFile.
- #read ⇒ Object
- #write(user) ⇒ Object
Constructor Details
#initialize(file_name) ⇒ UserFile
Returns a new instance of UserFile.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/gitsu/user_file.rb', line 22 def initialize(file_name) @file = file_name unless File.exist? file_name FileUtils.touch file_name end if File.size(file_name) == 0 File.open(file_name, "w") do |file| file << "\n" end end end |
Instance Method Details
#read ⇒ Object
40 41 42 43 44 45 |
# File 'lib/gitsu/user_file.rb', line 40 def read user_map = YAML.load_file(@file) or return [] user_map.map do |email, name| User.new(name, email) end end |
#write(user) ⇒ Object
34 35 36 37 38 |
# File 'lib/gitsu/user_file.rb', line 34 def write(user) File.open(@file, "a") do |file| file.write "\n#{user.email} : #{user.name}" end end |