dragonfly-mongoid_data_store 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7489acaa663c4678b8c995faa12ad684908579ec
4
+ data.tar.gz: c8e8dd35531ae09d8d73fc9457b8c4e5e7f9e270
5
+ SHA512:
6
+ metadata.gz: ade77f7494432fdc46e8eddab421c384ca690c3619f600c38fe06cbd458b332478b8ab826f34cb2954f8f169842b14ca443759f732b9faf60302ea8a97647a94
7
+ data.tar.gz: 023b3246c991ffc5e069b9145f8d62c22fcdda9dd9cef9ed79b088efd6d6756ba2471b0a84ffd22f3d737f822f70dec297862a68537a60a87328653e83594e26
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+ cache: bundler
3
+ script: 'bundle exec rake'
4
+ rvm:
5
+ - 2.1.2
6
+ services:
7
+ - mongodb
8
+
9
+ notifications:
10
+ email:
11
+ recipients:
12
+ - tomas.celizna@gmail.com
13
+ on_failure: change
14
+ on_success: never
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dragonfly-mongoid_data_store.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,8 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :minitest do
5
+ watch(%r{^lib/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
6
+ watch(%r{^test/.+_test\.rb$})
7
+ watch(%r{^test/test_helper\.rb$}) { 'test' }
8
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Tomas Celizna
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Asger Behncke Jacobsen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Dragonfly::MongoidDataStore
2
+
3
+ [![Build Status](https://travis-ci.org/tomasc/dragonfly-mongoid_data_store.svg)](https://travis-ci.org/tomasc/dragonfly-mongoid_data_store) [![Gem Version](https://badge.fury.io/rb/dragonfly-mongoid_data_store.svg)](http://badge.fury.io/rb/dragonfly-mongoid_data_store) [![Coverage Status](https://img.shields.io/coveralls/tomasc/dragonfly-mongoid_data_store.svg)](https://coveralls.io/r/tomasc/dragonfly-mongoid_data_store)
4
+
5
+ [Dragonfly](https://github.com/markevans/dragonfly) data store that uses [Mongoid::GridFs](https://github.com/ahoward/mongoid-grid_fs).
6
+
7
+ Data store similar to [dragonfly-mongo_data_store](https://github.com/markevans/dragonfly-mongo_data_store) which works with [Dragonfly](https://github.com/markevans/dragonfly) > 1 and [Mongoid](https://github.com/mongoid/mongoid) > 4.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'dragonfly-mongoid_data_store'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install dragonfly-mongoid_data_store
22
+
23
+ ## Usage
24
+
25
+ You can configure Dragonfly to use the mongoid datastore in the dragonfly initializer like so:
26
+
27
+ ```ruby
28
+ # config/initializers/dragonfly.rb
29
+
30
+ require 'dragonfly/mongoid_data_store'
31
+
32
+ Dragonfly.app.configure do
33
+ # ...
34
+
35
+ datastore :mongoid
36
+
37
+ # ...
38
+ end
39
+ ```
40
+
41
+ Remember the require!
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it ( https://github.com/tomasc/dragonfly-mongoid_data_store/fork )
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ t.pattern = 'test/**/*_test.rb'
7
+ end
8
+
9
+ task :default => :test
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dragonfly/mongoid_data_store/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dragonfly-mongoid_data_store"
8
+ spec.version = Dragonfly::MongoidDataStore::VERSION
9
+ spec.authors = ["Tomas Celizna"]
10
+ spec.email = ["tomas.celizna@gmail.com"]
11
+ spec.summary = %q{Dragonfly data store that uses Mongoid::GridFs.}
12
+ spec.description = %q{Dragonfly data store that uses Mongoid::GridFs.}
13
+ spec.homepage = "https://github.com/tomasc/dragonfly-mongoid_data_store"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "dragonfly", "~> 1.0"
22
+ spec.add_dependency "mongoid", "~> 4.0"
23
+ spec.add_dependency "mongoid-grid_fs", "~> 2.1"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.6"
26
+ spec.add_development_dependency "coveralls"
27
+ spec.add_development_dependency "database_cleaner"
28
+ spec.add_development_dependency "guard"
29
+ spec.add_development_dependency "guard-minitest"
30
+ spec.add_development_dependency "rake"
31
+ end
@@ -0,0 +1,58 @@
1
+ require 'dragonfly/mongoid_data_store/version'
2
+ require 'dragonfly'
3
+ require 'mongoid-grid_fs'
4
+
5
+ Dragonfly::App.register_datastore(:mongoid){ Dragonfly::MongoidDataStore }
6
+
7
+ module Dragonfly
8
+ class MongoidDataStore
9
+
10
+ class DataNotFound < StandardError; end
11
+
12
+ # ---------------------------------------------------------------------
13
+
14
+ include Serializer
15
+
16
+ # ---------------------------------------------------------------------
17
+
18
+ OBJECT_ID = BSON::ObjectId
19
+ INVALID_OBJECT_ID = Moped::Errors::InvalidObjectId
20
+
21
+ # =====================================================================
22
+
23
+ def write temp_object, opts={}
24
+ content_type = opts[:content_type] || opts[:mime_type] || 'application/octet-stream'
25
+ meta = temp_object.meta
26
+ meta = meta.merge(opts[:meta]) if opts[:meta].present?
27
+
28
+ temp_object.file do |f|
29
+ grid_file = Mongoid::GridFS.put(f, content_type: content_type, meta: marshal_b64_encode(meta))
30
+ grid_file.id
31
+ end
32
+ end
33
+
34
+ # ---------------------------------------------------------------------
35
+
36
+ def read uid
37
+ grid_file = Mongoid::GridFS.get(uid)
38
+
39
+ meta = {}
40
+ meta = marshal_b64_decode(grid_file.meta) if grid_file.respond_to?(:meta)
41
+ meta.merge!(stored_at: grid_file.upload_date) if grid_file.respond_to?(:upload_date)
42
+
43
+ [ grid_file.data, meta ]
44
+
45
+ rescue Mongoid::Errors::DocumentNotFound, INVALID_OBJECT_ID => e
46
+ raise DataNotFound, "#{e} - #{uid}"
47
+ end
48
+
49
+ # ---------------------------------------------------------------------
50
+
51
+ def destroy uid
52
+ Mongoid::GridFs.delete(uid)
53
+ end
54
+
55
+ # ---------------------------------------------------------------------
56
+
57
+ end
58
+ end
@@ -0,0 +1,5 @@
1
+ module Dragonfly
2
+ class MongoidDataStore
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,81 @@
1
+ require 'test_helper'
2
+ require 'dragonfly/mongoid_data_store'
3
+ require 'dragonfly/serializer'
4
+
5
+ describe Dragonfly::MongoidDataStore do
6
+
7
+ include Dragonfly::Serializer
8
+
9
+ # ---------------------------------------------------------------------
10
+
11
+ let(:app) { Dragonfly.app }
12
+ let(:content) { Dragonfly::Content.new(app, "Foo Bar!") }
13
+ let(:data_store) { Dragonfly::MongoidDataStore.new }
14
+ let(:meta) { { my_meta: 'my meta' } }
15
+
16
+ # ---------------------------------------------------------------------
17
+
18
+ describe '#write' do
19
+ it "stores the data in the database" do
20
+ uid = data_store.write(content)
21
+ response = Mongoid::GridFS.get(uid)
22
+ response.data.must_equal content.data
23
+ end
24
+
25
+ it 'stores default mime type' do
26
+ uid = data_store.write(content)
27
+ response = Mongoid::GridFS.get(uid)
28
+ response.content_type.must_equal 'application/octet-stream'
29
+ end
30
+
31
+ it 'stores supplied mime type' do
32
+ uid = data_store.write(content, content_type: 'text/plain')
33
+ response = Mongoid::GridFS.get(uid)
34
+ response.content_type.must_equal 'text/plain'
35
+ end
36
+
37
+ it 'stores additional meta data' do
38
+ uid = data_store.write(content, meta: meta)
39
+ response = Mongoid::GridFS.get(uid)
40
+ marshal_b64_decode(response.meta)[:my_meta].must_equal meta[:my_meta]
41
+ end
42
+ end
43
+
44
+ # ---------------------------------------------------------------------
45
+
46
+ describe '#read' do
47
+ before do
48
+ stored_content = Mongoid::GridFS.put(content.file, content_type: 'text/plain', meta: marshal_b64_encode(meta))
49
+ @result = data_store.read(stored_content.id)
50
+ end
51
+
52
+ it 'retrieves the file' do
53
+ @result.first.must_equal content.data
54
+ end
55
+
56
+ it 'retrieves meta data' do
57
+ @result.last.must_equal meta
58
+ end
59
+
60
+ it 'raises DataNotFound when file does not exist' do
61
+ proc { data_store.read(BSON::ObjectId.new) }.must_raise Dragonfly::MongoidDataStore::DataNotFound
62
+ end
63
+ end
64
+
65
+ # ---------------------------------------------------------------------
66
+
67
+ describe '#destroy' do
68
+ before do
69
+ @stored_content = Mongoid::GridFS.put(content.file)
70
+ end
71
+
72
+ it 'destroys data in the database' do
73
+ res = data_store.destroy(@stored_content.id)
74
+ res.must_equal true
75
+ Mongoid::GridFS.find(_id: @stored_content.id).must_be_nil
76
+ end
77
+ end
78
+
79
+ # ---------------------------------------------------------------------
80
+
81
+ end
@@ -0,0 +1,43 @@
1
+ require 'bundler/setup'
2
+ require 'minitest'
3
+ require 'minitest/autorun'
4
+ require 'minitest/spec'
5
+ require 'dragonfly/mongoid_data_store'
6
+ require 'rubygems'
7
+ require 'database_cleaner'
8
+
9
+ if ENV["CI"]
10
+ require "coveralls"
11
+ Coveralls.wear!
12
+ end
13
+
14
+ ENV["MONGOID_TEST_HOST"] ||= "localhost"
15
+ ENV["MONGOID_TEST_PORT"] ||= "27017"
16
+
17
+ HOST = ENV["MONGOID_TEST_HOST"]
18
+ PORT = ENV["MONGOID_TEST_PORT"].to_i
19
+
20
+ def database_id
21
+ "dragonfly-mongoid_data_store_test"
22
+ end
23
+
24
+ CONFIG = {
25
+ sessions: {
26
+ default: {
27
+ database: database_id,
28
+ hosts: [ "#{HOST}:#{PORT}" ]
29
+ }
30
+ }
31
+ }
32
+
33
+ Mongoid.configure do |config|
34
+ config.load_configuration(CONFIG)
35
+ end
36
+
37
+ DatabaseCleaner.orm = :mongoid
38
+ DatabaseCleaner.strategy = :truncation
39
+
40
+ class MiniTest::Spec
41
+ before(:each) { DatabaseCleaner.start }
42
+ after(:each) { DatabaseCleaner.clean }
43
+ end
metadata ADDED
@@ -0,0 +1,185 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dragonfly-mongoid_data_store
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tomas Celizna
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dragonfly
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mongoid
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mongoid-grid_fs
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: database_cleaner
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard-minitest
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Dragonfly data store that uses Mongoid::GridFs.
140
+ email:
141
+ - tomas.celizna@gmail.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".travis.yml"
148
+ - Gemfile
149
+ - Guardfile
150
+ - LICENSE
151
+ - LICENSE.txt
152
+ - README.md
153
+ - Rakefile
154
+ - dragonfly-mongoid_data_store.gemspec
155
+ - lib/dragonfly/mongoid_data_store.rb
156
+ - lib/dragonfly/mongoid_data_store/version.rb
157
+ - test/dragonfly/mongoid_data_store_test.rb
158
+ - test/test_helper.rb
159
+ homepage: https://github.com/tomasc/dragonfly-mongoid_data_store
160
+ licenses:
161
+ - MIT
162
+ metadata: {}
163
+ post_install_message:
164
+ rdoc_options: []
165
+ require_paths:
166
+ - lib
167
+ required_ruby_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ requirements: []
178
+ rubyforge_project:
179
+ rubygems_version: 2.2.2
180
+ signing_key:
181
+ specification_version: 4
182
+ summary: Dragonfly data store that uses Mongoid::GridFs.
183
+ test_files:
184
+ - test/dragonfly/mongoid_data_store_test.rb
185
+ - test/test_helper.rb