Skip to content

Commit

Permalink
closing file handle
Browse files Browse the repository at this point in the history
  • Loading branch information
Dean Brundage committed Nov 14, 2016
1 parent 26b7127 commit b73ef94
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/thermostat/config_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ def locate_config_file(key)


def read
raise NoConfigError.new("Please suppply :filename or :stream to ConfigLoader") unless find_stream
hash = @stream_loader.load_stream(find_stream)[0]
raise NoConfigError.new("Please suppply :filename or :stream to ConfigLoader") unless open_stream
hash = @stream_loader.load_stream(@handle)[0]
@handle.close
Config.new hash
end

Expand All @@ -33,9 +34,14 @@ def config_dir
end


def find_stream
return @stream if @stream
File.open @filename if @filename
def open_stream
!! @handle and return @handle
if @stream
@handle = @stream
else
@handle = File.open @filename if @filename
end
@handle
end

end
Expand Down

0 comments on commit b73ef94

Please sign in to comment.