cassanova 0.0.4 → 0.0.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3807c49429cc3a92a05750b7f6680bd54d06a738
4
- data.tar.gz: 882b653f076c088938d26276d57ad115821a4187
3
+ metadata.gz: d2669f7f31131a1a3d11876c0d65a7bf8c0e1f32
4
+ data.tar.gz: 6e2e0f5b633218ca43ce4d608140bae0a222b1ee
5
5
  SHA512:
6
- metadata.gz: 7470d643ba26dbc172a1f4ab252bd642a897f13de40fac634a4febcf0e70b04a8e3a7c822a4206d837214405524ffb89ef5864c85050a609ba6a073acee40879
7
- data.tar.gz: 4d9f8c7f93240b56940229fda55c31cb2712dd610a424ed9d5d176504c67d4130042b75a6da59a3a2deded8f719d11a14e64581da916ced3c8079670a4e2c09f
6
+ metadata.gz: 4cc043f05ff5b2933c17f81d2230e42f86c460672a8f474b14f81e0d0fb861d59684c261b81bf5501595e91b2a677a66e7d297af342f6c95c17d5961048f0e1f
7
+ data.tar.gz: ee0bd6e9161c11bb0562ac4b2ace5f8562919471cf1a3fc9a62651786a99a837c3dddae23905bdc3b981ef0add093b6b9219bd49d89e5f4ff6fc2a93d9c9e31c
data/README.rdoc CHANGED
@@ -1,6 +1,12 @@
1
- = cassanova
1
+ = Cassanova
2
2
 
3
- Description goes here.
3
+ This is a work in progress guys.
4
+
5
+ == Credit
6
+
7
+ A big thanks goes to -
8
+
9
+ * {Maropost}[http://maropost.com] for giving me an opportunity to extract and release this functionality as a gem for the larger community
4
10
 
5
11
  == Contributing to cassanova
6
12
 
@@ -17,3 +23,4 @@ Description goes here.
17
23
  Copyright (c) 2014 Jagdeep Singh. See LICENSE.txt for
18
24
  further details.
19
25
 
26
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
data/cassanova.gemspec CHANGED
@@ -2,20 +2,19 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: cassanova 0.0.4 ruby lib
5
+ # stub: cassanova 0.0.5 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "cassanova"
9
- s.version = "0.0.4"
9
+ s.version = "0.0.5"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.authors = ["Jagdeep Singh"]
13
- s.date = "2014-12-01"
13
+ s.date = "2014-12-02"
14
14
  s.description = "Use cassandra with rails by adding active record style methods using active model."
15
15
  s.email = "jagdeepkh@gmail.com"
16
16
  s.extra_rdoc_files = [
17
17
  "LICENSE.txt",
18
- "README.md",
19
18
  "README.rdoc"
20
19
  ]
21
20
  s.files = [
@@ -23,7 +22,6 @@ Gem::Specification.new do |s|
23
22
  "Gemfile",
24
23
  "Gemfile.lock",
25
24
  "LICENSE.txt",
26
- "README.md",
27
25
  "README.rdoc",
28
26
  "Rakefile",
29
27
  "VERSION",
data/lib/cassanova.rb CHANGED
@@ -15,7 +15,9 @@ module Cassanova
15
15
  cattr_reader :cassandra_columns, :cassandra_hosts, :cassandra_database
16
16
 
17
17
  def initialize data={}
18
- cassandra_columns.each{|c| send("#{c}=", data[c.to_s]) }
18
+ params = {}
19
+ data.each{|k,v| params[k.to_s] = v }
20
+ cassandra_columns.each{|c| send("#{c}=", params[c.to_s]) }
19
21
  end
20
22
 
21
23
  def attributes
@@ -66,11 +68,37 @@ module Cassanova
66
68
 
67
69
  def self.create data={}
68
70
  obj = self.new(data)
69
- cols = obj.attributes.keys
70
- vals = cols.map{|k| obj.send(k) }
71
- query = "INSERT INTO #{self.name.underscore.pluralize} (#{cols.join(', ')}) VALUES (#{vals.map{'?'}.join(', ')})"
72
- query = Cassanova::Model.session.prepare(query)
73
- Cassanova::Model.session.execute(*[query, vals].flatten)
71
+ obj.created_at = Time.zone.now if obj.attributes.include?("created_at")
72
+ obj.updated_at = Time.zone.now if obj.attributes.include?("updated_at")
73
+ if obj.valid?
74
+ cols = obj.attributes.keys
75
+ vals = cols.map{|k| obj.send(k) }
76
+ query = "INSERT INTO #{self.name.underscore.pluralize} (#{cols.join(', ')}) VALUES (#{vals.map{'?'}.join(', ')})"
77
+ begin
78
+ query = Cassanova::Model.session.prepare(query)
79
+ result = Cassanova::Model.session.execute(*[query, vals].flatten)
80
+ return result.class == Cassandra::Results::Void
81
+ rescue Exception => e
82
+ obj.errors.add(:cassandra, e.message)
83
+ return obj
84
+ end
85
+ else
86
+ return obj
87
+ end
88
+ end
89
+
90
+ ### Relationship Methods ###
91
+
92
+ def self.belongs_to model_name
93
+ define_method(model_name.to_s) do
94
+ model_name.to_s.classify.constantize.where(:id => send("#{model_name}_id")).first
95
+ end
96
+ end
97
+
98
+ def self.has_many table_name
99
+ define_method(table_name.to_s) do
100
+ table_name.to_s.classify.constantize.where("#{self.class.name.underscore}_id" => send("id")).first
101
+ end
74
102
  end
75
103
 
76
104
  ### Config Methods ###
@@ -141,6 +169,13 @@ module Cassanova
141
169
  Cassanova::Model.session.execute(cq).rows.first['count']
142
170
  end
143
171
 
172
+ def destroy
173
+ cq = compiled_query
174
+ cq = "delete from " + cq.split("from")[1]
175
+ result = Cassanova::Model.session.execute(cq)
176
+ return result.class == Cassandra::Results::Void
177
+ end
178
+
144
179
  def self.parse response, table_name
145
180
  table_class = table_name.classify.constantize
146
181
  objs = []
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cassanova
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jagdeep Singh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-01 00:00:00.000000000 Z
11
+ date: 2014-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -115,14 +115,12 @@ executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files:
117
117
  - LICENSE.txt
118
- - README.md
119
118
  - README.rdoc
120
119
  files:
121
120
  - ".document"
122
121
  - Gemfile
123
122
  - Gemfile.lock
124
123
  - LICENSE.txt
125
- - README.md
126
124
  - README.rdoc
127
125
  - Rakefile
128
126
  - VERSION
data/README.md DELETED
File without changes