believer 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -40,8 +40,11 @@ module Believer
40
40
  begin
41
41
  name = "#{record_class.name} #{command_name}" if name.nil?
42
42
  return ActiveSupport::Notifications.instrument('cql.believer', :cql => cql, :name => name) do
43
- exec_opts = {}
44
- exec_opts[:consistency] = consistency_level unless consistency_level.nil?
43
+
44
+ unless consistency_level.nil? || consistency_level.empty?
45
+ exec_opts ||= {}
46
+ exec_opts[:consistency] = consistency_level
47
+ end
45
48
  begin
46
49
  return connection.execute(cql, exec_opts)
47
50
  rescue Cql::NotConnectedError => not_connected
@@ -47,9 +47,10 @@ module Believer
47
47
  diff > 0
48
48
  end
49
49
 
50
- def to_i
50
+ def value
51
51
  @value
52
52
  end
53
+ alias :to_i :value
53
54
 
54
55
  def initial_value
55
56
  if @initial_value.nil?
@@ -72,7 +72,8 @@ module Believer
72
72
  connection = Cql::Client.connect(cc)
73
73
  connection.use(cc[:keyspace])
74
74
  else
75
- connection = Cql::Client.connect(cc.delete_if { |k, v| k == :keyspace })
75
+ cc_no_keyspace = cc.delete_if { |k, v| k.to_s == 'keyspace' }
76
+ connection = Cql::Client.connect(cc_no_keyspace)
76
77
  end
77
78
  connection
78
79
  end
@@ -1,6 +1,6 @@
1
1
  module Believer
2
2
  module Querying
3
- delegate :select, :where, :order, :limit, :exists?, :to => :scoped
3
+ delegate :select, :where, :order, :limit, :exists?, :count, :pluck, :to => :scoped
4
4
 
5
5
  end
6
6
  end
@@ -9,6 +9,9 @@ module Believer
9
9
  Query.new(:record_class => self)
10
10
  end
11
11
 
12
+ def all
13
+ scoped
14
+ end
12
15
  end
13
16
 
14
17
  end
@@ -0,0 +1,42 @@
1
+ module Believer
2
+ module Test
3
+ class Database
4
+
5
+ # Drop, and create the keyspace. If options contains classes, creates all tables
6
+ # @param options [Hash] the options
7
+ # @option options :environment the environment to use. Must be a subclass of Believer::Environment::BaseEnv
8
+ # @option options :classes an array of classes to create tables for. Items can be strings or class constants
9
+ def self.setup(options = {})
10
+ env = options[:environment] || Believer::Base.environment
11
+
12
+ connection = env.create_connection(:connect_to_keyspace => false)
13
+
14
+ # First delete the existing keyspace
15
+ begin
16
+ puts "Dropping keyspace"
17
+ env.drop_keyspace
18
+ rescue Cql::QueryError
19
+ end
20
+
21
+ env.create_keyspace({}, connection)
22
+ connection.use(env.connection_configuration[:keyspace])
23
+
24
+ classes = options[:classes]
25
+ classes.each do |cl|
26
+ if cl.is_a?(String)
27
+ clazz = cl.split('::').inject(Kernel) { |scope, const_name| scope.const_get(const_name) }
28
+ elsif cl.is_a?(Class)
29
+ clazz = cl
30
+ end
31
+ if clazz.ancestors.include?(Believer::Base)
32
+ puts "Creating table #{clazz.table_name}"
33
+ clazz.create_table()
34
+ end
35
+
36
+ end unless classes.nil? || classes.empty?
37
+
38
+ end
39
+
40
+ end
41
+ end
42
+ end
@@ -1,5 +1,5 @@
1
1
  module Believer
2
2
  module Version
3
- VERSION = '0.2.7'
3
+ VERSION = '0.2.8'
4
4
  end
5
5
  end
data/spec/spec_helper.rb CHANGED
@@ -11,10 +11,12 @@ end
11
11
 
12
12
  require 'believer'
13
13
  require 'believer/test/test_run_life_cycle'
14
+ require 'believer/test/database'
14
15
 
15
16
  Dir[File.expand_path('../support/*.rb', __FILE__)].each {|f| require f}
16
17
 
17
- setup_database
18
+ #setup_database
19
+ Believer::Test::Database.setup(:environment => Test.test_environment, :classes => Test.classes)
18
20
 
19
21
  RSpec.configure do |config|
20
22
  config.add_setting :test_files_dir, :default => File.expand_path('../test_files/', __FILE__)
metadata CHANGED
@@ -1,119 +1,122 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: believer
3
- version: !ruby/object:Gem::Version
4
- version: 0.2.7
3
+ version: !ruby/object:Gem::Version
4
+ hash: 7
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 8
10
+ version: 0.2.8
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Jerphaes van Blijenburgh
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2013-10-30 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2013-11-05 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
15
21
  name: activemodel
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ~>
20
- - !ruby/object:Gem::Version
21
- version: '3'
22
- type: :runtime
23
22
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
23
+ requirement: &id001 !ruby/object:Gem::Requirement
25
24
  none: false
26
- requirements:
25
+ requirements:
27
26
  - - ~>
28
- - !ruby/object:Gem::Version
29
- version: '3'
30
- - !ruby/object:Gem::Dependency
31
- name: cql-rb
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: 1.1.0.pre6
27
+ - !ruby/object:Gem::Version
28
+ hash: 5
29
+ segments:
30
+ - 3
31
+ version: "3"
38
32
  type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: cql-rb
