client: add each_file_info iterator
[ruby-mogilefs-client.git] / lib / mogilefs / client.rb
blob7a808f140402e4e237cf63ee20382746c82112b3
1 # -*- encoding: binary -*-
3 ##
4 # MogileFS::Client is the MogileFS client base class.  Concrete clients like
5 # MogileFS::MogileFS and MogileFS::Admin are implemented atop this one to do
6 # real work.
7 class MogileFS::Client
9   ##
10   # The backend connection for this client
12   attr_reader :backend
14   # :stopdoc:
15   attr_accessor :hosts if defined? $TESTING
16   # :startdoc
18   ##
19   # Creates a new Client.  See MogileFS::Backend#initialize for how to specify
20   # hosts.  If :readonly is set to true, the client will not modify anything
21   # on the server.
22   #
23   #   MogileFS::Client.new :hosts => ['kaa:6001', 'ziz:6001'], :readonly => true
25   def initialize(args)
26     @hosts = args[:hosts]
27     @readonly = args[:readonly] ? true : false
28     @timeout = args[:timeout]
29     @fail_timeout = args[:fail_timeout]
31     reload
32   end
34   ##
35   # Creates a new MogileFS::Backend.
37   def reload
38     @backend = MogileFS::Backend.new(:hosts => @hosts,
39                                      :timeout => @timeout,
40                                      :fail_timeout => @fail_timeout)
41   end
43   ##
44   # The last error reported by the backend.
46   def err
47     @backend.lasterr
48   end
50   ##
51   # The last error message reported by the backend.
53   def errstr
54     @backend.lasterrstr
55   end
57   ##
58   # Is this a read-only client?
60   def readonly?
61     @readonly
62   end
64 end