zbox 0.1.0 → 0.1.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
- SHA1:
3
- metadata.gz: 49e5354beb9f28c06bda0a127b4add8e3f3fd024
4
- data.tar.gz: 4e500c5f3d8b89ed1b91d724351074d0aaec437c
2
+ SHA256:
3
+ metadata.gz: 0db865c602b30d49f5ab40ccf554c3adf16a8fa496fafd640be28ffb1a7d70f9
4
+ data.tar.gz: 3bb324b8a749a3d148fd705a6d9b5b68841a8bb53942f269582014f498f0c777
5
5
  SHA512:
6
- metadata.gz: 1e23271efbc2c42e413d499628ec62cfec3af182b01d3ce7cf28a7e2af47d263d5da5220a8bf986d649b91d93a570574a1e2560587fd4382c6cd743ba2b5e99f
7
- data.tar.gz: 3a251e8db5009a25e47a5c2780df66274941c6e9df5394a634706fe17efe80eefd9ad594449a508431e204bfb6439c9cec66fba250af340e8ced335c5d0dae78
6
+ metadata.gz: 9425b0c030364006e35777a57be9b43cf26dc7c04fa703ca5bf7a845b5879a6d86246e10ce9fa30d0f15d7ccd1de6230a87d10e076f1d782c079ef791e92a44e
7
+ data.tar.gz: 7e721d5755950a77a00d30de5104db7a3da1fd2d98cb34a91e821d6e39a5b139becf498546e496948cdbffb1a63692848140ffb60c800214d56bdfd1d209c6e6
@@ -0,0 +1,20 @@
1
+ Copyright 2017 zxy
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ ## Mongoid monkey patch added
2
+
3
+ when mongoid is included , dynamic method is added
4
+
5
+ when you need remove a grid file , you just need to
6
+
7
+ ```ruby
8
+ # xxx is a special field with hash type containing grid_id
9
+ after_destroy :remove_xxx
10
+
11
+ # if xxx is plurals
12
+ after_destory :remove_xxx
13
+ ```
14
+
15
+ when you remove a page that contains a field like content that contains some grid fs image
16
+
17
+ so you need following methods to remove these embed grid file
18
+
19
+ ```ruby
20
+ after_destroy -> {delete_medias :content}
21
+ ```
22
+
23
+ ## Plug::Mixin
24
+
25
+ when this module is included, you can use class method
26
+
27
+ ```ruby
28
+ array_attr :x,:y,:z..
29
+ # x, y, z a array filed
30
+ ```
31
+
32
+ this method add two method
33
+
34
+ ```
35
+ x_list=(v)
36
+ x_list
37
+ ```
38
+
39
+ this two methods convert array field to string between model and view
@@ -0,0 +1,56 @@
1
+ module Mongoid
2
+ module Mongoid::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
@@ -1,3 +1,3 @@
1
1
  module Zbox
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - zxy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-25 00:00:00.000000000 Z
11
+ date: 2018-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: quick_magick
@@ -31,17 +31,18 @@ executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
- - ".gitignore"
34
+ - MIT-LICENSE
35
+ - README.md
35
36
  - lib/zbox.rb
36
37
  - lib/zbox/ext/array.rb
37
38
  - lib/zbox/ext/hash.rb
39
+ - lib/zbox/ext/mongoid.rb
38
40
  - lib/zbox/ext/numeric.rb
39
41
  - lib/zbox/ext/plug.rb
40
42
  - lib/zbox/ext/struct.rb
41
43
  - lib/zbox/ext/time.rb
42
44
  - lib/zbox/img/qm.rb
43
45
  - lib/zbox/version.rb
44
- - zbox.gemspec
45
46
  homepage: http://lajunta.qq.com/
46
47
  licenses:
47
48
  - MIT
@@ -61,8 +62,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
62
  - !ruby/object:Gem::Version
62
63
  version: '0'
63
64
  requirements: []
64
- rubyforge_project: zbox
65
- rubygems_version: 2.6.8
65
+ rubyforge_project:
66
+ rubygems_version: 2.7.7
66
67
  signing_key:
67
68
  specification_version: 4
68
69
  summary: zxy's ruby toolbox'
data/.gitignore DELETED
@@ -1,4 +0,0 @@
1
- *.gem
2
- .bundle
3
- Gemfile.lock
4
- pkg/*
@@ -1,24 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "zbox/version"
4
-
5
- Gem::Specification.new do |s|
6
- s.name = "zbox"
7
- s.version = Zbox::VERSION
8
- s.platform = Gem::Platform::RUBY
9
- # gem.executables = ['foo'] #note,it's the file name relative to 'bin/',not the project root
10
- s.authors = ["zxy"]
11
- s.email = ["zxy@qq.com"]
12
- s.homepage = "http://lajunta.qq.com/"
13
- s.summary = %q{zxy's ruby toolbox'}
14
- s.description = %q{zxy's ruby tool collections'}
15
- s.licenses = "MIT"
16
-
17
- s.rubyforge_project = "zbox"
18
-
19
- s.files = `git ls-files`.split("\n")
20
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
- s.require_paths = ["lib"]
23
- s.add_runtime_dependency 'quick_magick', '~> 0'
24
- end