toughguy 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 503921d8feeb6ca7b9c9012b589aa6665df1bd24
4
- data.tar.gz: f04d741f4c17c579626f5f7c2a7141fdc085c17d
3
+ metadata.gz: 455afb848105f624c48c038bb7f4861ee4ab430a
4
+ data.tar.gz: b1cc52e6b73deaf3bd3f68ba30cbe77a3797f6ce
5
5
  SHA512:
6
- metadata.gz: 9b5c5257a30b1450a59e160d67629049d59042d758751c53b589e1a372199bbd5a4490b497c24e423fa0425bf65aca8533c80cd76d530645857e461b5adb8d9a
7
- data.tar.gz: 2ef7156be46aa1bda56afa34869002a414cc12305bb1d98a3cfbea47d11cb1e03b17c9e74c5e704a2bf87df26f809b41f62b58ed477a184db612d69ae58849c7
6
+ metadata.gz: 18fd76232d199c8b41dc67327f65b0f2abab1c35b3378a53f4145ee14c9ee8946c0734282c48147ecc4bbd2890c6abc1e807fe841129032c640717a4ebe40bbe
7
+ data.tar.gz: 70a115cd1c20335aff0109f12aa56e4b37d82878a06304ecb61dddc57549d418e529a440db3119922986dd92febb5ef5397e6f1e517074e94425d144cdaba28d
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- toughguy (0.2.6)
4
+ toughguy (0.2.8)
5
5
  assistance (= 0.1.5)
6
- bson_ext (= 1.12.3)
7
- mongo (= 1.12.3)
6
+ bson_ext (>= 1.8.0)
7
+ mongo (>= 1.8.0)
8
8
  plucky (= 0.6.6)
9
9
 
10
10
  GEM
@@ -41,3 +41,6 @@ DEPENDENCIES
41
41
  rake
42
42
  rspec
43
43
  toughguy!
44
+
45
+ BUNDLED WITH
46
+ 1.11.2
data/Rakefile CHANGED
@@ -1,4 +1,24 @@
1
1
  require 'rspec/core/rake_task'
2
2
  RSpec::Core::RakeTask.new
3
3
 
4
- task :default => :spec
4
+ task :default => :spec
5
+
6
+ require File.expand_path("./lib/toughguy/version", File.dirname(__FILE__))
7
+ PACKAGE_NAME = "toughguy"
8
+ VERSION = ToughGuy::VERSION
9
+
10
+ desc "Push gem to rubygems.org"
11
+ task :push_gem do
12
+ sh "gem build toughguy.gemspec"
13
+ sh "gem push toughguy-#{VERSION}.gem"
14
+ sh "rm *.gem"
15
+ end
16
+
17
+ desc "Install gem locally"
18
+ task :install_gem do
19
+ sh "rm ~/.toughguy/bin/*" rescue nil
20
+ sh "gem uninstall -a -x --force toughguy"
21
+ sh "gem build toughguy.gemspec"
22
+ sh "gem install toughguy-#{VERSION}.gem"
23
+ sh "rm *.gem"
24
+ end
@@ -31,7 +31,7 @@ module ToughGuy
31
31
  def model
32
32
  self.class
33
33
  end
34
-
34
+
35
35
  def bulk(&block)
36
36
  model.bulk(&block)
37
37
  end
@@ -67,7 +67,7 @@ module ToughGuy
67
67
  self.class.update({_id: id}, values.exclude(:_id))
68
68
  end
69
69
  end
70
-
70
+
71
71
  def update(hash)
72
72
  model.update({_id: id}, hash)
73
73
  end
@@ -119,7 +119,7 @@ module ToughGuy
119
119
  def exists?
120
120
  model.find(id) != nil
121
121
  end
122
-
122
+
123
123
  class << self
124
124
  def bulk(&block)
125
125
  reentered = @bulk
@@ -129,23 +129,23 @@ module ToughGuy
129
129
  ensure
130
130
  @bulk = nil unless reentered
131
131
  end
132
-
132
+
133
133
  def add_index(spec, opts={})
134
134
  @indexes ||= []
