Skip to content

Commit

Permalink
Merge branch 'master' into codedb-ffi-io
Browse files Browse the repository at this point in the history
Had to make a few modifications to the visibility of some
methods in order for specs to pass.
  • Loading branch information
chuckremes committed Mar 30, 2016
2 parents 17c6b5f + 532cb80 commit 531eaa1
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions core/io.rb
Expand Up @@ -1728,7 +1728,7 @@ def initialize(fd, mode=undefined, options=undefined)
(@external || Encoding.default_external) == Encoding::ASCII_8BIT
@internal = nil
end
elsif !@fd.read_only?
elsif !mode_read_only?
if Encoding.default_external != Encoding.default_internal
@internal = Encoding.default_internal
end
Expand Down Expand Up @@ -1906,7 +1906,7 @@ def <<(obj)
def close_read
return if invalid_descriptor?

if @fd.write_only? || @fd.read_write?
if mode_write_only? || mode_read_write?
raise IOError, 'closing non-duplex IO for reading'
end

Expand All @@ -1929,7 +1929,7 @@ def close_read
def close_write
return if invalid_descriptor?

if @fd.read_only? || @fd.read_write?
if mode_read_only? || mode_read_write?
raise IOError, 'closing non-duplex IO for writing'
end

Expand Down Expand Up @@ -2340,9 +2340,19 @@ def eof?

alias_method :eof, :eof?

def ensure_open_and_readable
ensure_open
raise IOError, "not opened for reading" if mode_write_only?
end

def ensure_open_and_writable
ensure_open
raise IOError, "not opened for writing" if mode_read_only?
end

def external_encoding
return @external if @external
return Encoding.default_external if @fd.read_only?
return Encoding.default_external if mode_read_only?
end

##
Expand Down Expand Up @@ -2545,6 +2555,21 @@ def lineno=(line_number)
@lineno = Integer(line_number)
end

def mode_read_only?
@fd.read_only?
end
private :mode_read_only?

def mode_read_write?
@fd.read_write?
end
private :mode_read_write?

def mode_write_only?
@fd.write_only?
end
private :mode_write_only?

##
# FIXME
# Returns the process ID of a child process
Expand Down Expand Up @@ -2999,7 +3024,7 @@ def reopen(other, mode=undefined)
mode = @fd.mode
# If this IO was already opened for writing, we should
# create the target file if it doesn't already exist.
if (mode & RDWR == RDWR) || (mode & WRONLY == WRONLY)
if mode_read_write? || mode_write_only?
mode |= CREAT
end
else
Expand Down Expand Up @@ -3075,7 +3100,7 @@ def set_encoding(external, internal=nil, options=undefined)
when String
@external = nil
when nil
if @fd.read_only? || @external
if mode_read_only? || @external
@external = nil
else
@external = Encoding.default_external
Expand Down

0 comments on commit 531eaa1

Please sign in to comment.