ruby-hdfs-cdh4 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/ext/hdfs/hdfs.c +38 -15
  2. metadata +4 -5
@@ -155,32 +155,55 @@ VALUE HDFS_File_System_alloc(VALUE klass) {
155
155
 
156
156
  /**
157
157
  * call-seq:
158
- * hdfs.new(host='localhost', port=8020) -> hdfs
158
+ * hdfs.new(options={}) -> hdfs
159
159
  *
160
160
  * Creates a new HDFS client connection, returning a new
161
161
  * Hadoop::DFS::FileSystem object if successful. If this fails, raises a
162
162
  * ConnectError.
163
+ *
164
+ * Options:
165
+ * :local
166
+ * :host
167
+ * :port
163
168
  */
164
169
  VALUE HDFS_File_System_initialize(int argc, VALUE* argv, VALUE self) {
165
- VALUE host, port;
166
- rb_scan_args(argc, argv, "02", &host, &port);
167
- // Sets default values for host and port if not supplied by user.
168
- char* hdfs_host = (char*) HDFS_DEFAULT_HOST;
169
- int hdfs_port = HDFS_DEFAULT_PORT;
170
- if (!NIL_P(host)) {
171
- hdfs_host = RSTRING_PTR(host);
172
- }
173
- if (!NIL_P(port)) {
174
- hdfs_port = NUM2INT(port);
175
- }
170
+ VALUE options;
171
+ rb_scan_args(argc, argv, "01", &options);
172
+
176
173
  FSData* data = NULL;
177
174
  Data_Get_Struct(self, FSData, data);
178
- data->fs = hdfsConnect(hdfs_host, hdfs_port);
175
+
176
+ if (NIL_P(options)) {
177
+ options = rb_hash_new();
178
+ }
179
+
180
+ VALUE r_local = rb_hash_aref(options, rb_eval_string(":local"));
181
+ if (r_local == Qtrue) {
182
+ data->fs = hdfsConnect(NULL, 0);
183
+ } else {
184
+ VALUE r_host = rb_hash_aref(options, rb_eval_string(":host"));
185
+ VALUE r_port = rb_hash_aref(options, rb_eval_string(":port"));
186
+
187
+ // Sets default values for host and port if not supplied by user.
188
+ char* hdfs_host = (char*) HDFS_DEFAULT_HOST;
189
+ int hdfs_port = HDFS_DEFAULT_PORT;
190
+
191
+ if (RTEST(r_host)) {
192
+ hdfs_host = RSTRING_PTR(r_host);
193
+ }
194
+
195
+ if (RTEST(r_port)) {
196
+ hdfs_port = NUM2INT(r_port);
197
+ }
198
+
199
+ data->fs = hdfsConnect(hdfs_host, hdfs_port);
200
+ }
201
+
179
202
  if (data->fs == NULL) {
180
- rb_raise(e_connect_error, "Failed to connect to HDFS at: %s:%d",
181
- hdfs_host, hdfs_port);
203
+ rb_raise(e_connect_error, "Failed to connect to HDFS");
182
204
  return Qnil;
183
205
  }
206
+
184
207
  return self;
185
208
  }
186
209
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-hdfs-cdh4
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-05-15 00:00:00.000000000 Z
14
+ date: 2013-05-22 00:00:00.000000000 Z
15
15
  dependencies: []
16
16
  description: ruby hadoop libhdfs client with support for cdh4
17
17
  email:
@@ -45,12 +45,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - ! '>='
47
47
  - !ruby/object:Gem::Version
48
- version: 1.9.2
48
+ version: 1.8.10
49
49
  requirements: []
50
50
  rubyforge_project:
51
- rubygems_version: 1.8.24
51
+ rubygems_version: 1.8.23
52
52
  signing_key:
53
53
  specification_version: 3
54
54
  summary: ruby hadoop libhdfs client with support for cdh4
55
55
  test_files: []
56
- has_rdoc: