cassandra-model 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cassandra-model}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tien Le"]
12
- s.date = %q{2010-11-28}
12
+ s.date = %q{2010-12-22}
13
13
  s.description = %q{Cassandra-model allows you to map ColumnFamily/SuperColumnFamily in Cassandra to Ruby objects. It was designed to be fast and simple.}
14
14
  s.email = %q{tienlx /at/ gmail /dot/ com}
15
15
  s.extra_rdoc_files = [
@@ -21,7 +21,10 @@ module CassandraModel
21
21
  end
22
22
 
23
23
  def key(name)
24
- class_eval "def #{name}=(value); @key = value.to_s; end"
24
+ class_eval <<-EVAL, __FILE__, __LINE__ + 1
25
+ def #{name}=(value); @key = value.to_s; end
26
+ def #{name}; @key; end
27
+ EVAL
25
28
  end
26
29
 
27
30
  def column(name, type = :string)
@@ -56,8 +59,8 @@ module CassandraModel
56
59
  end
57
60
  end
58
61
 
59
- attr_accessor :new_record
60
- attr_reader :key, :attributes, :errors
62
+ attr_accessor :key, :new_record
63
+ attr_reader :attributes, :errors
61
64
 
62
65
  def initialize(attrs = {}, convert = true)
63
66
  @new_record = true
@@ -27,7 +27,7 @@ module CassandraModel
27
27
  end
28
28
 
29
29
  def update_attributes(attrs)
30
- attributes = attrs
30
+ self.attributes = attrs
31
31
  save
32
32
  end
33
33
 
@@ -40,6 +40,7 @@ module CassandraModel
40
40
  def write(attrs)
41
41
  self.class.write(key, attrs)
42
42
  @new_record = false
43
+ self
43
44
  end
44
45
  end
45
46
 
@@ -58,8 +59,11 @@ module CassandraModel
58
59
  attrs = connection.get(column_family, key, options)
59
60
  return nil if attrs.empty?
60
61
  new(attrs, false).tap do |object|
62
+ object.key = key
61
63
  object.new_record = false
62
64
  end
65
+ rescue
66
+ nil
63
67
  end
64
68
 
65
69
  alias :find :get
@@ -71,8 +75,11 @@ module CassandraModel
71
75
  end
72
76
 
73
77
  def exists?(key)
78
+ return false if key.nil? || key == ''
74
79
  #connection.exists?(column_family, key)
75
80
  !connection.get(column_family, key).empty?
81
+ rescue
82
+ false
76
83
  end
77
84
 
78
85
  def all(keyrange = ''..'', options = {})
@@ -64,7 +64,10 @@ class CassandraModelTest < Test::Unit::TestCase
64
64
  should "destroy a record" do
65
65
  @user.destroy
66
66
  assert User.get("tl").nil?
67
+ assert User.get(nil).nil?
68
+
67
69
  assert_raise(CassandraModel::RecordNotFound) { User["tl"] }
70
+ assert_raise(CassandraModel::RecordNotFound) { User[nil] }
68
71
  end
69
72
 
70
73
  should "return true if record exists and otherwise" do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Tien Le
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-11-28 00:00:00 +07:00
17
+ date: 2010-12-22 00:00:00 +07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency