mongo_grid 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0b967f020175148e6e9660e41afe88a24107b524
4
- data.tar.gz: bdd8ab76393220b35e312d90ee92a4e926871a52
3
+ metadata.gz: eaaf801a15cf6a1c400fc477e72a2b8ddd2aff78
4
+ data.tar.gz: 885ad7f222cad01171aa333f6d63e4ddf4c42a04
5
5
  SHA512:
6
- metadata.gz: b290adb6b358518090d8a47afba2ded797d261d99fa795c83c3277d9ce8f2de061dd7414cf264226a974a39a0193c8e118538b8062a1da64819502012e46c4d4
7
- data.tar.gz: d954c56e866c6d939986f93b18c3c14d95741ae16342b8dc6e4ae6eb6cec4e3e5d390e93b552fad69ed14dfcf7bcf4363dd50aed484f2938a19209cb5330d891
6
+ metadata.gz: 4b9396ae097514e6df16d181263216caa947401a084aa6dbe9d7c7eb93b04a32994d0398de003bc0a8f2c142b662b4fb71dfa7328b23af35cbbeb66c10039e92
7
+ data.tar.gz: 9ebf0cc33dd29c9800c94d2ad99ceddd53f5a91d6b1792bc7da6f69f4e538e5f1e8f44fc7dfe334ff56937a1821aa910c960015245f98281290e9a75470310cd
@@ -1,36 +1,35 @@
1
- class ActionController::Base
2
- def self.need_role(*roles)
3
- roles.each do |role|
4
- eval(%Q(
1
+ require "action_controller"
2
+ ActionController::Base.class_eval do
3
+ def self.need_role(*roles)
4
+ roles.each do |role|
5
+ eval(%Q(
5
6
  def need_#{role.to_s}
6
7
  unless is_#{role.to_s}?
7
8
  flash[:alert] = "身份不对"
8
9
  redirect_to root_path and return
9
10
  end
10
11
  end
11
- ))
12
+ ))
13
+ end
12
14
  end
13
- end
14
-
15
15
 
16
- def attachit(model,attach = :attach)
17
- unless params[model.to_sym][attach].blank?
18
- if params[:action] == 'update'
19
- old_attach = eval("@#{model}.#{attach.to_s}")
20
- unless old_attach.blank?
21
- id = BSON::ObjectId.from_string(old_attach['grid_id'])
22
- MongoGrid.grid.delete(id)
16
+ def attachit(model,attach = :attach)
17
+ unless params[model.to_sym][attach].blank?
18
+ if params[:action] == 'update'
19
+ old_attach = eval("@#{model}.#{attach.to_s}")
20
+ unless old_attach.blank?
21
+ id = BSON::ObjectId.from_string(old_attach['grid_id'])
22
+ MongoGrid.grid.delete(id)
23
+ end
23
24
  end
25
+ attach=params[model.to_sym][attach]
26
+ MongoGrid.uploadtogrid(attach,width: 300)
24
27
  end
25
- attach=params[model.to_sym][attach]
26
- MongoGrid.uploadtogrid(attach,width: 300)
27
28
  end
28
- end
29
29
 
30
- def pageit
31
- params[:page] ||= 1
32
- per_page = 10
33
- @num=per_page*(params[:page].to_i-1)
30
+ def pageit
31
+ params[:page] ||= 1
32
+ per_page = 10
33
+ @num=per_page*(params[:page].to_i-1)
34
+ end
34
35
  end
35
-
36
- end
@@ -1,26 +1,27 @@
1
1
  module ::Mongoid
2
2
  module Document
3
- def remove_logo
4
- logo=self.logo
5
- unless logo.blank?
6
- id = BSON::ObjectId.from_string(logo['grid_id'])
7
- MongoGrid.grid.delete(id)
8
- end
9
- end
10
3
 
11
- def remove_avatar
12
- attach=self.avatar
4
+ %w[logo avatar attach].each do |name|
5
+ module_eval(%Q(
6
+ def remove_#{name}
7
+ attach=self.#{name}
13
8
  unless attach.blank?
14
9
  id = BSON::ObjectId.from_string(attach['grid_id'])
15
10
  MongoGrid.grid.delete(id)
16
11
  end
17
12
  end
18
- def remove_attach
19
- attach=self.attach
20
- unless attach.blank?
21
- id = BSON::ObjectId.from_string(attach['grid_id'])
22
- MongoGrid.grid.delete(id)
23
- end
13
+ ))
24
14
  end
15
+
16
+ =begin
17
+ def self.included(base)
18
+ base.class_eval(%Q(
19
+ before_destroy :remove_logo
20
+ before_destroy :remove_avatar
21
+ before_destroy :remove_attach
22
+ ))
23
+ end
24
+ =end
25
+
25
26
  end
26
27
  end
@@ -1,3 +1,3 @@
1
1
  module MongoGrid
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.6"
3
3
  end
data/lib/mongo_grid.rb CHANGED
@@ -1,5 +1,9 @@
1
- require "mongo_grid/version"
2
1
  require 'zbox'
2
+ require 'mongo_grid/version'
3
+
4
+ #Dir[File.join(File.dirname(__FILE__), 'mongo_grid', '*.rb')].each do |extension|
5
+ # require extension
6
+ #end
3
7
 
4
8
  module ::MongoGrid
5
9
  attr_accessor :db_name, :db_url
@@ -55,6 +59,8 @@ module ::MongoGrid
55
59
  :content_type=>content_type,:file_size=>file_size}
56
60
 
57
61
  end
62
+ end
58
63
 
59
64
 
60
- end
65
+ require 'mongo_grid/mongoid'
66
+ require 'mongo_grid/action_base'
data/mongo_grid.gemspec CHANGED
@@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ["lib"]
29
29
 
30
+ spec.add_development_dependency "action_controller", "~> 5.0.2"
30
31
  spec.add_development_dependency "bundler", "~> 1.11"
31
32
  spec.add_development_dependency "rake", "~> 11.2",'>=11.2.0'
32
33
  spec.add_development_dependency "zbox", "~> 0.0.5"
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.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - zxy
@@ -10,6 +10,20 @@ bindir: exe
10
10
  cert_chain: []
11
11
  date: 2017-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: action_controller
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.0.2
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.0.2
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement