populate-me 0.0.27 → 0.0.28

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ed06edf0120a1daf291849f203063ec826302f8e
4
+ data.tar.gz: a3fcd26ccae3347c8ecac05afcd6030967e434b7
5
+ SHA512:
6
+ metadata.gz: 53dcf1737422f6c1fa10bfdd32d13650ee8dad526ac9561b5d77ca50cd97ebb7bab6c91a4e9d58ad0919220a6b797762075db1939bd135f85c9a66f0a437711c
7
+ data.tar.gz: a1b50ab8e0ea8ebd9647695420296f10cc912cb6a3c5cac306c45bca0bb6b1867fa264ea7a2f93fe3352894a2d1c6aa90c331cc408cf3ea46e90b2ce56422246
@@ -0,0 +1,8 @@
1
+ .DS_STORE
2
+ *.swp
3
+ .ruby-version
4
+ pkg/
5
+ *.gem
6
+ Gemfile.lock
7
+ .bundle/
8
+
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2017 Mickael Riga
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
20
+
@@ -9,8 +9,8 @@ module PopulateMe
9
9
  def self.included(weak)
10
10
  weak.extend(MutateClass)
11
11
  weak.db = DB if defined?(DB)
12
- weak.schema = BSON::OrderedHash.new
13
- weak.relationships = BSON::OrderedHash.new
12
+ weak.schema = {}
13
+ weak.relationships = {}
14
14
  end
15
15
 
16
16
  module MutateClass
@@ -45,30 +45,36 @@ module PopulateMe
45
45
  def find_one(spec_or_object_id=nil,opts={})
46
46
  spec_or_object_id.nil? ? spec_or_object_id = opts.delete(:selector) : spec_or_object_id.update(opts.delete(:selector)||{})
47
47
  opts = {:sort=>self.sorting_order}.update(opts)
48
- item = collection.find_one(spec_or_object_id,opts)
48
+ item = collection.find(spec_or_object_id,opts).first
49
49
  item.nil? ? nil : self.new(item)
50
50
  end
51
51
  def count(opts={}); collection.count(opts); end
52
52
 
53
53
  def sorting_order
54
54
  @sorting_order ||= if @schema.key?('position')&&!@schema['position'][:scope].nil?
55
- [[@schema['position'][:scope], :asc], ['position', :asc]]
55
+ {@schema['position'][:scope] => 1, 'position' => 1}
56
56
  elsif @schema.key?('position')
57
- [['position', :asc],['_id', :asc]]
57
+ {'position' => 1, '_id' => 1}
58
58
  else
59
- ['_id', :asc]
59
+ {'_id' => 1}
60
60
  end
61
61
  end
62
62
 
63
- def sort(id_list)
64
- id_list.each_with_index do |id, position|
65
- collection.update(ref(id), {'$set' => {'position'=>position}})
63
+ def sort(ids)
64
+ requests = ids.each_with_index.inject([]) do |list, (id, i)|
65
+ list << {update_one:
66
+ {
67
+ filter: ref(id),
68
+ update: {'$set'=>{'position'=>i}}
69
+ }
70
+ }
66
71
  end
72
+ collection.bulk_write requests
67
73
  end
68
74
 
69
75
  # CRUD
70
- def get(id, opts={}); doc = collection.find_one(ref(id), opts); doc.nil? ? nil : self.new(doc); end
71
- def delete(id); collection.remove(ref(id)); end
76
+ def get(id, opts={}); doc = collection.find(ref(id), opts).first; doc.nil? ? nil : self.new(doc); end
77
+ def delete(id); collection.delete_one(ref(id)); end
72
78
 
73
79
  def get_multiple(ids, opts={})
74
80
  corrected_ids = ids.map{|id| correct_id_class(id) }
@@ -256,16 +262,18 @@ module PopulateMe
256
262
  before_save
257
263
  if new?
258
264
  before_create
