mm-files 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ === 0.0.1 2009-08-03
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
@@ -0,0 +1,10 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.rdoc
5
+ Rakefile
6
+ lib/mm-files.rb
7
+ lib/mm-files/file.rb
8
+ lib/mm-files/files.rb
9
+ test/test_helper.rb
10
+ test/test_mm-files.rb
@@ -0,0 +1,7 @@
1
+
2
+ For more information on mm-files, see http://mm-files.rubyforge.org
3
+
4
+ NOTE: Change this information in PostInstall.txt
5
+ You can also delete it if you don't want it.
6
+
7
+
@@ -0,0 +1,48 @@
1
+ = mm-files
2
+
3
+ * http://github.com/#{github_username}/#{project_name}
4
+
5
+ == DESCRIPTION:
6
+
7
+ FIX (describe your package)
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * FIX (list of features or problems)
12
+
13
+ == SYNOPSIS:
14
+
15
+ FIX (code sample of usage)
16
+
17
+ == REQUIREMENTS:
18
+
19
+ * FIX (list of requirements)
20
+
21
+ == INSTALL:
22
+
23
+ * FIX (sudo gem install, anything else)
24
+
25
+ == LICENSE:
26
+
27
+ (The MIT License)
28
+
29
+ Copyright (c) 2009 David Cuadrado
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining
32
+ a copy of this software and associated documentation files (the
33
+ 'Software'), to deal in the Software without restriction, including
34
+ without limitation the rights to use, copy, modify, merge, publish,
35
+ distribute, sublicense, and/or sell copies of the Software, and to
36
+ permit persons to whom the Software is furnished to do so, subject to
37
+ the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be
40
+ included in all copies or substantial portions of the Software.
41
+
42
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
43
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/mm-files'
6
+
7
+ Hoe.plugin :newgem
8
+ # Hoe.plugin :website
9
+ # Hoe.plugin :cucumberfeatures
10
+
11
+ # Generate all the Rake tasks
12
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
+ $hoe = Hoe.spec 'mm-files' do
14
+ self.developer 'David Cuadrado', 'krawek@gmail.com'
15
+ # self.post_install_message = 'PostInstall.txt'
16
+ self.rubyforge_name = "mm-plugins"
17
+ self.extra_deps = [['mongomapper','>= 0.3.1']]
18
+
19
+ end
20
+
21
+ require 'newgem/tasks'
22
+ Dir['tasks/**/*.rake'].each { |t| load t }
23
+
24
+ # TODO - want other tests/tasks run by default? Add them to the list
25
+ # remove_task :default
26
+ # task :default => [:spec, :features]
@@ -0,0 +1,11 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ module MmFiles
5
+ VERSION = '0.0.1'
6
+ end
7
+
8
+ require 'mongomapper'
9
+ require 'mongo/gridfs'
10
+ require 'mm-files/file'
11
+ require 'mm-files/files'
@@ -0,0 +1,34 @@
1
+ module MongoMapper
2
+ class File < XGen::Mongo::GridFS::GridStore
3
+ attr_reader :id, :attributes
4
+
5
+ def initialize(owner, attrs = {})
6
+ @owner = owner
7
+ @id = attrs.delete("_id")
8
+
9
+ class_eval do
10
+ attrs.each do |k,v|
11
+ define_method(k) do
12
+ v
13
+ end
14
+ end
15
+ end
16
+
17
+ super(@owner.class.database, attrs["filename"], "r", :root => @owner.collection.name)
18
+ end
19
+
20
+ def [](name)
21
+ @attributes[name.to_s]
22
+ end
23
+
24
+ def self.fetch(owner, filename)
25
+ db = owner.class.database
26
+ criteria, options = FinderOptions.new(:filename => filename, :metadata => owner.id, :limit => 1).to_a
27
+
28
+ obj = db.collection("#{owner.collection.name}.files").find(criteria, options).next_object
29
+ if obj
30
+ self.new(owner, obj)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,43 @@
1
+ module MongoMapper
2
+ module Files
3
+ def self.included?(model)
4
+ model.class_eval do
5
+ after_create :_sync_pending_files
6
+ end
7
+ end
8
+
9
+ def put_file(filename, data)
10
+ if !new?
11
+ XGen::Mongo::GridFS::GridStore.open(self.class.database, filename, "w",
12
+ :root => self.collection.name,
13
+ :metadata => self.id) do |f|
14
+ f << data
15
+ end
16
+ else
17
+ (@_pending_files ||= {})[filename] = data
18
+ end
19
+ end
20
+
21
+ def fetch_file(filename)
22
+ MongoMapper::File.fetch(self, filename) if !new?
23
+ end
24
+
25
+ def files
26
+ criteria, options = FinderOptions.new(:metadata => self.id).to_a
27
+ coll = self.class.database.collection("#{self.collection.name}.files")
28
+ @files = coll.find(criteria, options).map do |a|
29
+ MongoMapper::File.new(self, a)
30
+ end
31
+ end
32
+
33
+ protected
34
+ def _sync_pending_files
35
+ if @_pending_files
36
+ @_pending_files.each do |filename, data|
37
+ put_file(filename, data)
38
+ end
39
+ @_pending_files = nil
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ require 'stringio'
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/../lib/mm-files'
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestMmFiles < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def test_truth
9
+ assert true
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mm-files
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - David Cuadrado
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-04 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: mongomapper
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.3.1
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: hoe
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.3.2
34
+ version:
35
+ description: FIX (describe your package)
36
+ email:
37
+ - krawek@gmail.com
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - History.txt
44
+ - Manifest.txt
45
+ - PostInstall.txt
46
+ files:
47
+ - History.txt
48
+ - Manifest.txt
49
+ - PostInstall.txt
50
+ - README.rdoc
51
+ - Rakefile
52
+ - lib/mm-files.rb
53
+ - lib/mm-files/file.rb
54
+ - lib/mm-files/files.rb
55
+ - test/test_helper.rb
56
+ - test/test_mm-files.rb
57
+ has_rdoc: true
58
+ homepage: http://github.com/#{github_username}/#{project_name}
59
+ licenses: []
60
+
61
+ post_install_message:
62
+ rdoc_options:
63
+ - --main
64
+ - README.rdoc
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ version:
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ version:
79
+ requirements: []
80
+
81
+ rubyforge_project: mm-plugins
82
+ rubygems_version: 1.3.5
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: FIX (describe your package)
86
+ test_files:
87
+ - test/test_helper.rb
88
+ - test/test_mm-files.rb