Class: Proj::FileApiImpl
Overview
Proj allows its file api to be replaced by a custom implementation. This can be done by calling Context#set_file_api with a user defined Class that includes the FileApiCallbacks module and implements its required methods.
The FileApiImpl class is a simple example file api implementation.
Instance Method Summary
collapse
#close_callback, #exists_callback, #install_callbacks, #mkdir_callback, #open_callback, #read_callback, #rename_callback, #seek_callback, #tell_callback, #unlink_callback, #write_callback
Constructor Details
#initialize(context) ⇒ FileApiImpl
Returns a new instance of FileApiImpl.
107
108
109
|
# File 'lib/proj/file_api.rb', line 107
def initialize(context)
install_callbacks(context)
end
|
Instance Method Details
#close ⇒ Object
146
147
148
|
# File 'lib/proj/file_api.rb', line 146
def close
@file.close
end
|
#exists(path) ⇒ Object
150
151
152
|
# File 'lib/proj/file_api.rb', line 150
def exists(path)
File.exist?(path)
end
|
#mkdir(path) ⇒ Object
154
155
156
|
# File 'lib/proj/file_api.rb', line 154
def mkdir(path)
Dir.mkdir(path)
end
|
#open(path, access_mode) ⇒ Object
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/proj/file_api.rb', line 111
def open(path, access_mode)
case access_mode
when :PROJ_OPEN_ACCESS_READ_ONLY
if File.exist?(path)
@file = File.open(path, :mode => 'rb')
else
nil end
when :PROJ_OPEN_ACCESS_READ_UPDATE
if File.exist?(path)
@file = File.open(path, :mode => 'r+b')
else
nil end
when :PROJ_OPEN_ACCESS_CREATE
@file = File.open(path, :mode => 'wb')
end
end
|
#read(size_bytes) ⇒ Object
130
131
132
|
# File 'lib/proj/file_api.rb', line 130
def read(size_bytes)
@file.read(size_bytes)
end
|
#rename(original_path, new_path) ⇒ Object
162
163
164
|
# File 'lib/proj/file_api.rb', line 162
def rename(original_path, new_path)
File.rename(original_path, new_path)
end
|
#seek(offset, whence) ⇒ Object
138
139
140
|
# File 'lib/proj/file_api.rb', line 138
def seek(offset, whence)
@file.seek(offset, whence)
end
|
#tell ⇒ Object
142
143
144
|
# File 'lib/proj/file_api.rb', line 142
def tell
@file.tell
end
|
#unlink(path) ⇒ Object
158
159
160
|
# File 'lib/proj/file_api.rb', line 158
def unlink(path)
File.unlink(path) if File.exist?(path)
end
|
#write(data) ⇒ Object
134
135
136
|
# File 'lib/proj/file_api.rb', line 134
def write(data)
@file.write(data)
end
|