forward-rbase 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/rbase/client.rb +16 -6
  2. metadata +3 -7
data/lib/rbase/client.rb CHANGED
@@ -1,8 +1,11 @@
1
1
  module Rbase
2
2
  class Client
3
- attr_reader :client
3
+ def self.connect(server, port=9090, &blk)
4
+ client = Client.new(server, port)
5
+ yield client if block_given?
6
+ end
4
7
 
5
- def initialize(server,port=9090)
8
+ def initialize(server, port=9090)
6
9
  socket = Thrift::Socket.new(server, port.to_s)
7
10
  transport = Thrift::BufferedTransport.new(socket)
8
11
  transport.open
@@ -13,7 +16,7 @@ module Rbase
13
16
  end
14
17
 
15
18
  def table_names
16
- client.getTableNames
19
+ @client.getTableNames
17
20
  end
18
21
 
19
22
  def table_exists?(table_name)
@@ -24,17 +27,24 @@ module Rbase
24
27
  column_families = column_family_names.map do |family_name|
25
28
  Apache::Hadoop::Hbase::Thrift::ColumnDescriptor.new(:name => family_name)
26
29
  end
27
- client.createTable(table_name, column_families)
30
+ @client.createTable(table_name, column_families)
31
+ end
32
+
33
+ def create_table!(table_name, *column_family_names)
34
+ if table_exists?(table_name)
35
+ delete_table(table_name)
36
+ end
37
+ create_table(table_name, *column_family_names)
28
38
  end
29
39
 
30
40
  def delete_table(table_name)
31
41
  @client.disableTable(table_name)
32
42
  @client.deleteTable(table_name)
43
+ @tables.delete(table_name)
33
44
  end
34
45
 
35
46
  def [](table_name)
36
- table_name = table_name.to_sym
37
- @tables[table_name] ||= Rbase::Table.new(client, table_name)
47
+ @tables[table_name] ||= Rbase::Table.new(@client, table_name) if table_exists?(table_name)
38
48
  @tables[table_name]
39
49
  end
40
50
  end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forward-rbase
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 2
9
- - 1
10
- version: 0.2.1
8
+ - 2
9
+ version: 0.2.2
11
10
  platform: ruby
12
11
  authors:
13
12
  - Forward Internet Group
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2011-01-12 00:00:00 +00:00
17
+ date: 2011-02-17 00:00:00 +00:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- hash: 15
30
28
  segments:
31
29
  - 0
32
30
  - 4
@@ -63,7 +61,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
63
61
  requirements:
64
62
  - - ">="
65
63
  - !ruby/object:Gem::Version
66
- hash: 3
67
64
  segments:
68
65
  - 0
69
66
  version: "0"
@@ -72,7 +69,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
69
  requirements:
73
70
  - - ">="
74
71
  - !ruby/object:Gem::Version
75
- hash: 3
76
72
  segments:
77
73
  - 0
78
74
  version: "0"