39
36
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
37
+ requirement: &id002 !ruby/object:Gem::Requirement
41
38
  none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: -2179262306
43
+ segments:
44
+ - 1
45
+ - 1
46
+ - 0
47
+ - pre
48
+ - 6
45
49
  version: 1.1.0.pre6
46
- - !ruby/object:Gem::Dependency
47
- name: connection_pool
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ! '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
54
50
  type: :runtime
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: connection_pool
55
54
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
55
+ requirement: &id003 !ruby/object:Gem::Requirement
57
56
  none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- - !ruby/object:Gem::Dependency
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ type: :runtime
65
+ version_requirements: *id003
66
+ - !ruby/object:Gem::Dependency
63
67
  name: rake
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ! '>='
68
- - !ruby/object:Gem::Version
69
- version: '0'
70
- type: :development
71
68
  prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
69
+ requirement: &id004 !ruby/object:Gem::Requirement
73
70
  none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
78
- - !ruby/object:Gem::Dependency
79
- name: rspec
80
- requirement: !ruby/object:Gem::Requirement
81
- none: false
82
- requirements:
83
- - - ! '>='
84
- - !ruby/object:Gem::Version
85
- version: '0'
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
77
+ version: "0"
86
78
  type: :development
79
+ version_requirements: *id004
80
+ - !ruby/object:Gem::Dependency
81
+ name: rspec
87
82
  prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
83
+ requirement: &id005 !ruby/object:Gem::Requirement
89
84
  none: false
90
- requirements:
91
- - - ! '>='
92
- - !ruby/object:Gem::Version
93
- version: '0'
94
- - !ruby/object:Gem::Dependency
95
- name: simplecov
96
- requirement: !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
99
- - - '='
100
- - !ruby/object:Gem::Version
101
- version: 0.7.1
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ hash: 3
89
+ segments:
90
+ - 0
91
+ version: "0"
102
92
  type: :development
93
+ version_requirements: *id005
94
+ - !ruby/object:Gem::Dependency
95
+ name: simplecov
103
96
  prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
97
+ requirement: &id006 !ruby/object:Gem::Requirement
105
98
  none: false
106
- requirements:
107
- - - '='
108
- - !ruby/object:Gem::Version
99
+ requirements:
100
+ - - "="
101
+ - !ruby/object:Gem::Version
102
+ hash: 1
103
+ segments:
104
+ - 0
105
+ - 7
106
+ - 1
109
107
  version: 0.7.1
110
- description: ! 'An Object Relational Mapping library for CQL3 '
111
- email:
108
+ type: :development
109
+ version_requirements: *id006
110
+ description: "An Object Relational Mapping library for CQL3 "
111
+ email:
112
112
  - jerphaes@gmail.com
113
113
  executables: []
114
+
114
115
  extensions: []
116
+
115
117
  extra_rdoc_files: []
116
- files:
118
+
119
+ files:
117
120
  - lib/believer/base.rb
118
121
  - lib/believer/batch.rb
119
122
  - lib/believer/batch_delete.rb
@@ -148,6 +151,7 @@ files:
148
151
  - lib/believer/querying.rb
149
152
  - lib/believer/relation.rb
150
153
  - lib/believer/scoping.rb
154
+ - lib/believer/test/database.rb
151
155
  - lib/believer/test/test_run_life_cycle.rb
152
156
  - lib/believer/update.rb
153
157
  - lib/believer/values.rb
@@ -180,31 +184,41 @@ files:
180
184
  - spec/support/setup_database.rb
181
185
  - spec/support/test_classes.rb
182
186
  homepage: http://github.com/jerphaes/believer
183
- licenses:
187
+ licenses:
184
188
  - Apache License 2.0
185
189
  post_install_message:
186
190
  rdoc_options: []
187
- require_paths:
191
+
192
+ require_paths:
188
193
  - lib
189
- required_ruby_version: !ruby/object:Gem::Requirement
194
+ required_ruby_version: !ruby/object:Gem::Requirement
190
195
  none: false
191
- requirements:
192
- - - ! '>='
193
- - !ruby/object:Gem::Version
196
+ requirements:
197
+ - - ">="
198
+ - !ruby/object:Gem::Version
199
+ hash: 55
200
+ segments:
201
+ - 1
202
+ - 9
203
+ - 2
194
204
  version: 1.9.2
195
- required_rubygems_version: !ruby/object:Gem::Requirement
205
+ required_rubygems_version: !ruby/object:Gem::Requirement
196
206
  none: false
197
- requirements:
198
- - - ! '>='
199
- - !ruby/object:Gem::Version
200
- version: '0'
207
+ requirements:
208
+ - - ">="
209
+ - !ruby/object:Gem::Version
210
+ hash: 3
211
+ segments:
212
+ - 0
213
+ version: "0"
201
214
  requirements: []
215
+
202
216
  rubyforge_project:
203
217
  rubygems_version: 1.8.25
204
218
  signing_key:
205
219
  specification_version: 3
206
220
  summary: CQL3 ORM
207
- test_files:
221
+ test_files:
208
222
  - spec/believer/base_spec.rb
209
223
  - spec/believer/callback_spec.rb
210
224
  - spec/believer/collection_columns_spec.rb