Class: FileSystem::FileAdapter

Inherits:
Object
  • Object
show all
Extended by:
Adapter
Defined in:
lib/filesystem.rb

Overview

:nodoc:

Class Method Summary collapse

Methods included from Adapter

get_node, method_missing, respond_to?

Class Method Details

.chmod(perms, *filenames) ⇒ Object



110
111
112
# File 'lib/filesystem.rb', line 110

def self.chmod( perms, *filenames )
	get_node( filenames.first ).permissions = perms
end

.exist?(filename) ⇒ Boolean Also known as: exists?

Returns:

  • (Boolean)


115
116
117
118
119
120
121
122
# File 'lib/filesystem.rb', line 115

def exist?( filename )
	begin
		get_node( filename )
		true
	rescue Errno::ENOENT
		false
	end
end

.open(fd, mode_string = File::RDONLY, &action) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/filesystem.rb', line 127

def self.open( fd, mode_string = File::RDONLY, &action )
	if mode_string.class == String
		if mode_string == 'w'
			mode_string = File::WRONLY
		end
	end
	if mode_string == File::RDONLY
		node = get_node( fd )
		if node && node.permissions && node.permissions[0] == 0
			raise Errno::EACCES
		end
		result = action.call( node )
		node.rewind
		result
	else
		path = Path.new( fd ).absolute
		dir = get_node( path.parent )
		if ( mode_string & File::APPEND > 0 )
			mock_file = get_node( fd )
		else
			mock_file = MockFileSystem::MockFile.new( dir, path.node, '' )
		end
		if ( mode_string & File::APPEND == File::APPEND )
			mock_file.pos = mock_file.size
		end
		action.call( mock_file )
		mock_file.rewind
		if ( mode_string & File::APPEND == 0 )
			dir[path.node] = mock_file
		end
	end
end