ramdo 0.1.5 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/.gitlab-ci.yml +21 -0
- data/lib/ramdo/cleaner.rb +15 -0
- data/lib/ramdo/exceptions.rb +5 -0
- data/lib/ramdo/ramdisk/darwin_wrapper.rb +1 -1
- data/lib/ramdo/ramdisk/factory.rb +1 -1
- data/lib/ramdo/ramdisk/generic_wrapper.rb +41 -0
- data/lib/ramdo/ramdisk/instance.rb +5 -5
- data/lib/ramdo/ramdisk/linux_wrapper.rb +3 -5
- data/lib/ramdo/store.rb +19 -8
- data/lib/ramdo/version.rb +1 -1
- data/lib/ramdo.rb +8 -2
- data/ramdo.gemspec +1 -0
- data/spec/cleaner_spec.rb +17 -0
- data/spec/darwin_wrapper_spec.rb +67 -0
- data/spec/generic_wrapper_spec.rb +62 -0
- data/spec/linux_wrapper_spec.rb +67 -0
- data/spec/ramdisk_factory_spec.rb +6 -55
- data/spec/spec_helper.rb +6 -1
- data/spec/store_spec.rb +11 -1
- metadata +28 -4
- data/Gemfile.lock +0 -76
- data/lib/ramdo/ramdisk/exceptions.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 439c86b3e38f8b1f40e9669235ce8cfdac5cbf75
|
4
|
+
data.tar.gz: 4276f58ea837d01171f2444d65f4974d7c9f2c64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1e42d45451100eb6f3f85ea1f8d3f97cb79b49f7f24fdf3516314ef32f6a00aaaae2b5bc91f501bbba118ccd5a7d2ab2d06fff3eddd1c6fc1daaa30103adb7f
|
7
|
+
data.tar.gz: 0aa2463d9946781fdcb147acb5e4e45f8a40983b2309216765ad94dfae5347a395bb81c66c57751305d4107743f8b176ac225b12d0189948fb3e5722582679b3
|
data/.gitignore
CHANGED
@@ -13,6 +13,7 @@
|
|
13
13
|
/test/tmp/
|
14
14
|
/test/version_tmp/
|
15
15
|
/tmp/
|
16
|
+
Gemfile.lock
|
16
17
|
|
17
18
|
# Used by dotenv library to load environment variables.
|
18
19
|
# .env
|
@@ -93,4 +94,4 @@ Temporary Items
|
|
93
94
|
.directory
|
94
95
|
|
95
96
|
# Linux trash folder which might appear on any partition or disk
|
96
|
-
.Trash-*
|
97
|
+
.Trash-*
|
data/.gitlab-ci.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
before_script:
|
2
|
+
- ruby -v
|
3
|
+
- which ruby
|
4
|
+
- gem install bundler --no-ri --no-rdoc
|
5
|
+
- bundle install --jobs $(nproc) "${FLAGS[@]}"
|
6
|
+
|
7
|
+
stages:
|
8
|
+
- test
|
9
|
+
- deploy
|
10
|
+
|
11
|
+
|
12
|
+
rspec_job:
|
13
|
+
stage: test
|
14
|
+
script:
|
15
|
+
- bundle exec rspec
|
16
|
+
|
17
|
+
deploy_job:
|
18
|
+
stage: deploy
|
19
|
+
script:
|
20
|
+
- bundle exec rake build
|
21
|
+
- bundle exec gem inabox -g https://gems.aisler.net
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Ramdo
|
2
|
+
class Cleaner
|
3
|
+
def self.clean_up(disk)
|
4
|
+
Dir.entries(disk.path).each do |dir|
|
5
|
+
if dir =~ Store::NAME_PATTERN
|
6
|
+
uuid = Regexp.last_match[1]
|
7
|
+
timestamp = Regexp.last_match[2].to_i
|
8
|
+
if (timestamp + DEFAULTS[:ttl]) < Time.now.utc.to_i
|
9
|
+
FileUtils.rm_r File.join(disk.path, dir), :force => true
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Ramdo
|
2
|
+
module Ramdisk
|
3
|
+
class GenericWrapper
|
4
|
+
def initialize
|
5
|
+
@tmp_path = '/tmp'
|
6
|
+
raise GeneralRamdiskException.new("tmp path not found") unless @tmp_path && Dir.exist?(@tmp_path)
|
7
|
+
end
|
8
|
+
|
9
|
+
def list
|
10
|
+
disks = []
|
11
|
+
Dir.glob(@tmp_path + '/*').each do |dir|
|
12
|
+
if dir.split(File::SEPARATOR).last =~ Instance::NAME_PATTERN
|
13
|
+
disks << Instance.new(self, path: dir, device: @tmp_path, size: Filesize.from("1 GB"))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
disks
|
18
|
+
end
|
19
|
+
|
20
|
+
def create(size)
|
21
|
+
# Create new directory as dedicated space
|
22
|
+
path = [@tmp_path, Instance.generate_name].join('/')
|
23
|
+
Dir.mkdir(path)
|
24
|
+
|
25
|
+
# Receive all disk and select just created one
|
26
|
+
list().select { |disk| disk.path == path }.first
|
27
|
+
end
|
28
|
+
|
29
|
+
def destroy(instance)
|
30
|
+
return false unless Dir.exist? instance.path
|
31
|
+
FileUtils.rm_r instance.path, :force => true
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def enough_ram?(size)
|
36
|
+
# As the generic wrapper does not use RAM always return true
|
37
|
+
true
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -1,23 +1,23 @@
|
|
1
1
|
module Ramdo
|
2
2
|
module Ramdisk
|
3
3
|
class Instance
|
4
|
-
NAME_PATTERN =
|
4
|
+
NAME_PATTERN = /^ramdo_disk_([a-z0-9]+)$/
|
5
5
|
|
6
6
|
def self.generate_name
|
7
|
-
"
|
7
|
+
"ramdo_disk_#{SecureRandom.hex(4)}"
|
8
8
|
end
|
9
9
|
|
10
10
|
attr_accessor :device, :path, :size
|
11
11
|
|
12
|
-
def initialize(info = {})
|
12
|
+
def initialize(wrapper, info = {})
|
13
|
+
@wrapper = wrapper
|
13
14
|
@device = info[:device]
|
14
15
|
@path = info[:path]
|
15
16
|
@size = info[:size]
|
16
17
|
end
|
17
18
|
|
18
19
|
def destroy!
|
19
|
-
wrapper
|
20
|
-
wrapper.destroy self
|
20
|
+
@wrapper.destroy self
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -12,8 +12,8 @@ module Ramdo
|
|
12
12
|
def list
|
13
13
|
disks = []
|
14
14
|
Dir.glob(@shm_path + '/*').each do |dir|
|
15
|
-
if dir =~ Instance::NAME_PATTERN
|
16
|
-
disks << Instance.new(path: dir, device: @shm_path, size: Filesize.from("1 GB"))
|
15
|
+
if dir.split(File::SEPARATOR).last =~ Instance::NAME_PATTERN
|
16
|
+
disks << Instance.new(self, path: dir, device: @shm_path, size: Filesize.from("1 GB"))
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -34,9 +34,7 @@ module Ramdo
|
|
34
34
|
|
35
35
|
def destroy(instance)
|
36
36
|
return false unless File.exist? instance.path
|
37
|
-
|
38
|
-
Dir.glob(instance.path + "/*").each { |file| File.delete(file) if File.file? file }
|
39
|
-
Dir.rmdir(instance.path)
|
37
|
+
FileUtils.rm_r instance.path, :force => true
|
40
38
|
end
|
41
39
|
|
42
40
|
private
|
data/lib/ramdo/store.rb
CHANGED
@@ -1,22 +1,32 @@
|
|
1
1
|
module Ramdo
|
2
2
|
class Store
|
3
|
-
|
3
|
+
NAME_PATTERN = /^ramdo_([a-z0-9]+)_([0-9]+)$/
|
4
|
+
|
5
|
+
attr_reader :file, :dir
|
4
6
|
|
5
7
|
def initialize(opts = {})
|
6
8
|
wrapper = Ramdisk::Factory.get
|
7
9
|
list = wrapper.list
|
10
|
+
disk = nil
|
8
11
|
if list.length <= 0
|
9
12
|
# Create a new Ramdisk
|
10
|
-
|
13
|
+
disk = wrapper.create(DEFAULTS[:disk_size])
|
11
14
|
else
|
12
15
|
# Use one which is large enough
|
13
|
-
list.each { |
|
14
|
-
|
16
|
+
list.each { |d| disk = d if d.size >= Filesize.from(DEFAULTS[:disk_size]) }
|
17
|
+
disk = wrapper.create(DEFAULTS[:disk_size]) if disk.nil?
|
15
18
|
end
|
16
19
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
+
# Every time a new store is created we check if any other store is out of date
|
21
|
+
Cleaner.clean_up(disk)
|
22
|
+
|
23
|
+
ext = opts[:extension] ? opts[:extension].sub('.', '') : 'bin'
|
24
|
+
uuid = SecureRandom.hex(4)
|
25
|
+
timestamp = Time.now.utc.to_i
|
26
|
+
@dir = File.join(disk.path, "ramdo_#{uuid}_#{timestamp}")
|
27
|
+
@file = File.join(@dir, "store.#{ext}")
|
28
|
+
|
29
|
+
Dir.mkdir(@dir)
|
20
30
|
end
|
21
31
|
|
22
32
|
def data=(data)
|
@@ -28,7 +38,8 @@ module Ramdo
|
|
28
38
|
end
|
29
39
|
|
30
40
|
def truncate
|
31
|
-
|
41
|
+
return if @dir.empty? || @dir == File::SEPARATOR # Safety net
|
42
|
+
FileUtils.rm_r @dir, :force => true
|
32
43
|
end
|
33
44
|
end
|
34
45
|
end
|
data/lib/ramdo/version.rb
CHANGED
data/lib/ramdo.rb
CHANGED
@@ -2,15 +2,21 @@ require 'cocaine'
|
|
2
2
|
require 'pp'
|
3
3
|
require 'filesize'
|
4
4
|
require 'securerandom'
|
5
|
+
require 'fileutils'
|
5
6
|
|
6
7
|
require 'ramdo/version'
|
7
|
-
require 'ramdo/
|
8
|
+
require 'ramdo/exceptions'
|
8
9
|
require 'ramdo/ramdisk/factory'
|
9
10
|
require 'ramdo/ramdisk/instance'
|
10
11
|
require 'ramdo/ramdisk/darwin_wrapper'
|
11
12
|
require 'ramdo/ramdisk/linux_wrapper'
|
13
|
+
require 'ramdo/ramdisk/generic_wrapper'
|
12
14
|
require 'ramdo/store'
|
15
|
+
require 'ramdo/cleaner'
|
13
16
|
|
14
17
|
module Ramdo
|
15
|
-
|
18
|
+
DEFAULTS = {
|
19
|
+
disk_size: '100mb',
|
20
|
+
ttl: 120 # In seconds
|
21
|
+
}
|
16
22
|
end
|
data/ramdo.gemspec
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include Ramdo
|
4
|
+
describe Cleaner do
|
5
|
+
it 'should clean up all stores' do
|
6
|
+
stores = []
|
7
|
+
10.times { stores << Store.new }
|
8
|
+
|
9
|
+
Timecop.freeze(Time.local(2100)) do
|
10
|
+
stores.each { |store| expect(Dir.exist?(store.dir)).to be_truthy }
|
11
|
+
|
12
|
+
new_store = Store.new
|
13
|
+
stores.each { |store| expect(Dir.exist?(store.dir)).to be_falsey }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include Ramdo
|
4
|
+
describe Ramdisk::DarwinWrapper, if: os?(/darwin/) do
|
5
|
+
before(:each) do
|
6
|
+
wrapper = Ramdisk::DarwinWrapper.new
|
7
|
+
wrapper.list.each do |disk|
|
8
|
+
disk.destroy!
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
it 'should check if a ramdisk already exists' do
|
14
|
+
wrapper = Ramdisk::DarwinWrapper.new
|
15
|
+
disks = wrapper.list
|
16
|
+
expect(disks).to be_an(Array)
|
17
|
+
expect(disks.length).to be_a(Integer)
|
18
|
+
expect(disks.length).to be(0)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should check if enough RAM space is free' do
|
22
|
+
wrapper = Ramdisk::DarwinWrapper.new
|
23
|
+
expect(wrapper.send(:enough_ram?, '100 MB')).to be_truthy
|
24
|
+
expect(wrapper.send(:enough_ram?, '100 GB')).to be_falsey
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should create a new RAM disk and save a file to it' do
|
28
|
+
size = '100 MB'
|
29
|
+
|
30
|
+
wrapper = Ramdisk::DarwinWrapper.new
|
31
|
+
disk = wrapper.create(size)
|
32
|
+
|
33
|
+
expect(disk).to be_an(Ramdisk::Instance)
|
34
|
+
expect { IO.write("#{disk.path}/test.bin", IO.read('/dev/urandom', 100000)) }.not_to raise_error
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should remove a RAM disk' do
|
38
|
+
wrapper = Ramdisk::DarwinWrapper.new
|
39
|
+
disk = wrapper.create('100 MB')
|
40
|
+
|
41
|
+
count = wrapper.list.length
|
42
|
+
expect(disk.destroy!).to be_truthy
|
43
|
+
expect(disk.destroy!).to be_falsey # Should not work another time
|
44
|
+
|
45
|
+
expect(wrapper.list.length).to be(count - 1)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should list all available RAM disks' do
|
49
|
+
wrapper = Ramdisk::DarwinWrapper.new
|
50
|
+
disk = wrapper.create('100 MB')
|
51
|
+
|
52
|
+
list = wrapper.list
|
53
|
+
expect(list.length).to eq(1)
|
54
|
+
expect(list.first.device).not_to be_empty
|
55
|
+
expect(File.exist?(list.first.device)).to be_truthy
|
56
|
+
expect(Dir.exist?(list.first.path)).to be_truthy
|
57
|
+
|
58
|
+
disk = wrapper.create('200 MB')
|
59
|
+
|
60
|
+
list = wrapper.list
|
61
|
+
expect(list.length).to eq(2)
|
62
|
+
expect(list.last.device).not_to be_empty
|
63
|
+
expect(File.exist?(list.last.device)).to be_truthy
|
64
|
+
expect(Dir.exist?(list.last.path)).to be_truthy
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include Ramdo
|
4
|
+
describe Ramdisk::GenericWrapper, focus: true do
|
5
|
+
before(:each) do
|
6
|
+
wrapper = Ramdisk::GenericWrapper.new
|
7
|
+
wrapper.list.each do |disk|
|
8
|
+
disk.destroy!
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
it 'should check if a ramdisk already exists' do
|
14
|
+
wrapper = Ramdisk::GenericWrapper.new
|
15
|
+
disks = wrapper.list
|
16
|
+
expect(disks).to be_an(Array)
|
17
|
+
expect(disks.length).to be_a(Integer)
|
18
|
+
expect(disks.length).to be(0)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should create a new disk and save a file to it' do
|
22
|
+
size = '100 MB'
|
23
|
+
|
24
|
+
wrapper = Ramdisk::GenericWrapper.new
|
25
|
+
disk = wrapper.create(size)
|
26
|
+
|
27
|
+
expect(disk).to be_an(Ramdisk::Instance)
|
28
|
+
expect { IO.write("#{disk.path}/test.bin", IO.read('/dev/urandom', 100000)) }.not_to raise_error
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should remove a RAM disk' do
|
32
|
+
wrapper = Ramdisk::GenericWrapper.new
|
33
|
+
disk = wrapper.create('100 MB')
|
34
|
+
|
35
|
+
count = wrapper.list.length
|
36
|
+
expect(disk.destroy!).to be_truthy
|
37
|
+
expect(disk.destroy!).to be_falsey # Should not work another time
|
38
|
+
|
39
|
+
expect(wrapper.list.length).to be(count - 1)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should list all available RAM disks' do
|
43
|
+
wrapper = Ramdisk::GenericWrapper.new
|
44
|
+
disk = wrapper.create('100 MB')
|
45
|
+
|
46
|
+
list = wrapper.list
|
47
|
+
expect(list.length).to eq(1)
|
48
|
+
expect(list.first.device).not_to be_empty
|
49
|
+
expect(File.exist?(list.first.device)).to be_truthy
|
50
|
+
expect(Dir.exist?(list.first.path)).to be_truthy
|
51
|
+
|
52
|
+
disk = wrapper.create('200 MB')
|
53
|
+
|
54
|
+
list = wrapper.list
|
55
|
+
expect(list.length).to eq(2)
|
56
|
+
expect(list.last.device).not_to be_empty
|
57
|
+
expect(File.exist?(list.last.device)).to be_truthy
|
58
|
+
expect(Dir.exist?(list.last.path)).to be_truthy
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include Ramdo
|
4
|
+
describe Ramdisk::LinuxWrapper, if: os?(/linux/) do
|
5
|
+
before(:each) do
|
6
|
+
wrapper = Ramdisk::LinuxWrapper.new
|
7
|
+
wrapper.list.each do |disk|
|
8
|
+
disk.destroy!
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
it 'should check if a ramdisk already exists' do
|
14
|
+
wrapper = Ramdisk::LinuxWrapper.new
|
15
|
+
disks = wrapper.list
|
16
|
+
expect(disks).to be_an(Array)
|
17
|
+
expect(disks.length).to be_a(Integer)
|
18
|
+
expect(disks.length).to be(0)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should check if enough RAM space is free' do
|
22
|
+
wrapper = Ramdisk::LinuxWrapper.new
|
23
|
+
expect(wrapper.send(:enough_ram?, '100 MB')).to be_truthy
|
24
|
+
expect(wrapper.send(:enough_ram?, '100 GB')).to be_falsey
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should create a new RAM disk and save a file to it' do
|
28
|
+
size = '100 MB'
|
29
|
+
|
30
|
+
wrapper = Ramdisk::LinuxWrapper.new
|
31
|
+
disk = wrapper.create(size)
|
32
|
+
|
33
|
+
expect(disk).to be_an(Ramdisk::Instance)
|
34
|
+
expect { IO.write("#{disk.path}/test.bin", IO.read('/dev/urandom', 100000)) }.not_to raise_error
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should remove a RAM disk' do
|
38
|
+
wrapper = Ramdisk::LinuxWrapper.new
|
39
|
+
disk = wrapper.create('100 MB')
|
40
|
+
|
41
|
+
count = wrapper.list.length
|
42
|
+
expect(disk.destroy!).to be_truthy
|
43
|
+
expect(disk.destroy!).to be_falsey # Should not work another time
|
44
|
+
|
45
|
+
expect(wrapper.list.length).to be(count - 1)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should list all available RAM disks' do
|
49
|
+
wrapper = Ramdisk::LinuxWrapper.new
|
50
|
+
disk = wrapper.create('100 MB')
|
51
|
+
|
52
|
+
list = wrapper.list
|
53
|
+
expect(list.length).to eq(1)
|
54
|
+
expect(list.first.device).not_to be_empty
|
55
|
+
expect(File.exist?(list.first.device)).to be_truthy
|
56
|
+
expect(Dir.exist?(list.first.path)).to be_truthy
|
57
|
+
|
58
|
+
disk = wrapper.create('200 MB')
|
59
|
+
|
60
|
+
list = wrapper.list
|
61
|
+
expect(list.length).to eq(2)
|
62
|
+
expect(list.last.device).not_to be_empty
|
63
|
+
expect(File.exist?(list.last.device)).to be_truthy
|
64
|
+
expect(Dir.exist?(list.last.path)).to be_truthy
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -2,64 +2,15 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
include Ramdo
|
4
4
|
describe Ramdisk::Factory do
|
5
|
-
after(:each) do
|
6
|
-
wrapper = Ramdisk::Factory.get
|
7
|
-
wrapper.list.each do |disk|
|
8
|
-
disk.destroy!
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
|
13
|
-
it 'should check if a ramdisk already exists' do
|
14
|
-
wrapper = Ramdisk::Factory.get
|
15
|
-
disks = wrapper.list
|
16
|
-
expect(disks).to be_an(Array)
|
17
|
-
expect(disks.length).to be(0)
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'should check if enough RAM space is free' do
|
21
|
-
wrapper = Ramdisk::Factory.get
|
22
|
-
expect(wrapper.send(:enough_ram?, '100 MB')).to be_truthy
|
23
|
-
expect(wrapper.send(:enough_ram?, '100 GB')).to be_falsey
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'should create a new RAM disk and save a file to it', focus: true do
|
27
|
-
size = '100 MB'
|
28
5
|
|
6
|
+
it 'should receive wrapper for the current OS' do
|
29
7
|
wrapper = Ramdisk::Factory.get
|
30
|
-
disk = wrapper.create(size)
|
31
8
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
wrapper = Ramdisk::Factory.get
|
38
|
-
disk = wrapper.create('100 MB')
|
39
|
-
|
40
|
-
count = wrapper.list.length
|
41
|
-
expect(disk.destroy!).to be_truthy
|
42
|
-
expect(disk.destroy!).to be_falsey # Should not work another time
|
43
|
-
|
44
|
-
expect(wrapper.list.length).to be(count - 1)
|
9
|
+
if RUBY_PLATFORM =~ /linux/
|
10
|
+
expect(wrapper).to be_a(Ramdisk::LinuxWrapper)
|
11
|
+
elsif RUBY_PLATFORM =~ /darwin/
|
12
|
+
expect(wrapper).to be_a(Ramdisk::DarwinWrapper)
|
13
|
+
end
|
45
14
|
end
|
46
15
|
|
47
|
-
it 'should list all available RAM disks' do
|
48
|
-
wrapper = Ramdisk::Factory.get
|
49
|
-
disk = wrapper.create('100 MB')
|
50
|
-
|
51
|
-
list = wrapper.list
|
52
|
-
expect(list.length).to eq(1)
|
53
|
-
expect(list.first.device).not_to be_empty
|
54
|
-
expect(File.exist?(list.first.device)).to be_truthy
|
55
|
-
expect(Dir.exist?(list.first.path)).to be_truthy
|
56
|
-
|
57
|
-
disk = wrapper.create('200 MB')
|
58
|
-
|
59
|
-
list = wrapper.list
|
60
|
-
expect(list.length).to eq(2)
|
61
|
-
expect(list.last.device).not_to be_empty
|
62
|
-
expect(File.exist?(list.last.device)).to be_truthy
|
63
|
-
expect(Dir.exist?(list.last.path)).to be_truthy
|
64
|
-
end
|
65
16
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/store_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
include Ramdo
|
4
|
-
describe Store
|
4
|
+
describe Store do
|
5
5
|
after(:all) do
|
6
6
|
wrapper = Ramdisk::Factory.get
|
7
7
|
wrapper.list.each do |disk|
|
@@ -41,6 +41,7 @@ describe Store, focus: true do
|
|
41
41
|
store.data = 'Test'
|
42
42
|
store.truncate
|
43
43
|
expect(File.exist?(store.file)).to be_falsey
|
44
|
+
expect(Dir.exist?(store.dir)).to be_falsey
|
44
45
|
end
|
45
46
|
|
46
47
|
it 'should use existing RAM disk if available' do
|
@@ -54,4 +55,13 @@ describe Store, focus: true do
|
|
54
55
|
expect(wrapper.list.length).to eq(1)
|
55
56
|
end
|
56
57
|
|
58
|
+
it 'should allow to define a specific file extension' do
|
59
|
+
store = Store.new(extension: 'png')
|
60
|
+
store.data = 'make me sexy'
|
61
|
+
expect(File.extname(store.file)).to eq('.png')
|
62
|
+
|
63
|
+
store = Store.new(extension: '.png')
|
64
|
+
store.data = 'make me sexy'
|
65
|
+
expect(File.extname(store.file)).to eq('.png')
|
66
|
+
end
|
57
67
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ramdo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Franken
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cocaine
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: timecop
|
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'
|
111
125
|
description: Fast temporary store powered by RAM disks
|
112
126
|
email:
|
113
127
|
- p.franken@aisler.net
|
@@ -116,20 +130,26 @@ extensions: []
|
|
116
130
|
extra_rdoc_files: []
|
117
131
|
files:
|
118
132
|
- ".gitignore"
|
133
|
+
- ".gitlab-ci.yml"
|
119
134
|
- Gemfile
|
120
|
-
- Gemfile.lock
|
121
135
|
- LICENSE.txt
|
122
136
|
- README.md
|
123
137
|
- Rakefile
|
124
138
|
- lib/ramdo.rb
|
139
|
+
- lib/ramdo/cleaner.rb
|
140
|
+
- lib/ramdo/exceptions.rb
|
125
141
|
- lib/ramdo/ramdisk/darwin_wrapper.rb
|
126
|
-
- lib/ramdo/ramdisk/exceptions.rb
|
127
142
|
- lib/ramdo/ramdisk/factory.rb
|
143
|
+
- lib/ramdo/ramdisk/generic_wrapper.rb
|
128
144
|
- lib/ramdo/ramdisk/instance.rb
|
129
145
|
- lib/ramdo/ramdisk/linux_wrapper.rb
|
130
146
|
- lib/ramdo/store.rb
|
131
147
|
- lib/ramdo/version.rb
|
132
148
|
- ramdo.gemspec
|
149
|
+
- spec/cleaner_spec.rb
|
150
|
+
- spec/darwin_wrapper_spec.rb
|
151
|
+
- spec/generic_wrapper_spec.rb
|
152
|
+
- spec/linux_wrapper_spec.rb
|
133
153
|
- spec/ramdisk_factory_spec.rb
|
134
154
|
- spec/spec_helper.rb
|
135
155
|
- spec/store_spec.rb
|
@@ -159,6 +179,10 @@ signing_key:
|
|
159
179
|
specification_version: 4
|
160
180
|
summary: Fast temporary store powered by RAM disks
|
161
181
|
test_files:
|
182
|
+
- spec/cleaner_spec.rb
|
183
|
+
- spec/darwin_wrapper_spec.rb
|
184
|
+
- spec/generic_wrapper_spec.rb
|
185
|
+
- spec/linux_wrapper_spec.rb
|
162
186
|
- spec/ramdisk_factory_spec.rb
|
163
187
|
- spec/spec_helper.rb
|
164
188
|
- spec/store_spec.rb
|
data/Gemfile.lock
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
ramdo (0.1.1)
|
5
|
-
cocaine
|
6
|
-
filesize
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: https://rubygems.org/
|
10
|
-
specs:
|
11
|
-
activesupport (5.0.0)
|
12
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
-
i18n (~> 0.7)
|
14
|
-
minitest (~> 5.1)
|
15
|
-
tzinfo (~> 1.1)
|
16
|
-
builder (3.2.2)
|
17
|
-
climate_control (0.0.3)
|
18
|
-
activesupport (>= 3.0)
|
19
|
-
cocaine (0.5.8)
|
20
|
-
climate_control (>= 0.0.3, < 1.0)
|
21
|
-
concurrent-ruby (1.0.2)
|
22
|
-
diff-lcs (1.2.5)
|
23
|
-
faraday (0.9.2)
|
24
|
-
multipart-post (>= 1.2, < 3)
|
25
|
-
filesize (0.1.1)
|
26
|
-
geminabox (0.12.4)
|
27
|
-
builder
|
28
|
-
faraday
|
29
|
-
httpclient (>= 2.2.7)
|
30
|
-
nesty
|
31
|
-
sinatra (>= 1.2.7)
|
32
|
-
httpclient (2.7.0.1)
|
33
|
-
i18n (0.7.0)
|
34
|
-
minitest (5.9.0)
|
35
|
-
multipart-post (2.0.0)
|
36
|
-
nesty (1.0.2)
|
37
|
-
rack (1.6.4)
|
38
|
-
rack-protection (1.5.3)
|
39
|
-
rack
|
40
|
-
rake (10.4.2)
|
41
|
-
rspec (3.3.0)
|
42
|
-
rspec-core (~> 3.3.0)
|
43
|
-
rspec-expectations (~> 3.3.0)
|
44
|
-
rspec-mocks (~> 3.3.0)
|
45
|
-
rspec-core (3.3.2)
|
46
|
-
rspec-support (~> 3.3.0)
|
47
|
-
rspec-expectations (3.3.1)
|
48
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
49
|
-
rspec-support (~> 3.3.0)
|
50
|
-
rspec-mocks (3.3.2)
|
51
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
52
|
-
rspec-support (~> 3.3.0)
|
53
|
-
rspec-support (3.3.0)
|
54
|
-
sinatra (1.4.5)
|
55
|
-
rack (~> 1.4)
|
56
|
-
rack-protection (~> 1.4)
|
57
|
-
tilt (~> 1.3, >= 1.3.4)
|
58
|
-
thread_safe (0.3.5)
|
59
|
-
tilt (1.4.1)
|
60
|
-
tzinfo (1.2.2)
|
61
|
-
thread_safe (~> 0.1)
|
62
|
-
yard (0.8.7.6)
|
63
|
-
|
64
|
-
PLATFORMS
|
65
|
-
ruby
|
66
|
-
|
67
|
-
DEPENDENCIES
|
68
|
-
bundler
|
69
|
-
geminabox
|
70
|
-
rake
|
71
|
-
ramdo!
|
72
|
-
rspec
|
73
|
-
yard
|
74
|
-
|
75
|
-
BUNDLED WITH
|
76
|
-
1.12.5
|