cassanova 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 02171bde72bd86bd0b8b4369a7e763c16f465bd9
4
+ data.tar.gz: 4d7f38e8de65fc53d4971aea548b546a2eeb1e76
5
+ SHA512:
6
+ metadata.gz: b60fc7521a0cc6e30d3daa14f5c391e0335e2deee4bbb5be995499717f90330867cd031cd1f4dbc210f17383bbba471a0cf225bbeae1576bd928f4238c7bbbf3
7
+ data.tar.gz: e5933bbb47ef0517e9d79409bb35974394a4146f3ffd3dd669ae519de1c137fe5e4751c2b1856c35c491e2a8c1e9932d3b4fb8c212cb77e0e7ffe5debe35e9a9
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem "activemodel", "~> 3.2.17"
7
+ gem "cassandra-driver", "~> 1.0.0"
8
+
9
+ # Add dependencies to develop your gem here.
10
+ # Include everything needed to run rake, tests, features, etc.
11
+ group :development do
12
+ gem "shoulda", ">= 0"
13
+ gem "rdoc", "~> 3.12"
14
+ gem "bundler", "~> 1.0"
15
+ gem "jeweler", "~> 2.0.1"
16
+ gem "simplecov", ">= 0"
17
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,82 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (3.2.21)
5
+ activesupport (= 3.2.21)
6
+ builder (~> 3.0.0)
7
+ activesupport (3.2.21)
8
+ i18n (~> 0.6, >= 0.6.4)
9
+ multi_json (~> 1.0)
10
+ addressable (2.3.6)
11
+ builder (3.0.4)
12
+ cassandra-driver (1.0.0)
13
+ ione (~> 1.2)
14
+ descendants_tracker (0.0.4)
15
+ thread_safe (~> 0.3, >= 0.3.1)
16
+ docile (1.1.5)
17
+ faraday (0.9.0)
18
+ multipart-post (>= 1.2, < 3)
19
+ git (1.2.8)
20
+ github_api (0.12.2)
21
+ addressable (~> 2.3)
22
+ descendants_tracker (~> 0.0.4)
23
+ faraday (~> 0.8, < 0.10)
24
+ hashie (>= 3.3)
25
+ multi_json (>= 1.7.5, < 2.0)
26
+ nokogiri (~> 1.6.3)
27
+ oauth2
28
+ hashie (3.3.2)
29
+ highline (1.6.21)
30
+ i18n (0.6.11)
31
+ ione (1.2.0)
32
+ jeweler (2.0.1)
33
+ builder
34
+ bundler (>= 1.0)
35
+ git (>= 1.2.5)
36
+ github_api
37
+ highline (>= 1.6.15)
38
+ nokogiri (>= 1.5.10)
39
+ rake
40
+ rdoc
41
+ json (1.8.1)
42
+ jwt (1.2.0)
43
+ mini_portile (0.6.1)
44
+ multi_json (1.10.1)
45
+ multi_xml (0.5.5)
46
+ multipart-post (2.0.0)
47
+ nokogiri (1.6.5)
48
+ mini_portile (~> 0.6.0)
49
+ oauth2 (1.0.0)
50
+ faraday (>= 0.8, < 0.10)
51
+ jwt (~> 1.0)
52
+ multi_json (~> 1.3)
53
+ multi_xml (~> 0.5)
54
+ rack (~> 1.2)
55
+ rack (1.5.2)
56
+ rake (10.4.0)
57
+ rdoc (3.12.2)
58
+ json (~> 1.4)
59
+ shoulda (3.5.0)
60
+ shoulda-context (~> 1.0, >= 1.0.1)
61
+ shoulda-matchers (>= 1.4.1, < 3.0)
62
+ shoulda-context (1.2.1)
63
+ shoulda-matchers (2.7.0)
64
+ activesupport (>= 3.0.0)
65
+ simplecov (0.9.1)
66
+ docile (~> 1.1.0)
67
+ multi_json (~> 1.0)
68
+ simplecov-html (~> 0.8.0)
69
+ simplecov-html (0.8.0)
70
+ thread_safe (0.3.4)
71
+
72
+ PLATFORMS
73
+ ruby
74
+
75
+ DEPENDENCIES
76
+ activemodel (~> 3.2.17)
77
+ bundler (~> 1.0)
78
+ cassandra-driver (~> 1.0.0)
79
+ jeweler (~> 2.0.1)
80
+ rdoc (~> 3.12)
81
+ shoulda
82
+ simplecov
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Jagdeep Singh
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
File without changes
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = cassanova
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to cassanova
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2014 Jagdeep Singh. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "cassanova"
18
+ gem.homepage = "http://github.com/jagdeep/cassanova"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Get cassandra to play nice with rails.}
21
+ gem.description = %Q{Use cassandra with rails adding active record style methods using active model.}
22
+ gem.email = "jagdeepkh@gmail.com"
23
+ gem.authors = ["Jagdeep Singh"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ desc "Code coverage detail"
36
+ task :simplecov do
37
+ ENV['COVERAGE'] = "true"
38
+ Rake::Task['test'].execute
39
+ end
40
+
41
+ task :default => :test
42
+
43
+ require 'rdoc/task'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "cassanova #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/lib/cassanova.rb ADDED
@@ -0,0 +1,162 @@
1
+ require 'cassandra'
2
+
3
+ module Cassanova
4
+ class Model
5
+ extend ActiveModel::Naming
6
+ extend ActiveModel::Translation
7
+ include ActiveModel::AttributeMethods
8
+ include ActiveModel::Validations
9
+ include ActiveModel::Conversion
10
+
11
+ ### Initializing Methods ###
12
+
13
+ # define_attribute_methods COLUMNS
14
+
15
+ cattr_reader :cassandra_columns, :cassandra_hosts, :cassandra_database
16
+
17
+ def initialize data={}
18
+ cassandra_columns.each{|c| send("#{c}=", data[c.to_s]) }
19
+ end
20
+
21
+ def attributes
22
+ attrs = {}
23
+ cassandra_columns.each{|m| attrs[m] = send(m) }
24
+ return attrs
25
+ end
26
+
27
+ def assign_attributes data={}
28
+ data.each do |k,v|
29
+ begin
30
+ send("#{k}=", v)
31
+ rescue
32
+ # only assign valid attributes
33
+ end
34
+ end
35
+ end
36
+
37
+ def self.cluster
38
+ @@cassandra_cluster ||= Cassandra.cluster(hosts: cassandra_hosts)
39
+ end
40
+
41
+ def self.session
42
+ @@cassandra_session ||= cluster.connect(cassandra_database)
43
+ end
44
+
45
+ def self.execute *query
46
+ session.execute(query)
47
+ end
48
+
49
+ def self.prepare query
50
+ session.prepare(query)
51
+ end
52
+
53
+ ### Query Methods ###
54
+
55
+ def self.where conditions={}
56
+ query = Cassa::Query.new(:table_name => self.name.underscore.pluralize)
57
+ query.where(conditions)
58
+ return query
59
+ end
60
+
61
+ def self.select *attrs
62
+ query = Cassa::Query.new(:table_name => self.name.underscore.pluralize)
63
+ query.select(attrs)
64
+ return query
65
+ end
66
+
67
+ ### Config Methods ###
68
+
69
+ def self.columns *syms
70
+ # unless defined? @@cassandra_columns
71
+ @@cassandra_columns = syms if syms.present?
72
+ @@cassandra_columns.each{|c| attr_accessor(c) }
73
+ # end
74
+ end
75
+
76
+ def self.hosts *host_names
77
+ # unless defined? @@cassandra_hosts
78
+ @@cassandra_hosts = host_names if host_names.present?
79
+ # end
80
+ end
81
+
82
+ def self.database db
83
+ # unless defined? @@cassandra_database
84
+ @@cassandra_database = db if db.present?
85
+ # end
86
+ end
87
+
88
+ end
89
+
90
+ class Query
91
+ attr_accessor :query, :query_type, :queries, :table_name
92
+
93
+ def initialize options={}
94
+ @query = options[:query]
95
+ @query_type = options[:query_type]
96
+ @table_name = options[:table_name]
97
+ end
98
+
99
+ def where conditions={}
100
+ query = []
101
+ conditions.each do |key, val|
102
+ query << "#{key} = #{val}"
103
+ end
104
+ self.queries ||= []
105
+ self.queries << Cassa::Query.new(:query_type => "where", :query => query.join(" AND "))
106
+ return self
107
+ end
108
+
109
+ def select *attrs
110
+ self.queries ||= []
111
+ self.queries << Cassa::Query.new(:query_type => "select", :query => attrs.join(','))
112
+ return self
113
+ end
114
+
115
+ def limit i
116
+ cq = compiled_query + " LIMIT #{i}"
117
+ Cassa::Query.parse(Cassa::Model.session.execute(cq), table_name)
118
+ end
119
+
120
+ def first
121
+ limit(1).first
122
+ end
123
+
124
+ def all
125
+ Cassa::Query.parse(Cassa::Model.session.execute(compiled_query), table_name)
126
+ end
127
+
128
+ def count
129
+ cq = compiled_query
130
+ selects = cq.split("select ")[1].split(" from")[0]
131
+ cq = cq.gsub(selects, "COUNT(*)")
132
+ Cassa::Model.session.execute(cq).rows.first['count']
133
+ end
134
+
135
+ def self.parse response, table_name
136
+ table_class = table_name.classify.constantize
137
+ objs = []
138
+ response.each do |d|
139
+ objs << table_class.new(d)
140
+ end
141
+ return objs
142
+ end
143
+
144
+ def compiled_query
145
+ wheres = []
146
+ selects = []
147
+ queries.each do |query|
148
+ case query.query_type
149
+ when "where"
150
+ wheres << query.query
151
+ when "select"
152
+ selects << query.query
153
+ end
154
+ end
155
+ query = "select #{selects.present? ? selects.join(',') : '*'} from #{table_name}"
156
+ if wheres.present?
157
+ query += " where #{wheres.join(' AND ')}"
158
+ end
159
+ end
160
+
161
+ end
162
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,34 @@
1
+ require 'simplecov'
2
+
3
+ module SimpleCov::Configuration
4
+ def clean_filters
5
+ @filters = []
6
+ end
7
+ end
8
+
9
+ SimpleCov.configure do
10
+ clean_filters
11
+ load_adapter 'test_frameworks'
12
+ end
13
+
14
+ ENV["COVERAGE"] && SimpleCov.start do
15
+ add_filter "/.rvm/"
16
+ end
17
+ require 'rubygems'
18
+ require 'bundler'
19
+ begin
20
+ Bundler.setup(:default, :development)
21
+ rescue Bundler::BundlerError => e
22
+ $stderr.puts e.message
23
+ $stderr.puts "Run `bundle install` to install missing gems"
24
+ exit e.status_code
25
+ end
26
+ require 'test/unit'
27
+ require 'shoulda'
28
+
29
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
30
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
31
+ require 'cassanova'
32
+
33
+ class Test::Unit::TestCase
34
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestCassanova < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cassanova
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jagdeep Singh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activemodel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 3.2.17
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 3.2.17
27
+ - !ruby/object:Gem::Dependency
28
+ name: cassandra-driver
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: shoulda
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rdoc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.12'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.12'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: jeweler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 2.0.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 2.0.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Use cassandra with rails adding active record style methods using active
112
+ model.
113
+ email: jagdeepkh@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files:
117
+ - LICENSE.txt
118
+ - README.md
119
+ - README.rdoc
120
+ files:
121
+ - ".document"
122
+ - Gemfile
123
+ - Gemfile.lock
124
+ - LICENSE.txt
125
+ - README.md
126
+ - README.rdoc
127
+ - Rakefile
128
+ - VERSION
129
+ - lib/cassanova.rb
130
+ - test/helper.rb
131
+ - test/test_cassanova.rb
132
+ homepage: http://github.com/jagdeep/cassanova
133
+ licenses:
134
+ - MIT
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.1.11
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: Get cassandra to play nice with rails.
156
+ test_files: []