135
135
  @indexes << [spec, opts]
136
136
  end
137
-
137
+
138
138
  def ensure_index(spec, opts={})
139
139
  add_index(spec, opts)
140
140
  collection.create_index(spec, opts)
141
141
  end
142
-
142
+
143
143
  def recreate_indexes
144
144
  if @indexes
145
145
  @indexes.each {|idx| ensure_index(*idx)}
146
146
  end
147
147
  end
148
-
148
+
149
149
  def load(values)
150
150
  new(values).tap {|o| o.after_load}
151
151
  end
@@ -162,25 +162,25 @@ module ToughGuy
162
162
  end
163
163
  first(opts)
164
164
  end
165
-
165
+
166
166
  alias_method :find, :[]
167
167
 
168
168
  def query(opts = {})
169
169
  ToughGuy::Query.new(self).where(opts)
170
170
  end
171
-
171
+
172
172
  alias_method :q, :query
173
173
  alias_method :where, :query
174
174
  alias_method :filter, :query
175
-
175
+
176
176
  def sort(*args)
177
177
  query.sort(*args)
178
178
  end
179
-
179
+
180
180
  def limit(l, skip = 0)
181
181
  query.limit(l).skip(0)
182
182
  end
183
-
183
+
184
184
  def paginate(opts)
185
185
  query.paginate(opts)
186
186
  end
@@ -192,15 +192,15 @@ module ToughGuy
192
192
  def all(opts = {})
193
193
  query(opts).to_a
194
194
  end
195
-
195
+
196
196
  def each(*args, &block)
197
197
  query.each(*args, &block)
198
198
  end
199
-
199
+
200
200
  def map(key = nil, &block)
201
201
  query.map(key, &block)
202
202
  end
203
-
203
+
204
204
  def sort(*args)
205
205
  query.sort(*args)
206
206
  end
@@ -208,7 +208,7 @@ module ToughGuy
208
208
  def first(opts = {})
209
209
  query(opts).first
210
210
  end
211
-
211
+
212
212
  def map_keys(hash)
213
213
  hash.each do |key, short_key|
214
214
  define_method(key) {@values[short_key]}
@@ -219,17 +219,17 @@ module ToughGuy
219
219
  def collection
220
220
  @collection ||= database[collection_name]
221
221
  end
222
-
222
+
223
223
  def set_collection(c)
224
224
  @collection = c
225
225
  end
226
-
226
+
227
227
  def to_table_name
228
228
  parts = name.downcase.split('::')
229
229
  parts.push(parts.pop.pluralize)
230
230
  parts.join('.')
231
231
  end
232
-
232
+
233
233
  def collection_name
234
234
  @collection_name ||= to_table_name
235
235
  end
@@ -237,11 +237,11 @@ module ToughGuy
237
237
  def set_collection_name(n)
238
238
  @collection_name = n
239
239
  end
240
-
240
+
241
241
  def delete_all
242
242
  collection.remove
243
243
  end
244
-
244
+
245
245
  def delete(selector)
246
246
  if @bulk
247
247
  @bulk.find(selector).remove
@@ -249,7 +249,7 @@ module ToughGuy
249
249
  q(selector).remove
250
250
  end
251
251
  end
252
-
252
+
253
253
  def destroy_all
254
254
  q.each {|d| d.destroy}
255
255
  end
@@ -257,7 +257,7 @@ module ToughGuy
257
257
  def drop
258
258
  collection.drop
259
259
  end
260
-
260
+
261
261
  def update(*args)
262
262
  if @bulk
263
263
  @bulk.find(args[0]).update(args[1])
@@ -266,7 +266,7 @@ module ToughGuy
266
266
  end
267
267
  # (@bulk || collection).update(*args)
268
268
  end
269
-
269
+
270
270
  def stats
271
271
  collection.stats
272
272
  end
@@ -278,30 +278,26 @@ module ToughGuy
278
278
  end
279
279
 
280
280
  alias_method :db, :database
281
-
282
- @@db_map = {}
283
-
281
+
284
282
  def database=(db)
