Class: Jetel::Loaders::Couchbase
- Defined in:
- lib/jetel/loaders/couchbase/couchbase.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Attributes inherited from Loader
Instance Method Summary collapse
-
#initialize(uri) ⇒ Couchbase
constructor
A new instance of Couchbase.
- #load(modul, source, file, opts) ⇒ Object
Constructor Details
#initialize(uri) ⇒ Couchbase
Returns a new instance of Couchbase.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/jetel/loaders/couchbase/couchbase.rb', line 14 def initialize(uri) super tmp = uri.split('://') tmp = tmp[1].split('@') parts = tmp[0].split(':') user = parts[0] password = parts[1] parts = tmp[1].split('/') host, port = parts[0].split(':') bucket = parts[1] opts = { :host => host, :port => (port && port.to_i) || 8091, # :options => '', # :tty => '', :bucket => bucket, # :username => user, # :password => password, :connection_timeout => 360e6, :timeout => 360e6 } @client = ::Couchbase.connect(opts) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
12 13 14 |
# File 'lib/jetel/loaders/couchbase/couchbase.rb', line 12 def client @client end |
Instance Method Details
#load(modul, source, file, opts) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/jetel/loaders/couchbase/couchbase.rb', line 43 def load(modul, source, file, opts) super cache = {} CSV.open(file, 'rt', :headers => true, :converters => :all) do |csv| csv.each do |row| cache[SecureRandom.uuid] = row.to_hash if cache.length === 5_000 client.add(cache) cache = {} print '.' end end if cache.length > 0 client.add(cache) cache = {} end end end |