Class: Ole::IOMode
Defined Under Namespace
Modules: Constants
Constant Summary collapse
- NAMES =
%w[rdonly wronly rdwr creat trunc append binary]
Constants included from Constants
Instance Attribute Summary collapse
-
#flags ⇒ Object
readonly
Returns the value of attribute flags.
Class Method Summary collapse
-
.parse_mode(mode) ⇒ Object
nabbed from rubinius, and modified.
Instance Method Summary collapse
- #append? ⇒ Boolean
- #binary? ⇒ Boolean
- #create? ⇒ Boolean
-
#initialize(flags) ⇒ IOMode
constructor
A new instance of IOMode.
-
#inspect ⇒ Object
# revisit this def apply io if truncate? io.truncate 0 elsif append? io.seek IO::SEEK_END, 0 end end.
- #readable? ⇒ Boolean
- #truncate? ⇒ Boolean
- #writeable? ⇒ Boolean
Constructor Details
#initialize(flags) ⇒ IOMode
Returns a new instance of IOMode.
199 200 201 202 203 |
# File 'lib/ole/support.rb', line 199 def initialize flags flags = self.class.parse_mode flags.to_str if flags.respond_to? :to_str raise ArgumentError, "invalid flags - #{flags.inspect}" unless Integer === flags @flags = flags end |
Instance Attribute Details
#flags ⇒ Object (readonly)
Returns the value of attribute flags.
198 199 200 |
# File 'lib/ole/support.rb', line 198 def flags @flags end |
Class Method Details
.parse_mode(mode) ⇒ Object
nabbed from rubinius, and modified
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/ole/support.rb', line 177 def self.parse_mode mode ret = 0 case mode[0, 1] when 'r'; ret |= RDONLY when 'w'; ret |= WRONLY | CREAT | TRUNC when 'a'; ret |= WRONLY | CREAT | APPEND else raise ArgumentError, "illegal access mode #{mode}" end (1...mode.length).each do |i| case mode[i, 1] when '+'; ret = (ret & ~(RDONLY | WRONLY)) | RDWR when 'b'; ret |= BINARY else raise ArgumentError, "illegal access mode #{mode}" end end ret end |
Instance Method Details
#append? ⇒ Boolean
218 219 220 |
# File 'lib/ole/support.rb', line 218 def append? (@flags & APPEND) != 0 end |
#binary? ⇒ Boolean
226 227 228 |
# File 'lib/ole/support.rb', line 226 def binary? (@flags & BINARY) != 0 end |
#create? ⇒ Boolean
222 223 224 |
# File 'lib/ole/support.rb', line 222 def create? (@flags & CREAT) != 0 end |
#inspect ⇒ Object
# revisit this def apply io if truncate? io.truncate 0 elsif append? io.seek IO::SEEK_END, 0 end end
241 242 243 244 245 |
# File 'lib/ole/support.rb', line 241 def inspect names = NAMES.map { |name| name if (flags & IOMode.const_get(name.upcase)) != 0 } names.unshift 'rdonly' if (flags & 0x3) == 0 "#<#{self.class} #{names.compact * '|'}>" end |
#readable? ⇒ Boolean
210 211 212 |
# File 'lib/ole/support.rb', line 210 def readable? (@flags & WRONLY) == 0 end |
#truncate? ⇒ Boolean
214 215 216 |
# File 'lib/ole/support.rb', line 214 def truncate? (@flags & TRUNC) != 0 end |
#writeable? ⇒ Boolean
205 206 207 208 |
# File 'lib/ole/support.rb', line 205 def writeable? #(@flags & RDONLY) == 0 (@flags & 0x3) != RDONLY end |