259
- id = model.collection.insert(@doc)
260
- @doc['_id'] = id
265
+ result = model.collection.insert_one(@doc)
266
+ if result.ok? and @doc['_id'].nil?
267
+ @doc['_id'] = result.inserted_id
268
+ end
261
269
  after_create
262
270
  else
263
271
  before_update
264
- id = model.collection.update({'_id'=>@doc['_id']}, @doc)
272
+ result = model.collection.update_one({'_id'=>@doc['_id']}, @doc)
265
273
  after_update
266
274
  end
267
275
  after_save
268
- id.nil? ? nil : self
276
+ result.ok? ? self : nil
269
277
  end
270
278
  def before_save; end
271
279
  def before_create; end
@@ -283,9 +291,16 @@ module PopulateMe
283
291
  # so we should extend on demand.
284
292
  # Meaning the cursor object should be extended, not the cursor class.
285
293
  # @mutant_class should be defined before extending
286
- def next
287
- n = super
288
- n.nil? ? nil : @mutant_class.new(n)
294
+ #
295
+ # def next
296
+ # n = super
297
+ # n.nil? ? nil : @mutant_class.new(n)
298
+ # end
299
+ #
300
+ def each
301
+ super do |doc|
302
+ yield @mutant_class.new(doc)
303
+ end if block_given?
289
304
  end
290
305
  # legacy
291
306
  def each_mutant(&b); each(&b); end
@@ -45,7 +45,11 @@ module PopulateMe
45
45
  delete_files_for(k) unless new?
46
46
  @temp_attachments ||= {}
47
47
  @temp_attachments[k] = v
48
- attachment_id = model.gridfs.put(v[:tempfile], {:filename=>v[:filename], :content_type=>v[:type]})
48
+ attachment_id = model.gridfs.upload_from_stream(
49
+ v[:filename],
50
+ v[:tempfile], {
51
+ :content_type=>v[:type]
52
+ })
49
53
  @doc[k] = {'original'=>attachment_id}
50
54
  end
51
55
  end
@@ -80,17 +84,17 @@ module PopulateMe
80
84
  def convert(col, convert_steps, style)
81
85
  return if @doc[col].nil?
82
86
  if @temp_attachments.nil? || @temp_attachments[col].nil?
83
- f = model.gridfs.get(@doc[col]['original']) rescue nil
87
+ f = model.gridfs.find({'_id'=>@doc[col]['original']}).first
84
88
  return if f.nil?