285
- if db.is_a?(String)
286
- db = (@@db_map[db] = connection[db])
287
- end
283
+ db = connection[db] if db.is_a?(String)
288
284
  @database = db
289
- # update also for mapped model
285
+ # update also for specialized model classes
290
286
  if self == ToughGuy::Model
291
287
  ToughGuy::MappedModel.database = db
292
288
  ToughGuy::SingletonModel.database = db
293
289
  end
294
290
  end
295
-
291
+
296
292
  def db_key(db)
297
293
  db.is_a?(String) ? db : db.name
298
294
  end
299
-
295
+
300
296
  def db_class_name(db_key)
301
297
  name = (db_key =~ /_(.+)/) && $1.gsub(/[^a-z0-9]/, '').capitalize
302
298
  "P_#{name}"
303
299
  end
304
-
300
+
305
301
  def subclass_with_db(db, db_key)
306
302
  c = Class.new(self).tap do |klass|
307
303
  klass.database = db
@@ -310,7 +306,7 @@ module ToughGuy
310
306
  @indexes.each {|idx| klass.ensure_index(*idx)}
311
307
  end
312
308
  end
313
-
309
+
314
310
  # create proper class name
315
311
  class_name = db_class_name(db_key)
316
312
  if class_name
@@ -318,10 +314,10 @@ module ToughGuy
318
314
  send(:remove_const, class_name) if const_defined?(class_name, false)
319
315
  const_set(class_name, c)
320
316
  end
321
-
317
+
322
318
  c
323
319
  end
324
-
320
+
325
321
  def with_db(db)
326
322
  key = db_key(db)
327
323
  return self if key == db_key(self.db)
@@ -338,23 +334,28 @@ module ToughGuy
338
334
  send(:remove_const, class_name) if const_defined?(class_name, false)
339
335
  end
340
336
  end
341
-
337
+
342
338
  def inherited(subclass)
339
+ subclass.connection = connection
343
340
  subclass.database = database
344
341
  end
345
-
342
+
346
343
  def mapped_db_classes
347
344
  (@subclass_map || {}).values.unshift(self)
348
345
  end
349
346
 
350
- @@connection = nil
351
-
352
347
  def connection
353
- @@connection
348
+ @connection
354
349
  end
355
350
 
356
351
  def connection=(c)
357
- @@connection = c
352
+ @connection = c
353
+
354
+ # update also for specialized model classes
355
+ if self == ToughGuy::Model
356
+ ToughGuy::MappedModel.connection = c
357
+ ToughGuy::SingletonModel.connection = c
358
+ end
358
359
  end
359
360
  end
360
361
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: UTF-8
2
2
  module ToughGuy
3
- Version = '0.2.7'
4
- end
3
+ VERSION = '0.2.8'
4
+ end
@@ -230,4 +230,4 @@ describe "Model.with_db" do
230
230
  s1.object_id.should == s3.object_id
231
231
  s2.object_id.should == s4.object_id
232
232
  end
233
- end
233
+ end
data/toughguy.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.require_path = 'lib'
9
9
  s.authors = ['Sharon Rosner']
10
10
  s.email = ['ciconia@gmail.com']
11
- s.version = ToughGuy::Version
11
+ s.version = ToughGuy::VERSION
12
12
  s.platform = Gem::Platform::RUBY
13
13
 
14
14
  s.files = `git ls-files`.split("\n")
@@ -20,4 +20,4 @@ Gem::Specification.new do |s|
20
20
  s.add_dependency 'bson_ext', '>= 1.8.0'
21
21
  s.add_dependency 'plucky', '0.6.6'
22
22
  s.add_dependency 'assistance', '0.1.5'
23
- end
23
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toughguy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sharon Rosner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-20 00:00:00.000000000 Z
11
+ date: 2016-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongo
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  version: '0'
110
110
  requirements: []
111
111
  rubyforge_project:
112
- rubygems_version: 2.4.6
112
+ rubygems_version: 2.5.1
113
113
  signing_key:
114
114
  specification_version: 4
115
115
  summary: Simple MongoDB ORM