fracassandra 0.3.0 → 0.3.2

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.
data/README.rdoc CHANGED
@@ -2,9 +2,6 @@
2
2
 
3
3
  Fracassandra is an object mapper for the Cassandra database.
4
4
 
5
- It's currently not ready for prime time, as super column family support is not available yet. It also
6
- does not support adjusting the row/key cache sizes, how columns are sorted, etc.
7
-
8
5
  == Example usage
9
6
 
10
7
  It can be used in familiar ways, for instance:
@@ -18,6 +15,15 @@ It can be used in familiar ways, for instance:
18
15
  attribute :email
19
16
  end
20
17
 
18
+ or with super columns:
19
+
20
+ class Group < Fracassandra::Model
21
+ column_family :Groups
22
+
23
+ attribute :id, :key => true
24
+ list :name, :columns => [:index, :username]
25
+ end
26
+
21
27
  This will create a class suitable for use with the Cassandra mapping, using the username as the key to the
22
28
  column family, storing a bunch of columns (password, salt and email respectively). Each attribute will respond
23
29
  to a getter with the same name, and a setter with the same name. One exception is the :key attribute, which
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.2
data/fracassandra.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{fracassandra}
8
- s.version = "0.3.0"
8
+ s.version = "0.3.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jeremy Tregunna"]
12
- s.date = %q{2011-03-16}
12
+ s.date = %q{2011-03-23}
13
13
  s.description = %q{Hook your cassandra column families into ruby classes, mapping your rows to objects.}
14
14
  s.email = %q{jeremy.tregunna@me.com}
15
15
  s.extra_rdoc_files = [
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
26
26
  "fracassandra.gemspec",
27
27
  "lib/fracassandra.rb",
28
28
  "lib/fracassandra/model.rb",
29
+ "lib/fracassandra/sunspot.rb",
29
30
  "spec/model_spec.rb",
30
31
  "spec/spec_helper.rb"
31
32
  ]
@@ -6,6 +6,7 @@ module Fracassandra
6
6
  # want to look for the SuperModel class.
7
7
  class Model
8
8
  attr_reader :key
9
+ attr_accessor :update_operation
9
10
 
10
11
  class << self
11
12
  def column_family(column_family_name=nil)
@@ -23,8 +24,16 @@ module Fracassandra
23
24
  @attributes ||= {}
24
25
  @attributes[name.to_s] = options
25
26
  end
26
-
27
- attr_reader :attributes
27
+
28
+ def on_create(s)
29
+ @create_hook = s
30
+ end
31
+
32
+ def on_update(s)
33
+ @update_hook = s
34
+ end
35
+
36
+ attr_reader :attributes, :create_hook, :update_hook
28
37
  end
29
38
 
30
39
  def initialize(defaults={})
@@ -32,6 +41,8 @@ module Fracassandra
32
41
  raise "Invalid key error. No key was given in either the model or as an argument to new" if r.nil?
33
42
  @key = r[0]
34
43
 
44
+ @update_operation = false
45
+
35
46
  defaults.each_pair do |attribute, value|
36
47
  self.send(:"#{attribute}=", value)
37
48
  end
@@ -60,6 +71,7 @@ module Fracassandra
60
71
  end
61
72
  r.send(:"#{sub_key}=", h)
62
73
  end
74
+ r.update_operation = true
63
75
  r
64
76
  end
65
77
 
@@ -71,6 +83,14 @@ module Fracassandra
71
83
  self.class.column_family
72
84
  end
73
85
 
86
+ def create_hook
87
+ self.class.create_hook
88
+ end
89
+
90
+ def update_hook
91
+ self.class.update_hook
92
+ end
93
+
74
94
  def self.timestamps!
75
95
  attribute('created_at')
76
96
  attribute('updated_at')
@@ -98,6 +118,12 @@ module Fracassandra
98
118
  @updated_at ||= now
99
119
 
100
120
  Fracassandra::database.insert(column_family, key, h)
121
+
122
+ if @update_operation
123
+ self.send(update_hook.to_sym)
124
+ elsif create_hook
125
+ self.send(create_hook.to_sym)
126
+ end
101
127
  end
102
128
 
103
129
  def destroy
@@ -0,0 +1,24 @@
1
+ # Sunspot support for Fracassandra
2
+ # Copyright © 2011, Jeremy Tregunna, All Rights Reserved.
3
+ #
4
+ # Sunspot integration for fracassandra
5
+ #
6
+
7
+ if defined?(Sunspot)
8
+ module Fracassandra
9
+ class FracassandraInstanceAdapter < Sunspot::Adapters::InstanceAdapter
10
+ def id
11
+ @instance.key
12
+ end
13
+ end
14
+
15
+ class FracassandraDataAccessor < Sunspot::Adapters::DataAccessor
16
+ def load(id)
17
+ @clazz[id]
18
+ end
19
+ end
20
+ end
21
+
22
+ Sunspot::Adapters::InstanceAdapter.register(Fracassandra::FracassandraInstanceAdapter, Fracassandra::Model)
23
+ Sunspot::Adapters::DataAdapter.register(Fracassandra::FracassandraDataAdapter, Fracassandra::Model)
24
+ end
data/lib/fracassandra.rb CHANGED
@@ -1,24 +1,18 @@
1
1
  # Frac.as Cassandra Library
2
2
  # Copyright © 2011, Jeremy Tregunna, All Rights Reserved.
3
3
 
4
- FRACASSANDRA_VERSION = "0.3.0"
4
+ FRACASSANDRA_VERSION = "0.3.2"
5
5
 
6
6
  require 'fracassandra/model'
7
- require 'fracassandra/super_model'
8
7
 
9
8
  module Fracassandra
10
- $cassandra = nil
11
-
12
- def self.database=(db)
13
- $cassandra = db
14
- end
15
-
16
- def self.database
17
- $cassandra
9
+ class << self
10
+ attr_accessor :database
18
11
  end
19
12
 
20
13
  def self.credentials=(options)
21
- $cassandra.login!(options[:username], options[:password])
14
+ raise DatabaseError, "No database defined." unless database
15
+ database.login!(options[:username], options[:password])
22
16
  end
23
17
 
24
18
  class DatabaseError < Exception
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fracassandra
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 0
10
- version: 0.3.0
9
+ - 2
10
+ version: 0.3.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jeremy Tregunna
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-16 00:00:00 -04:00
18
+ date: 2011-03-23 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -141,6 +141,7 @@ files:
141
141
  - fracassandra.gemspec
142
142
  - lib/fracassandra.rb
143
143
  - lib/fracassandra/model.rb
144
+ - lib/fracassandra/sunspot.rb
144
145
  - spec/model_spec.rb
145
146
  - spec/spec_helper.rb
146
147
  has_rdoc: true