mongo_grid 0.3.0 → 0.3.1

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: e282904f72ac6d5ae8d5151b448cbabbc1a2de1a3c6bc69331a94a0b52e41b7e
4
- data.tar.gz: 88b72e432aa20e86f316051f3becf54f38f850b902eb432e5da744c8d0c5dd82
3
+ metadata.gz: ffcb534714ce76aae95b96022f604a95252d5b442b6182c8f96e3d91cc2c8254
4
+ data.tar.gz: 87bf5014f84e6a7a17d14fbac507e69ea17cbf29840b66dbc2a9e90b8bca3f51
5
5
  SHA512:
6
- metadata.gz: 2d59f07057c4b286a65107562e4fadfcd1ba68cc6dfaf2c0d87c01e43355da16375e2a5c52ca44db849aabdb7c068dd3acf3e1e46a71433886f4c45136ee5ee8
7
- data.tar.gz: f72f9b9af7bf17ab134f04138a1006593407b594d72b39b8da31a490b0f08f18bb50370442e8b9b3c2603937d36d0e7042f7349c7223df5c456b085951f9531a
6
+ metadata.gz: 4345dd3ce0b3ac61feda1055e81e93ea9cd748a94619c199e3b041eddcfcad309959e0f0efbb1d0c1f8cbddae77d942bd5497806a6139e813b71aeae8c722f2a
7
+ data.tar.gz: 78f60241b7a247e265330ab92dd8745b4061e7e5e8a66be5de11850d21d6458c2c8224b319e28414630e75711cfef4d43d6c8ec67b71de3cad1b5a7609574dbd
data/.gitignore CHANGED
@@ -7,4 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
- .gem
10
+ *.gem
data/README.md CHANGED
@@ -47,15 +47,15 @@ resize -help
47
47
 
48
48
  ### Mongoid extensions
49
49
 
50
- This gem also add four dynamic method in mongoid module.
50
+ This gem also add some dynamic methods in mongoid module.
51
51
  ```
52
- - remove_logo
53
- - remove_avatar
54
- - remove_attach
55
- - remove_embed
52
+ - remove_XXX
53
+ - delete_medias(content)
56
54
  ```
57
55
 
58
- These methods can be used in module callback when you want to delete a document in mongodb
56
+ remove_XXX method can be used in module callback when you want to delete a document in mongodb
57
+
58
+ delete_medias(content) used to delete medias within content like article body
59
59
 
60
60
  ### Action Base extensions
61
61
 
File without changes
data/lib/mongo_grid.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'mongo_grid/version'
1
+ require 'version'
2
2
 
3
3
  #Dir[File.join(File.dirname(__FILE__), 'mongo_grid', '*.rb')].each do |extension|
4
4
  # require extension
@@ -65,6 +65,6 @@ module ::MongoGrid
65
65
  end
66
66
  end
67
67
 
68
-
69
- require 'mongo_grid/mongoid'
70
- require 'mongo_grid/action_base'
68
+ require 'mongoid'
69
+ require 'action_base'
70
+ require 'plug'
data/lib/mongoid.rb ADDED
@@ -0,0 +1,56 @@
1
+ module ::Mongoid
2
+ module Document
3
+
4
+ def self.included(base)
5
+ base.include(InstanceMethods)
6
+ base.extend(ClassMethods)
7
+ end
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
56
+ end
data/lib/plug.rb ADDED
@@ -0,0 +1,24 @@
1
+ module ::Plug
2
+ module Mixin
3
+
4
+ def self.included(base)
5
+ base.extend(ClassMethods)
6
+ end
7
+
8
+ module ClassMethods
9
+ def array_attr(attr)
10
+ attr = attr.to_s
11
+ self.class_eval(%Q{
12
+ def #{attr}_list
13
+ return "" if self.#{attr}.blank?
14
+ self.#{attr}.join(",")
15
+ end
16
+ def #{attr}_list=(value)
17
+ self.#{attr} = value.split(",") if !value.blank?
18
+ end
19
+ })
20
+ end
21
+ end
22
+
23
+ end
24
+ end
@@ -1,3 +1,3 @@
1
1
  module MongoGrid
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
data/mongo_grid.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'mongo_grid/version'
4
+ require 'version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "mongo_grid"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_grid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - zxy
@@ -24,10 +24,11 @@ files:
24
24
  - bin/console
25
25
  - bin/resize
26
26
  - bin/setup
27
+ - lib/action_base.rb
27
28
  - lib/mongo_grid.rb
28
- - lib/mongo_grid/action_base.rb
29
- - lib/mongo_grid/mongoid.rb
30
- - lib/mongo_grid/version.rb
29
+ - lib/mongoid.rb
30
+ - lib/plug.rb
31
+ - lib/version.rb
31
32
  - mongo_grid.gemspec
32
33
  homepage: https://rubygems.org/lajunta/mongo_grid
33
34
  licenses:
@@ -1,16 +0,0 @@
1
- module ::Mongoid
2
- module Document
3
-
4
- %w[logo avatar attach embed].each do |name|
5
- module_eval(%Q(
6
- def remove_#{name}
7
- attach=self.#{name}
8
- unless attach.blank?
9
- id = BSON::ObjectId.from_string(attach['grid_id'])
10
- MongoGrid.grid.delete(id)
11
- end
12
- end
13
- ))
14
- end
15
- end
16
- end