85
- return unless f.content_type[/^image\//]
86
89
  src = Tempfile.new('MongoStash_src')
87
90
  src.binmode
88
- src.write(f.read(4096)) until f.eof?
91
+ model.gridfs.download_to_stream(@doc[col]['original'], src)
92
+ return unless f['contentType'].to_s[/^image\//]
89
93
  src.close
90
94
  @temp_attachments ||= {}
91
95
  @temp_attachments[col] ||= {}
92
96
  @temp_attachments[col][:tempfile] = src
93
- @temp_attachments[col][:type] = f.content_type
97
+ @temp_attachments[col][:type] = f['contentType']
94
98
  else
95
99
  return unless @temp_attachments[col][:type][/^image\//]
96
100
  src = @temp_attachments[col][:tempfile]
@@ -107,9 +111,13 @@ module PopulateMe
107
111
  dest.close
108
112
  system "convert \"#{src.path}\" #{convert_steps} \"#{dest.path}\""
109
113
  filename = "#{model.name}/#{self.id}/#{style}"
110
- attachment_id = model.gridfs.put(dest.open, {:filename=>filename, :content_type=>content_type})
114
+ attachment_id = model.gridfs.upload_from_stream(
115
+ filename,
116
+ dest.open,
117
+ {:content_type=>content_type}
118
+ )
111
119
  @doc[col] = @doc[col].update({style=>attachment_id})
112
- model.collection.update({'_id'=>@doc['_id']}, @doc)
120
+ model.collection.update_one({'_id'=>@doc['_id']}, @doc)
113
121
  #src.close!
114
122
  dest.close!
115
123
  end
@@ -138,7 +146,7 @@ module PopulateMe
138
146
  next if old_hash==fixed_hash
139
147
 
140
148
  if for_real
141
- c.collection.update({'_id'=>e.id}, {'$set'=>fixed_hash})
149
+ c.collection.update_one({'_id'=>e.id}, {'$set'=>fixed_hash})
142
150
  else
143
151
  puts old_hash.inspect
144
152
  puts fixed_hash.inspect
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'populate-me'
3
- s.version = "0.0.27"
3
+ s.version = "0.0.28"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.summary = "ALPHA !!! Populate Me is relatively complete but simple CMS"
6
6
  s.description = "ALPHA !!! Populate Me is relatively complete but simple CMS. It includes a Rack middleware for putting in your Rack stack, and a bespoke MongoDB ODM. But Populate Me is not really finished yet."
@@ -9,7 +9,16 @@ Gem::Specification.new do |s|
9
9
  s.author = "Mickael Riga"
10
10
  s.email = "mig@mypeplum.com"
11
11
  s.homepage = "https://github.com/mig-hub/populate-me"
12
- s.add_dependency('rack-golem')
13
- s.add_dependency('json')
12
+ s.licenses = ['MIT']
13
+
14
+ s.add_dependency 'rack-golem', '~> 0'
15
+ s.add_dependency 'json', '~> 2.1'
16
+ s.add_dependency 'mongo', '~> 2.0'
17
+
18
+ s.add_development_dependency 'bundler', '~> 1.13'
19
+ s.add_development_dependency 'bacon', '~> 1.2'
20
+ s.add_development_dependency 'rack-test', '~> 0.6'
21
+ s.add_development_dependency 'racksh', '~> 1.0'
22
+
14
23
  end
15
24
 
@@ -26,3 +26,4 @@ describe 'String' do
26
26
  end
27
27
  end
28
28
  end
29
+
@@ -8,12 +8,12 @@ require 'rack/utils'
8
8
  $:.unshift './lib'
9
9
  require 'populate_me/mongo'
10
10
 
11
- MONGO = ::Mongo::MongoClient.new
11
+ MONGO = Mongo::Client.new([ '127.0.0.1:27017' ], :database => 'test-mongo-mutation')
12
12
  class NoDB
13
13
  include PopulateMe::Mongo::Plug
14
14
  def self.human_name; 'No DB'; end
15
15
  end
16
- DB = MONGO['test-mongo-mutation']
16
+ DB = MONGO.database
17
17
 
18
18
  class Naked; include PopulateMe::Mongo::Plug; end
19
19
 
@@ -54,21 +54,21 @@ describe "PopulateMe::Mongo::Mutation" do
54
54
  end
55
55
  end
56
56
 
57
- shared "Empty BSON" do
58
- it "Should be set to an empty BSON ordered hash by default" do
59
- @bson.class.should==::BSON::OrderedHash
57
+ shared "Empty Hash" do
58
+ it "Should be set to an empty hash by default" do
59
+ @bson.class.should==Hash
60
60
  @bson.empty?.should==true
61
61
  end
62
62
  end
63
63
 
64
64
  describe ".schema" do
65
65
  before { @bson = Naked.schema }
66
- behaves_like "Empty BSON"
66
+ behaves_like "Empty Hash"
67
67
  end
68
68
 
69
69
  describe ".relationships" do
70
70
  before { @bson = Naked.relationships }
71
- behaves_like "Empty BSON"
71
+ behaves_like "Empty Hash"
72
72
  end
73
73
 
74
74
  describe ".human_name" do
@@ -102,9 +102,14 @@ describe "PopulateMe::Mongo::Mutation" do
102
102
  BSON::ObjectId.legal?(string_id).should==true
103
103
  Address.ref(string_id).should=={'_id'=>BSON::ObjectId.from_string(string_id)}
104
104
  end
105
+ it 'Makes a selector for multiple docs if argument is an Array' do
106
+ Address.ref([]).should=={'_id'=>{'$in'=>[]}}
107
+ id = BSON::ObjectId.new
108
+ string_id = '000000000000000000000000'
109
+ Address.ref([id,string_id]).should=={'_id'=>{'$in'=>[id,BSON::ObjectId.from_string(string_id)]}}
110
+ end
105
111
  it 'Just put an empty string in selector for any invalid argument' do
106
112
  Address.ref('abc').should=={'_id'=>''}
107
- Address.ref([]).should=={'_id'=>''}
108
113
  end
109
114
  end
110
115
 
@@ -262,11 +267,13 @@ describe "PopulateMe::Mongo::Mutation" do
262
267
  describe 'CursorMutation' do
263
268
  it 'Should give the correct class of object on iterations' do
264
269
  Address.new('body'=>'42').save
265
- Address.find.to_a[0].model.name.should=='Address'
270
+ Address.find.each do |a|
271
+ a.model.name.should=='Address'
272
+ end
266
273
  end
267
274
  end
268
275
 
269
276
  end
270
277
 
271
- MONGO.drop_database('test-mongo-mutation')
278
+ DB.drop
272
279
 
metadata CHANGED
@@ -1,48 +1,113 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: populate-me
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.27
5
- prerelease:
4
+ version: 0.0.28
6
5
  platform: ruby
7
6
  authors:
8
7
  - Mickael Riga
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2016-04-19 00:00:00.000000000 Z
11
+ date: 2017-05-11 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rack-golem
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: json
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
- version: '0'
33
+ version: '2.1'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
- version: '0'
40
+ version: '2.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mongo
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.13'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.13'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bacon
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rack-test
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.6'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.6'
97
+ - !ruby/object:Gem::Dependency
98
+ name: racksh
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.0'
46
111
  description: ALPHA !!! Populate Me is relatively complete but simple CMS. It includes
47
112
  a Rack middleware for putting in your Rack stack, and a bespoke MongoDB ODM. But
48
113
  Populate Me is not really finished yet.
@@ -51,6 +116,9 @@ executables: []
51
116
  extensions: []
52
117
  extra_rdoc_files: []
53
118
  files:
119
+ - ".gitignore"
120
+ - Gemfile
121
+ - LICENSE
54
122
  - README.md
55
123
  - lib/populate_me/control.rb
56
124
  - lib/populate_me/control/_public/css/main.css
@@ -98,27 +166,27 @@ files:
98
166
  - test/spec_ext.rb
99
167
  - test/spec_mongo_mutation.rb
100
168
  homepage: https://github.com/mig-hub/populate-me
101
- licenses: []
169
+ licenses:
170
+ - MIT
171
+ metadata: {}
102
172
  post_install_message:
103
173
  rdoc_options: []
104
174
  require_paths:
105
- - ./lib
175
+ - "./lib"
106
176
  required_ruby_version: !ruby/object:Gem::Requirement
107
- none: false
108
177
  requirements:
109
- - - ! '>='
178
+ - - ">="
110
179
  - !ruby/object:Gem::Version
111
180
  version: '0'
112
181
  required_rubygems_version: !ruby/object:Gem::Requirement
113
- none: false
114
182
  requirements:
115
- - - ! '>='
183
+ - - ">="
116
184
  - !ruby/object:Gem::Version
117
185
  version: '0'
118
186
  requirements: []
119
187
  rubyforge_project:
120
- rubygems_version: 1.8.23
188
+ rubygems_version: 2.4.5.1
121
189
  signing_key:
122
- specification_version: 3
190
+ specification_version: 4
123
191
  summary: ALPHA !!! Populate Me is relatively complete but simple CMS
124
192
  test_files: []