Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix one encoding issue

  • Loading branch information...
commit f0ad6dcb007c10787fcf25157aea8713638866f3 1 parent 8bedfe1
@vincentp vincentp authored
View
1  Manifest
@@ -12,6 +12,7 @@ lib/massive_record/migration.rb
lib/massive_record/row.rb
lib/massive_record/scanner.rb
lib/massive_record/table.rb
+lib/massive_record/tables_collection.rb
lib/massive_record/thrift/hbase.rb
lib/massive_record/thrift/hbase_constants.rb
lib/massive_record/thrift/hbase_types.rb
View
44 lib/massive_record/cell.rb
@@ -4,13 +4,47 @@ module MassiveRecord
class Cell
- attr_accessor :value, :created_at
+ attr_writer :value
+ attr_accessor :created_at
def initialize(opts = {})
@value = opts[:value]
@created_at = opts[:created_at]
end
+ def value
+ @value.is_a?(String) ? self.class.convert_string(@value) : @value
+ end
+
+ def self.convert_string(str)
+ str.to_s.force_encoding(Encoding::UTF_8)
+ end
+
+ def self.convert_hash(hash)
+ hash.inject({}) do |h,(k,v)|
+ if v.is_a?(String)
+ h[k] = convert_string(v)
+ elsif v.is_a?(Hash)
+ h[k] = convert_hash(v)
+ elsif v.is_a?(Array)
+ h[k] = convert_array(v)
+ end
+ h
+ end
+ end
+
+ def self.convert_array(ar)
+ ar.collect do |k|
+ if k.is_a?(String)
+ convert_string(k)
+ elsif k.is_a?(Hash)
+ convert_hash(k)
+ elsif k.is_a?(Array)
+ convert_array(k)
+ end
+ end
+ end
+
def deserialize_value
@value.is_a?(String) ? JSON.parse(@value) : @value
end
@@ -18,7 +52,9 @@ def deserialize_value
def self.serialize_value(v)
if v.is_a?(String)
v
- elsif v.is_a?(Hash) || v.is_a?(Array)
+ elsif v.is_a?(Hash)
+ v.to_json
+ elsif v.is_a?(Array)
v.to_json
end
end
@@ -27,6 +63,10 @@ def serialize_value(v)
@value = self.class.serialize_value(v)
end
+ def serialized_value
+ self.class.serialize_value(@value)
+ end
+
end
end
View
2  lib/massive_record/row.rb
@@ -94,7 +94,7 @@ def save
@columns.each do |column_name, cell|
m = Apache::Hadoop::Hbase::Thrift::Mutation.new
m.column = column_name
- m.value = cell.value
+ m.value = cell.serialized_value
mutations.push(m)
end
View
6 massive_record.gemspec
@@ -6,11 +6,11 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
s.authors = ["Companybook"]
- s.date = %q{2010-11-23}
+ s.date = %q{2010-11-25}
s.description = %q{HBase Ruby client API}
s.email = %q{geeks@companybook.no}
- s.extra_rdoc_files = ["README.md", "lib/massive_record.rb", "lib/massive_record/base.rb", "lib/massive_record/cell.rb", "lib/massive_record/column_families_collection.rb", "lib/massive_record/column_family.rb", "lib/massive_record/connection.rb", "lib/massive_record/migration.rb", "lib/massive_record/row.rb", "lib/massive_record/scanner.rb", "lib/massive_record/table.rb", "lib/massive_record/thrift/hbase.rb", "lib/massive_record/thrift/hbase_constants.rb", "lib/massive_record/thrift/hbase_types.rb"]
- s.files = ["Manifest", "README.md", "Rakefile", "autotest/discover.rb", "lib/massive_record.rb", "lib/massive_record/base.rb", "lib/massive_record/cell.rb", "lib/massive_record/column_families_collection.rb", "lib/massive_record/column_family.rb", "lib/massive_record/connection.rb", "lib/massive_record/migration.rb", "lib/massive_record/row.rb", "lib/massive_record/scanner.rb", "lib/massive_record/table.rb", "lib/massive_record/thrift/hbase.rb", "lib/massive_record/thrift/hbase_constants.rb", "lib/massive_record/thrift/hbase_types.rb", "massive_record.gemspec", "spec/README.md", "spec/config.yml.example", "spec/connection_spec.rb", "spec/spec_helper.rb", "spec/table_spec.rb"]
+ s.extra_rdoc_files = ["README.md", "lib/massive_record.rb", "lib/massive_record/base.rb", "lib/massive_record/cell.rb", "lib/massive_record/column_families_collection.rb", "lib/massive_record/column_family.rb", "lib/massive_record/connection.rb", "lib/massive_record/migration.rb", "lib/massive_record/row.rb", "lib/massive_record/scanner.rb", "lib/massive_record/table.rb", "lib/massive_record/tables_collection.rb", "lib/massive_record/thrift/hbase.rb", "lib/massive_record/thrift/hbase_constants.rb", "lib/massive_record/thrift/hbase_types.rb"]
+ s.files = ["Manifest", "README.md", "Rakefile", "autotest/discover.rb", "lib/massive_record.rb", "lib/massive_record/base.rb", "lib/massive_record/cell.rb", "lib/massive_record/column_families_collection.rb", "lib/massive_record/column_family.rb", "lib/massive_record/connection.rb", "lib/massive_record/migration.rb", "lib/massive_record/row.rb", "lib/massive_record/scanner.rb", "lib/massive_record/table.rb", "lib/massive_record/tables_collection.rb", "lib/massive_record/thrift/hbase.rb", "lib/massive_record/thrift/hbase_constants.rb", "lib/massive_record/thrift/hbase_types.rb", "massive_record.gemspec", "spec/README.md", "spec/config.yml.example", "spec/connection_spec.rb", "spec/spec_helper.rb", "spec/table_spec.rb"]
s.homepage = %q{http://github.com/CompanyBook/massive_record}
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Massive_record", "--main", "README.md"]
s.require_paths = ["lib"]
Please sign in to comment.
Something went wrong with that request. Please try again.