mfs 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -4
- data/lib/mfs.rb +2 -2
- data/lib/mfs/can_be_created_from_files.rb +24 -0
- data/lib/mfs/entry.rb +2 -0
- data/lib/mfs/types/certificate.rb +17 -0
- data/lib/mfs/version.rb +1 -1
- data/spec/can_be_created_from_files_spec.rb +50 -0
- data/spec/entry_spec.rb +7 -4
- data/spec/integration_spec.rb +1 -1
- data/spec/types/certificate_spec.rb +16 -0
- metadata +7 -4
- data/lib/mfs/loader.rb +0 -24
- data/spec/loader_spec.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dcea98d53fb089d933a1eae596871bdac6c4b6ba
|
4
|
+
data.tar.gz: eb34cc820cf860ee89868c4259ddf6c0d2d8de6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a1594cff6da3ae6b2d441f26615de65217f4d295cd2bee50654211e6dbaa45fe6a9b653fb99f7db52d03b7d58cfa1af00d9530523e035b9e3338889b2416091
|
7
|
+
data.tar.gz: 17912fa43733acb15db6920cdf2f538385c6f8e070f03bfa8857f372178f6b44136dfc9af78c4dd0adf2210e70f865fb798d0263dc2c683284b5bc4610fd62b3
|
data/README.md
CHANGED
@@ -24,26 +24,29 @@ Usage
|
|
24
24
|
-----
|
25
25
|
```ruby
|
26
26
|
require 'mfs'
|
27
|
-
entry = Mfs::
|
27
|
+
entry = Mfs::Entry.load_file('path/to/file')
|
28
28
|
entry.filepath
|
29
29
|
entry.filename
|
30
30
|
entry.created_at
|
31
31
|
entry.data
|
32
32
|
|
33
33
|
# Set arbitrary Meta-data fields
|
34
|
-
Mfs::
|
34
|
+
Mfs::Entry.load_file('path/to/file',test_field: true)
|
35
35
|
entry = Mfs::Entry.where(test_field: true).first
|
36
36
|
|
37
37
|
# Load all files in a directory structure
|
38
|
-
entries = Mfs::
|
38
|
+
entries = Mfs::Entry.load_directory('path/to/files')
|
39
39
|
|
40
40
|
# Load all files and set meta-data
|
41
|
-
entries = Mfs::
|
41
|
+
entries = Mfs::Entry.load_directory('path/to/files') do |filename|
|
42
42
|
{has_a: filename.include('a')}
|
43
43
|
end
|
44
44
|
|
45
45
|
```
|
46
46
|
|
47
|
+
Create your own file types.
|
48
|
+
As an example see [Mfs::Types::Certificate](lib/types/certificate.rb) and its [Spec](spec/types/certificate_spec.rb)
|
49
|
+
|
47
50
|
Limitations
|
48
51
|
-----------
|
49
52
|
* No File Hierarchy
|
data/lib/mfs.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
module Mfs
|
2
|
+
module CanBeCreatedFromFiles
|
3
|
+
|
4
|
+
def load_directory(path)
|
5
|
+
Dir.glob("#{path}/**/*").map do |file|
|
6
|
+
next if File.directory?(file)
|
7
|
+
|
8
|
+
additional_metadata = block_given? ? yield(file) : {}
|
9
|
+
|
10
|
+
load_file(file, additional_metadata)
|
11
|
+
end.compact
|
12
|
+
end
|
13
|
+
|
14
|
+
def load_file(filename, additional_metadata = {})
|
15
|
+
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/entry.rb
CHANGED
@@ -2,10 +2,12 @@ module Mfs
|
|
2
2
|
class Entry
|
3
3
|
include Mongoid::Document
|
4
4
|
include Mongoid::Timestamps
|
5
|
+
extend CanBeCreatedFromFiles
|
5
6
|
|
6
7
|
field :data
|
7
8
|
field :filename, type: String
|
8
9
|
field :filepath
|
10
|
+
field :filetype
|
9
11
|
|
10
12
|
validates_presence_of :filename
|
11
13
|
before_create :calculate_metadata
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Mfs
|
2
|
+
module Types
|
3
|
+
class Certificate < Entry
|
4
|
+
field :filetype, default: "certificate"
|
5
|
+
|
6
|
+
|
7
|
+
def certificate
|
8
|
+
@certificate ||= OpenSSL::X509::Certificate.new data
|
9
|
+
end
|
10
|
+
|
11
|
+
def dn
|
12
|
+
certificate.subject.to_s
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/mfs/version.rb
CHANGED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Mfs
|
4
|
+
|
5
|
+
describe CanBeCreatedFromFiles do
|
6
|
+
|
7
|
+
class FileHolder
|
8
|
+
extend CanBeCreatedFromFiles
|
9
|
+
|
10
|
+
attr_reader :hash
|
11
|
+
|
12
|
+
def self.create(params)
|
13
|
+
new(params)
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(initialization_hash)
|
17
|
+
@hash = initialization_hash
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
describe "can load files from directory" do
|
24
|
+
before do
|
25
|
+
@file_holders = FileHolder.load_directory('spec/fixtures/files') do |filename|
|
26
|
+
{additional_field: filename}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
subject { @file_holders }
|
30
|
+
its(:size) { should eq 11 }
|
31
|
+
|
32
|
+
specify "they should all have additional_field" do
|
33
|
+
@file_holders.reject { |file| file.hash[:additional_field].match /#{file.hash[:filename]}/ }.should be_empty
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "can load file" do
|
39
|
+
before do
|
40
|
+
@file_holder = FileHolder.load_file('spec/fixtures/files/file1')
|
41
|
+
end
|
42
|
+
subject { @file_holder }
|
43
|
+
its(:hash) { should have_key :data }
|
44
|
+
it "should have file contents" do
|
45
|
+
@file_holder.hash[:data].should eq 'This is File One'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
data/spec/entry_spec.rb
CHANGED
@@ -8,9 +8,9 @@ module Mfs
|
|
8
8
|
@entry = Entry.new
|
9
9
|
end
|
10
10
|
|
11
|
-
subject {@entry}
|
11
|
+
subject { @entry }
|
12
12
|
|
13
|
-
it { should_not be_valid}
|
13
|
+
it { should_not be_valid }
|
14
14
|
end
|
15
15
|
|
16
16
|
describe "has proper fields" do
|
@@ -18,17 +18,20 @@ module Mfs
|
|
18
18
|
@entry = Entry.create(
|
19
19
|
data: "HarderBetterFasterStronger",
|
20
20
|
filename: "spec/fixtures/file1",
|
21
|
-
filepath: "spec/fixtures"
|
21
|
+
filepath: "spec/fixtures",
|
22
|
+
filetype: "fake"
|
22
23
|
)
|
23
24
|
end
|
24
25
|
|
25
26
|
subject { @entry }
|
26
27
|
|
27
|
-
it {should be_valid}
|
28
|
+
it { should be_valid }
|
28
29
|
its(:data) { should eq "HarderBetterFasterStronger" }
|
29
30
|
its(:filename) { should eq "file1" }
|
30
31
|
its(:filepath) { should match "spec/fixtures" }
|
32
|
+
its(:filetype) { should eq "fake"}
|
31
33
|
its(:created_at) { should be }
|
32
34
|
end
|
35
|
+
|
33
36
|
end
|
34
37
|
end
|
data/spec/integration_spec.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Mfs
|
3
|
+
module Types
|
4
|
+
|
5
|
+
describe Certificate do
|
6
|
+
describe "has correct filetype" do
|
7
|
+
before do
|
8
|
+
@certificate = Certificate.load_file("spec/fixtures/test.pem")
|
9
|
+
end
|
10
|
+
subject { @certificate}
|
11
|
+
its(:filetype) {should eq "certificate"}
|
12
|
+
its(:dn) { should eq "/C=US/ST=NJ/O=SoftwareWithFriends/CN=Tim"}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mfs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Johson
|
@@ -84,10 +84,12 @@ files:
|
|
84
84
|
- Rakefile
|
85
85
|
- config/mongoid.yml
|
86
86
|
- lib/mfs.rb
|
87
|
+
- lib/mfs/can_be_created_from_files.rb
|
87
88
|
- lib/mfs/entry.rb
|
88
|
-
- lib/mfs/
|
89
|
+
- lib/mfs/types/certificate.rb
|
89
90
|
- lib/mfs/version.rb
|
90
91
|
- mfs.gemspec
|
92
|
+
- spec/can_be_created_from_files_spec.rb
|
91
93
|
- spec/entry_spec.rb
|
92
94
|
- spec/fixtures/files/file1
|
93
95
|
- spec/fixtures/files/file10
|
@@ -101,9 +103,9 @@ files:
|
|
101
103
|
- spec/fixtures/files/file9
|
102
104
|
- spec/fixtures/files/sub/file11
|
103
105
|
- spec/integration_spec.rb
|
104
|
-
- spec/loader_spec.rb
|
105
106
|
- spec/mfs_spec.rb
|
106
107
|
- spec/spec_helper.rb
|
108
|
+
- spec/types/certificate_spec.rb
|
107
109
|
homepage: https://github.com/SoftwareWithFriends/mfs
|
108
110
|
licenses:
|
109
111
|
- MIT
|
@@ -129,6 +131,7 @@ signing_key:
|
|
129
131
|
specification_version: 4
|
130
132
|
summary: MongoFileStore stores files in mongo.
|
131
133
|
test_files:
|
134
|
+
- spec/can_be_created_from_files_spec.rb
|
132
135
|
- spec/entry_spec.rb
|
133
136
|
- spec/fixtures/files/file1
|
134
137
|
- spec/fixtures/files/file10
|
@@ -142,6 +145,6 @@ test_files:
|
|
142
145
|
- spec/fixtures/files/file9
|
143
146
|
- spec/fixtures/files/sub/file11
|
144
147
|
- spec/integration_spec.rb
|
145
|
-
- spec/loader_spec.rb
|
146
148
|
- spec/mfs_spec.rb
|
147
149
|
- spec/spec_helper.rb
|
150
|
+
- spec/types/certificate_spec.rb
|
data/lib/mfs/loader.rb
DELETED
@@ -1,24 +0,0 @@
|
|
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/spec/loader_spec.rb
DELETED
@@ -1,31 +0,0 @@
|
|
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
|