mfs 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.rvmrc +60 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +21 -0
- data/Rakefile +7 -0
- data/config/mongoid.yml +11 -0
- data/lib/mfs.rb +14 -0
- data/lib/mfs/entry.rb +19 -0
- data/lib/mfs/loader.rb +24 -0
- data/lib/mfs/version.rb +3 -0
- data/mfs.gemspec +26 -0
- data/spec/entry_spec.rb +34 -0
- data/spec/fixtures/files/file1 +1 -0
- data/spec/fixtures/files/file10 +0 -0
- data/spec/fixtures/files/file2 +0 -0
- data/spec/fixtures/files/file3 +0 -0
- data/spec/fixtures/files/file4 +0 -0
- data/spec/fixtures/files/file5 +0 -0
- data/spec/fixtures/files/file6 +0 -0
- data/spec/fixtures/files/file7 +0 -0
- data/spec/fixtures/files/file8 +0 -0
- data/spec/fixtures/files/file9 +0 -0
- data/spec/fixtures/files/sub/file11 +0 -0
- data/spec/loader_spec.rb +31 -0
- data/spec/mfs_spec.rb +7 -0
- data/spec/spec_helper.rb +25 -0
- metadata +145 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 204680b93d9f8916bc609dd0ab33fc8835a0dde3
|
4
|
+
data.tar.gz: ee56e500fdc2eabfb25a598b28800e7240cedfbc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2c8acd377e6d06c4507c514ba63b7920304e6fb31704189d89af33cbf6602d31aad244ee446371cf31c13a9cf12561b21ad4d44b09762743ebd8a854334c9c91
|
7
|
+
data.tar.gz: e1259fa3de32b196c3d2783f536534bce035ff69bde8304e7c16dbdafc0e3eb69f1681be04e3e4bbfd2597e63d9bf42814448602bcf58c7158129ba43069d62b
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
7
|
+
# Only full ruby name is supported here, for short names use:
|
8
|
+
# echo "rvm use 2.0.0" > .rvmrc
|
9
|
+
environment_id="ruby-2.0.0-p195@mfs"
|
10
|
+
|
11
|
+
# Uncomment the following lines if you want to verify rvm version per project
|
12
|
+
# rvmrc_rvm_version="1.20.13 (stable)" # 1.10.1 seams as a safe start
|
13
|
+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
14
|
+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
15
|
+
# return 1
|
16
|
+
# }
|
17
|
+
|
18
|
+
# First we attempt to load the desired environment directly from the environment
|
19
|
+
# file. This is very fast and efficient compared to running through the entire
|
20
|
+
# CLI and selector. If you want feedback on which environment was used then
|
21
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
22
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
23
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
24
|
+
then
|
25
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
26
|
+
for __hook in "${rvm_path:-$HOME/.rvm}/hooks/after_use"*
|
27
|
+
do
|
28
|
+
if [[ -f "${__hook}" && -x "${__hook}" && -s "${__hook}" ]]
|
29
|
+
then \. "${__hook}" || true
|
30
|
+
fi
|
31
|
+
done
|
32
|
+
unset __hook
|
33
|
+
if (( ${rvm_use_flag:=1} >= 2 )) # display only when forced
|
34
|
+
then
|
35
|
+
if [[ $- == *i* ]] # check for interactive shells
|
36
|
+
then printf "%b" "Using: \E[32m$GEM_HOME\E[0m" # show the user the ruby and gemset they are using in green
|
37
|
+
else printf "%b" "Using: $GEM_HOME" # don't use colors in non-interactive shells
|
38
|
+
fi
|
39
|
+
fi
|
40
|
+
else
|
41
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
42
|
+
rvm --create "$environment_id" || {
|
43
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
44
|
+
return 1
|
45
|
+
}
|
46
|
+
fi
|
47
|
+
|
48
|
+
# If you use bundler, this might be useful to you:
|
49
|
+
if [[ -s Gemfile ]] && {
|
50
|
+
! builtin command -v bundle >/dev/null ||
|
51
|
+
builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
|
52
|
+
}
|
53
|
+
then
|
54
|
+
printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
|
55
|
+
gem install bundler
|
56
|
+
fi
|
57
|
+
if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
|
58
|
+
then
|
59
|
+
bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
|
60
|
+
fi
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 e3 on barry.skarven.net
|
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,21 @@
|
|
1
|
+
Mongo File Store
|
2
|
+
================
|
3
|
+
|
4
|
+
Mongo File Store is a library for adding small files from the filesystem to MongoDB.
|
5
|
+
|
6
|
+
Status
|
7
|
+
------
|
8
|
+
[![Code Climate](https://codeclimate.com/github/SoftwareWithFriends/mfs.png)](https://codeclimate.com/github/SoftwareWithFriends/mfs)
|
9
|
+
[![Build Status](https://api.travis-ci.org/SoftwareWithFriends/mfs.png?branch=master)](https://travis-ci.org/SoftwareWithFriends/mfs)
|
10
|
+
|
11
|
+
Purpose
|
12
|
+
-------
|
13
|
+
* Shared Set of Files
|
14
|
+
* Attach Metadata to Files
|
15
|
+
* Retrieve Files based on metadata
|
16
|
+
|
17
|
+
Limitations
|
18
|
+
-----------
|
19
|
+
* No File Hierarchy
|
20
|
+
* Does not use GridFS (<16MB files only)
|
21
|
+
* Does not check for duplicate files
|
data/Rakefile
ADDED
data/config/mongoid.yml
ADDED
data/lib/mfs.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'mongoid'
|
3
|
+
|
4
|
+
require "mfs/version"
|
5
|
+
require "mfs/loader"
|
6
|
+
require "mfs/entry"
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
module Mfs
|
11
|
+
ROOT_DIR = "#{__dir__}/.."
|
12
|
+
ENV["MONGOID_ENV"] ||= 'development'
|
13
|
+
Mongoid.load!("#{ROOT_DIR}/config/mongoid.yml")
|
14
|
+
end
|
data/lib/mfs/entry.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Mfs
|
2
|
+
class Entry
|
3
|
+
include Mongoid::Document
|
4
|
+
include Mongoid::Timestamps
|
5
|
+
|
6
|
+
field :data
|
7
|
+
field :filename, type: String
|
8
|
+
field :filepath
|
9
|
+
|
10
|
+
validates_presence_of :filename
|
11
|
+
before_create :calculate_metadata
|
12
|
+
|
13
|
+
def calculate_metadata
|
14
|
+
self.filepath = File.realdirpath(filename)
|
15
|
+
self.filename = File.basename(filename)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
data/lib/mfs/loader.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module Mfs
|
2
|
+
module Loader
|
3
|
+
|
4
|
+
def self.load_directory(path)
|
5
|
+
Dir.glob("#{path}/**/*").map do |file|
|
6
|
+
unless File.directory?(file)
|
7
|
+
additional_metadata = block_given? ? yield(file) : {}
|
8
|
+
load_file(file, additional_metadata)
|
9
|
+
end
|
10
|
+
end.compact!
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.load_file(filename, additional_metadata = {})
|
14
|
+
|
15
|
+
Entry.create(
|
16
|
+
additional_metadata.merge(
|
17
|
+
data: File.read(filename),
|
18
|
+
filename: filename
|
19
|
+
)
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
data/lib/mfs/version.rb
ADDED
data/mfs.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mfs/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mfs"
|
8
|
+
spec.version = Mfs::VERSION
|
9
|
+
spec.authors = ["Tim Johson", "Eric Liu"]
|
10
|
+
spec.email = ["github@chubtoad.com"]
|
11
|
+
spec.description = %q{MongoFileStore lets you load files into mongo and attach metadata.}
|
12
|
+
spec.summary = %q{MongoFileStore stores files in mongo.}
|
13
|
+
spec.homepage = "https://github.com/SoftwareWithFriends/mfs"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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 "mongoid", "~> 3.1.0"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
end
|
data/spec/entry_spec.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Mfs
|
4
|
+
describe Entry do
|
5
|
+
|
6
|
+
describe "needs a filename" do
|
7
|
+
before do
|
8
|
+
@entry = Entry.new
|
9
|
+
end
|
10
|
+
|
11
|
+
subject {@entry}
|
12
|
+
|
13
|
+
it { should_not be_valid}
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "has proper fields" do
|
17
|
+
before do
|
18
|
+
@entry = Entry.create(
|
19
|
+
data: "HarderBetterFasterStronger",
|
20
|
+
filename: "spec/fixtures/file1",
|
21
|
+
filepath: "spec/fixtures"
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
subject { @entry }
|
26
|
+
|
27
|
+
it {should be_valid}
|
28
|
+
its(:data) { should eq "HarderBetterFasterStronger" }
|
29
|
+
its(:filename) { should eq "file1" }
|
30
|
+
its(:filepath) { should match "spec/fixtures" }
|
31
|
+
its(:created_at) { should be }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
This is File One
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/spec/loader_spec.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Mfs
|
4
|
+
|
5
|
+
describe Loader do
|
6
|
+
|
7
|
+
describe "can load files from directory" do
|
8
|
+
before do
|
9
|
+
@files = Loader.load_directory('spec/fixtures/files') do |filename|
|
10
|
+
{additional_field: filename}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
subject { @files }
|
14
|
+
its(:size) { should eq 11 }
|
15
|
+
|
16
|
+
specify "they should all have additional_field" do
|
17
|
+
@files.reject { |file| file.additional_field.match /#{file.filename}/ }.should be_empty
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "can load file" do
|
23
|
+
before do
|
24
|
+
@file = Loader.load_file('spec/fixtures/files/file1')
|
25
|
+
end
|
26
|
+
subject { @file }
|
27
|
+
its(:data) { should eq 'This is File One' }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
data/spec/mfs_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
config.order = 'random'
|
17
|
+
|
18
|
+
config.before :each do
|
19
|
+
Mongoid::Sessions.default.collections.select {|c| c.name !~ /system/ }.each(&:drop)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
ENV["MONGOID_ENV"] = 'test'
|
24
|
+
|
25
|
+
require 'mfs'
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mfs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tim Johson
|
8
|
+
- Eric Liu
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: mongoid
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 3.1.0
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 3.1.0
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: bundler
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1.3'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.3'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rake
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rspec
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
description: MongoFileStore lets you load files into mongo and attach metadata.
|
71
|
+
email:
|
72
|
+
- github@chubtoad.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- .gitignore
|
78
|
+
- .rspec
|
79
|
+
- .rvmrc
|
80
|
+
- .travis.yml
|
81
|
+
- Gemfile
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- config/mongoid.yml
|
86
|
+
- lib/mfs.rb
|
87
|
+
- lib/mfs/entry.rb
|
88
|
+
- lib/mfs/loader.rb
|
89
|
+
- lib/mfs/version.rb
|
90
|
+
- mfs.gemspec
|
91
|
+
- spec/entry_spec.rb
|
92
|
+
- spec/fixtures/files/file1
|
93
|
+
- spec/fixtures/files/file10
|
94
|
+
- spec/fixtures/files/file2
|
95
|
+
- spec/fixtures/files/file3
|
96
|
+
- spec/fixtures/files/file4
|
97
|
+
- spec/fixtures/files/file5
|
98
|
+
- spec/fixtures/files/file6
|
99
|
+
- spec/fixtures/files/file7
|
100
|
+
- spec/fixtures/files/file8
|
101
|
+
- spec/fixtures/files/file9
|
102
|
+
- spec/fixtures/files/sub/file11
|
103
|
+
- spec/loader_spec.rb
|
104
|
+
- spec/mfs_spec.rb
|
105
|
+
- spec/spec_helper.rb
|
106
|
+
homepage: https://github.com/SoftwareWithFriends/mfs
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
metadata: {}
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - '>='
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 2.0.3
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
129
|
+
summary: MongoFileStore stores files in mongo.
|
130
|
+
test_files:
|
131
|
+
- spec/entry_spec.rb
|
132
|
+
- spec/fixtures/files/file1
|
133
|
+
- spec/fixtures/files/file10
|
134
|
+
- spec/fixtures/files/file2
|
135
|
+
- spec/fixtures/files/file3
|
136
|
+
- spec/fixtures/files/file4
|
137
|
+
- spec/fixtures/files/file5
|
138
|
+
- spec/fixtures/files/file6
|
139
|
+
- spec/fixtures/files/file7
|
140
|
+
- spec/fixtures/files/file8
|
141
|
+
- spec/fixtures/files/file9
|
142
|
+
- spec/fixtures/files/sub/file11
|
143
|
+
- spec/loader_spec.rb
|
144
|
+
- spec/mfs_spec.rb
|
145
|
+
- spec/spec_helper.rb
|