mongo_grid 0.3.3 → 0.3.4

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: 426e3942961accd764ebd0ca12fa3c52865a870d2848696794d715894fa486ec
4
- data.tar.gz: f26eef496b519d4d8813f8b540b59d5542c9cbedcf3845f1773d41c41a62e734
3
+ metadata.gz: e5b236710ee24c90ff53eb32c2e4782244ec9614d713a0c0189cd1b924eb9694
4
+ data.tar.gz: c9bf8fee4015f25460ab2fcbcdc1a627e5ebca6c7348c0377b99b2a2bb26aee7
5
5
  SHA512:
6
- metadata.gz: dd0ed2f026ffe6f7b0c2c87ad091578a1d70b00aefa428654668926c36de3ecc21d600b821ccccbc17e3039ac88c486041b22636a29a7b797b06006ff0a58dbb
7
- data.tar.gz: bb3896ed2014bf2435932d7c3d8df570626175ee831c080a30d6138258d9156580f64511d9e7ba2d5c6aaa2bbfd526c1602ff43cdce4e4ff7caa540c42ec93c1
6
+ metadata.gz: 66e834e878d9d32ba258870b993905ea119e71b7885a4cf92eeb513199bf39a5c7c665c14f337c690a6d7d249ad6ec8d73dc16f20770c1f9e5d5052978a1a563
7
+ data.tar.gz: fd911230532f2da9b216f9a0e01c7cee4b793c80b98e6feedf22f7f7bf6a4aa0ecf160e1e8ec37dd48bb9c2530f63b545b6985c67bd698796fb1b08518c84494
@@ -10,22 +10,21 @@ ActionController::Base.class_eval do
10
10
  redirect_to login_path and return
11
11
  end
12
12
  end
13
- ))
13
+ ))
14
14
  end
15
15
  end
16
16
 
17
17
  def attachit(model,attach = :attach,opts = {})
18
- unless params[model.to_sym][attach].blank?
19
- if params[:action] == 'update'
20
- old_attach = eval("@#{model}.#{attach.to_s}")
21
- unless old_attach.blank?
22
- id = BSON::ObjectId.from_string(old_attach['grid_id'])
23
- MongoGrid.grid.delete(id)
24
- end
18
+ attachs=params[attach.to_sym]
19
+ attachs_ary=[]
20
+ unless attachs.blank?
21
+ attachs.each {|att| attachs_ary << ::MongoGrid.uploadtogrid(att)}
22
+ if params[:action] == "update"
23
+ old_attachs = evel("@#{model}.#{attach.to_s}")
24
+ attachs_ary=attachs_ary+old_attachs unless old_attachs.blank?
25
25
  end
26
- attach=params[model.to_sym][attach]
27
- MongoGrid.uploadtogrid(attach,opts)
28
26
  end
27
+ return attachs_ary
29
28
  end
30
29
 
31
30
  def pageit
@@ -1,56 +1,41 @@
1
1
  module ::Mongoid
2
- module Document
2
+ module Document
3
3
 
4
- def self.included(base)
5
- base.include(InstanceMethods)
6
- base.extend(ClassMethods)
7
- end
4
+ def self.included(base)
5
+ base.include(InstanceMethods)
6
+ #base.extend(ClassMethods)
7
+ end
8
8
 
9
- module InstanceMethods
10
- # remove medias within the content
11
- def delete_medias(content)
12
- doc = Nokogiri::HTML(eval("self.#{content.to_s}"))
13
- #doc = Nokogiri::HTML(self.content)
14
- images = doc.css("img[src*='/see/']")
15
- if images.count>0
16
- images.each do |image|
17
- grid_id = image["src"].split("/")[2]
18
- MongoGrid.remove(grid_id)
19
- end
20
- end
21
- end
22
- end
23
-
24
- module ClassMethods
25
- def method_missing(name,*args)
26
- if name.to_s =~ /^remove_(.*)$/
27
- # if name is pluralize
28
- if name.to_s.pluralize == name.to_s
29
- return self.class_eval(%Q{
30
- define_method("remove_#{$1}") do
31
- grid_files=self.#{$1}
32
- grid_files.each do |grid_file|
33
- id = BSON::ObjectId.from_string(grid_file['grid_id'])
34
- MongoGrid.grid.delete(id)
35
- end
36
- end
37
- })
38
- else
39
- # name is singlular
40
- return self.class_eval(%Q{
41
- define_method("remove_#{$1}") do
42
- grid_file=self.#{$1}
43
- unless grid_file.blank?
44
- id = BSON::ObjectId.from_string(grid_file['grid_id'])
45
- MongoGrid.grid.delete(id)
46
- end
47
- end
48
- })
49
- end
50
- else
51
- puts "No this method"
52
- end
53
- end
54
- end
55
- end
9
+ module InstanceMethods
10
+ # remove medias within the content
11
+ def delete_medias(content)
12
+ doc = Nokogiri::HTML(eval("self.#{content.to_s}"))
13
+ #doc = Nokogiri::HTML(self.content)
14
+ images = doc.css("img[src*='/see/']")
15
+ if images.count>0
16
+ images.each do |image|
17
+ grid_id = image["src"].split("/")[2]
18
+ MongoGrid.remove(grid_id)
19
+ end
20
+ end
21
+ end
22
+
23
+ def remove_attachs
24
+ grid_files=eval("self.attachs")
25
+ puts grid_files
26
+ grid_files.each do |grid_file|
27
+ id = BSON::ObjectId.from_string(grid_file['grid_id'])
28
+ MongoGrid.grid.delete(id)
29
+ end
30
+ end
31
+
32
+ def remove_attach
33
+ grid_file=eval("self.attach")
34
+ unless grid_file.blank?
35
+ id = BSON::ObjectId.from_string(grid_file['grid_id'])
36
+ MongoGrid.grid.delete(id)
37
+ end
38
+ end
39
+ end
40
+ end
56
41
  end
@@ -1,3 +1,3 @@
1
1
  module MongoGrid
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_grid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - zxy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-10 00:00:00.000000000 Z
11
+ date: 2020-01-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: file upload to mongodb
14
14
  email: