populate-me 0.9.1 → 0.9.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1018ecfc599e93df910787d00774153225b3cd0712f4f457117e8fe24bd97367
4
- data.tar.gz: d6f45771022d5941be410d368933881689bfb9c9c5fe6f6ab4e76ce84f07a6b9
3
+ metadata.gz: b2e11800f347033e3d25223ba4b1296e07e1bdd7f3231d35888b6bd56c2cb126
4
+ data.tar.gz: 10a0e20a877ad1c9ae25f9096cf55f253eab4b1014e50368af6cb8ac28e39976
5
5
  SHA512:
6
- metadata.gz: d841176c180c4b9effb1b30d7a4e4643f4be01ad2854dfbd74fafffe0cd9dac7b1b7817d2e9e8810fa1ff5935418875abb0d4bff694e2fdb1497a54f37d65a4e
7
- data.tar.gz: 24dcc0e7770a04db79eaa342bc290539a3f11feca74ef2fe42d7be51c62eaab85c6cfaef9ba939298a0650a01b7dc765f433aa2303562663d5061d7f74c0e8e9
6
+ metadata.gz: 28d96b6d98af49675ee4bd2050528cdfd387032fb7390464334d789c7c7e2bd0fe5730e13e545f88383a6aa19602d95472c8a72ffeaa8ace60e580a3e6af4ca9
7
+ data.tar.gz: 52692b913a4d6f3083a283c0638571d90e96aab8b1bf8ace375de6c108bccaad0f919323dbffa5be715ff52d4fc0990a3d7e9c3859bbbcfd64da757e5e86f6a0
@@ -6,17 +6,43 @@ module PopulateMe
6
6
  class MissingMongoDBError < StandardError; end
7
7
 
8
8
  class Mongo < Document
9
+
10
+ self.settings.instance_eval do
11
+ def collection_name
12
+ puts 'yo'
13
+ if self[:collection_name].respond_to? :call
14
+ self[:collection_name].call
15
+ else
16
+ self[:collection_name]
17
+ end
18
+ end
19
+ end
9
20
 
10
21
  class << self
11
22
 
12
23
  def inherited sub
13
24
  super
14
- sub.set :collection_name, WebUtils.dasherize_class_name(sub.name)
25
+ # self.inherited is not useful anymore because we use ::collection_name
26
+ # so that the class name exist when this is run.
27
+ # Which is not the case with dynamically created classes.
28
+ #
29
+ # But we'll keep it for legacy code in the meantime.
30
+ # Decide if we want to keep it.
31
+ #
32
+ # If statment is here for dynamically created classes,
33
+ # because Class.new.name==nil and then it breaks (see tests).
34
+ unless sub.name.nil?
35
+ sub.set :collection_name, WebUtils.dasherize_class_name(sub.name)
36
+ end
37
+ end
38
+
39
+ def collection_name
40
+ self.settings.collection_name || WebUtils.dasherize_class_name(self.name)
15
41
  end
16
42
 
17
43
  def collection
18
44
  raise MissingMongoDBError, "Document class #{self.name} does not have a Mongo database." if settings.db.nil?
19
- settings.db[settings.collection_name]
45
+ settings.db[self.collection_name]
20
46
  end
21
47
 
22
48
  def set_id_field
@@ -1,4 +1,4 @@
1
1
  module PopulateMe
2
- VERSION = '0.9.1'
2
+ VERSION = '0.9.2'
3
3
  end
4
4
 
@@ -65,14 +65,21 @@ describe 'PopulateMe::Mongo' do
65
65
  end
66
66
 
67
67
  it 'Should set DB collection to dasherized full class name by default' do
68
- assert_equal "cat-fish", CatFish.settings.collection_name
69
- assert_equal "paradise--cat-fish", Paradise::CatFish.settings.collection_name
68
+ assert_equal "cat-fish", CatFish.collection_name
69
+ assert_equal "paradise--cat-fish", Paradise::CatFish.collection_name
70
70
  end
71
71
 
72
72
  it 'Finds collection in DB' do
73
73
  assert_equal DB['cat-fish'].name, CatFish.collection.name
74
74
  end
75
75
 
76
+ it 'Should set DB and collection name even for dynamically created classes' do
77
+ # Happens when an included module automatically happens a class.
78
+ # e.g. Slides for a Slideshow
79
+ CatFish.const_set("Item", Class.new(CatFish.superclass))
80
+ assert_equal "cat-fish--item", CatFish::Item.collection.name
81
+ end
82
+
76
83
  end
77
84
 
78
85
  describe 'Low level CRUD' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: populate-me
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mickael Riga
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-13 00:00:00.000000000 Z
11
+ date: 2019-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: web-utils
@@ -271,7 +271,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
271
271
  - !ruby/object:Gem::Version
272
272
  version: '0'
273
273
  requirements: []
274
- rubygems_version: 3.0.2
274
+ rubygems_version: 3.0.3
275
275
  signing_key:
276
276
  specification_version: 4
277
277
  summary: PopulateMe is an admin system for web applications.