ramdo 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cec4df65cd2840f109a7205163af45c47a64df4b
4
- data.tar.gz: 5e19b6915b85392c75a7868058952a8a0db75c6e
3
+ metadata.gz: f92ac84a314fad2f1cf45da69f8c27418ee02a8c
4
+ data.tar.gz: 5ce4534961997c995b66794f7cdf5ada80bb5b5b
5
5
  SHA512:
6
- metadata.gz: 39ddd3e6dca71a664eaffd8224571bbd07878d57dd719d45ecbb859661b1387cf7397a06590e61efafb988bb7a48dea73f2433cc0431b3e54daeb070f1154376
7
- data.tar.gz: 1d3e76937dfa7c108c56cfd8f5e7093f641358a5aba78bdf18d3f930a5a49aed3ea34b8626e7f1aea318b44705f48ff95d60c5f841ac019a8101b5d61249a2e1
6
+ metadata.gz: 49203b023b7950ac56e0f33e4aa669456c9b8041f2570bf43afaa6d9f0d74a9f8324c294db1901e0f92278890355bd762b50e2b38390ab5320539d0992c330a3
7
+ data.tar.gz: f42d7d6f90642876e961ab0ffa2279e1b7f68c874d761b05dfb58d4b17b79ea17c227ff4a4ae68aa7f000d62993917e4aaa726fcc5150dccef151701d739aaa2
data/.gitignore ADDED
@@ -0,0 +1,96 @@
1
+
2
+ # Created by https://www.gitignore.io/api/ruby,osx,linux
3
+
4
+ ### Ruby ###
5
+ *.gem
6
+ *.rbc
7
+ /.config
8
+ /coverage/
9
+ /InstalledFiles
10
+ /pkg/
11
+ /spec/reports/
12
+ /spec/examples.txt
13
+ /test/tmp/
14
+ /test/version_tmp/
15
+ /tmp/
16
+
17
+ # Used by dotenv library to load environment variables.
18
+ # .env
19
+
20
+ ## Specific to RubyMotion:
21
+ .dat*
22
+ .repl_history
23
+ build/
24
+ *.bridgesupport
25
+ build-iPhoneOS/
26
+ build-iPhoneSimulator/
27
+
28
+ ## Specific to RubyMotion (use of CocoaPods):
29
+ #
30
+ # We recommend against adding the Pods directory to your .gitignore. However
31
+ # you should judge for yourself, the pros and cons are mentioned at:
32
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
33
+ #
34
+ # vendor/Pods/
35
+
36
+ ## Documentation cache and generated files:
37
+ /.yardoc/
38
+ /_yardoc/
39
+ /doc/
40
+ /rdoc/
41
+
42
+ ## Environment normalization:
43
+ /.bundle/
44
+ /vendor/bundle
45
+ /lib/bundler/man/
46
+
47
+ # for a library or gem, you might want to ignore these files since the code is
48
+ # intended to run in multiple environments; otherwise, check them in:
49
+ # Gemfile.lock
50
+ # .ruby-version
51
+ # .ruby-gemset
52
+
53
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
54
+ .rvmrc
55
+
56
+
57
+ ### OSX ###
58
+ *.DS_Store
59
+ .AppleDouble
60
+ .LSOverride
61
+
62
+ # Icon must end with two \r
63
+ Icon
64
+
65
+
66
+ # Thumbnails
67
+ ._*
68
+
69
+ # Files that might appear in the root of a volume
70
+ .DocumentRevisions-V100
71
+ .fseventsd
72
+ .Spotlight-V100
73
+ .TemporaryItems
74
+ .Trashes
75
+ .VolumeIcon.icns
76
+ .com.apple.timemachine.donotpresent
77
+
78
+ # Directories potentially created on remote AFP share
79
+ .AppleDB
80
+ .AppleDesktop
81
+ Network Trash Folder
82
+ Temporary Items
83
+ .apdisk
84
+
85
+
86
+ ### Linux ###
87
+ *~
88
+
89
+ # temporary files which can be created if a process still has a handle open of a deleted file
90
+ .fuse_hidden*
91
+
92
+ # KDE directory preferences
93
+ .directory
94
+
95
+ # Linux trash folder which might appear on any partition or disk
96
+ .Trash-*
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ramdo (0.0.2)
4
+ ramdo (0.1.1)
5
5
  cocaine
6
6
  filesize
7
7
 
@@ -73,4 +73,4 @@ DEPENDENCIES
73
73
  yard
74
74
 
75
75
  BUNDLED WITH
76
- 1.12.4
76
+ 1.12.5
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Ramdo
2
2
 
3
- Fast temporary store supported by RAM disks.
3
+ Fast temporary store powered by RAM disks.
4
4
 
5
5
  ## Installation
6
6
 
@@ -42,6 +42,13 @@ module Ramdo
42
42
  list().select { |disk| disk.device == device }.first
43
43
  end
44
44
 
45
+ def destroy(instance)
46
+ return false unless File.exist? instance.device
47
+
48
+ line = Cocaine::CommandLine.new("hdiutil", "detach :device")
49
+ line.run(device: instance.device)
50
+ end
51
+
45
52
  private
46
53
  def enough_ram?(size)
47
54
  size = Filesize.from(size) if size.is_a? String
@@ -61,4 +68,4 @@ module Ramdo
61
68
  end
62
69
  end
63
70
  end
64
- end
71
+ end
@@ -2,5 +2,6 @@ module Ramdo
2
2
  module Ramdisk
3
3
  class OSNotSupportedException < StandardError; end
4
4
  class NotEnoughFreeRamException < StandardError; end
5
+ class GeneralRamdiskException < StandardError; end
5
6
  end
6
- end
7
+ end
@@ -2,7 +2,7 @@ module Ramdo
2
2
  module Ramdisk
3
3
  class Factory
4
4
  def self.get
5
- if RUBY_PLATFORM =~ /linux_not_implemented_yet/
5
+ if RUBY_PLATFORM =~ /linux/
6
6
  LinuxWrapper.new
7
7
  elsif RUBY_PLATFORM =~ /darwin/
8
8
  DarwinWrapper.new
@@ -13,4 +13,4 @@ module Ramdo
13
13
  end
14
14
 
15
15
  end
16
- end
16
+ end
@@ -1,6 +1,8 @@
1
1
  module Ramdo
2
2
  module Ramdisk
3
3
  class Instance
4
+ NAME_PATTERN = /ramdo_[A-Za-z0-9_-]+$/
5
+
4
6
  def self.generate_name
5
7
  "ramdo_#{SecureRandom.uuid}"
6
8
  end
@@ -14,11 +16,9 @@ module Ramdo
14
16
  end
15
17
 
16
18
  def destroy!
17
- return false unless File.exist? @device
18
-
19
- line = Cocaine::CommandLine.new("hdiutil", "detach :device")
20
- line.run(device: @device)
19
+ wrapper = Ramdisk::Factory.get
20
+ wrapper.destroy self
21
21
  end
22
22
  end
23
23
  end
24
- end
24
+ end
@@ -1,7 +1,62 @@
1
1
  module Ramdo
2
2
  module Ramdisk
3
3
  class LinuxWrapper
4
+ def initialize
5
+ @shm_path = "/dev/shm"
6
+ end
4
7
 
8
+ def list
9
+ disks = []
10
+
11
+ found_shm = false
12
+ line = Cocaine::CommandLine.new("cat", "/proc/mounts")
13
+ line.run.each_line do |line|
14
+ found_shm ||= line =~ /^tmpfs \/dev\/shm tmpfs/
15
+ end
16
+ raise GeneralRamdiskException.new("#{@shm_path} not found") unless found_shm
17
+
18
+ Dir.glob(@shm_path + '/*').each do |dir|
19
+ if dir =~ Instance::NAME_PATTERN
20
+ disks << Instance.new(path: dir, device: @shm_path, size: Filesize.from("1 GB"))
21
+ end
22
+ end
23
+
24
+ disks
25
+ end
26
+
27
+ def create(size)
28
+ size = Filesize.from(size) if size.is_a? String
29
+ raise NotEnoughFreeRamException.new unless enough_ram? size
30
+
31
+ # Create new directory as dedicated space
32
+ path = [@shm_path, Instance.generate_name].join('/')
33
+ Dir.mkdir(path)
34
+
35
+ # Receive all disk and select just created one
36
+ list().select { |disk| disk.path == path }.first
37
+ end
38
+
39
+ def destroy(instance)
40
+ return false unless File.exist? instance.path
41
+
42
+ Dir.glob(instance.path + "/*").each { |file| File.delete(file) if File.file? file }
43
+ Dir.rmdir(instance.path)
44
+ end
45
+
46
+ private
47
+ def enough_ram?(size)
48
+ size = Filesize.from(size) if size.is_a? String
49
+ free_mem = ""
50
+
51
+ line = Cocaine::CommandLine.new("cat", "/proc/meminfo")
52
+ line.run.each_line do |line|
53
+ if line =~ /^MemFree:[\s]+([0-9]+ kB)/
54
+ free_mem = Regexp.last_match[1]
55
+ end
56
+ end
57
+
58
+ Filesize.from(free_mem) > size
59
+ end
5
60
  end
6
61
  end
7
- end
62
+ end
data/lib/ramdo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ramdo
2
- VERSION = '0.1.1'
3
- end
2
+ VERSION = '0.1.2'
3
+ end
data/ramdo.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Ramdo::VERSION
9
9
  spec.authors = ["Patrick Franken"]
10
10
  spec.email = ["p.franken@aisler.net"]
11
- spec.summary = "Fast temporary store supported by RAM disks"
11
+ spec.summary = "Fast temporary store powered by RAM disks"
12
12
  spec.description = spec.summary
13
13
  spec.homepage = "http://aisler.net"
14
14
  spec.license = "MIT"
@@ -23,7 +23,7 @@ describe Ramdisk::Factory do
23
23
  expect(wrapper.send(:enough_ram?, '100 GB')).to be_falsey
24
24
  end
25
25
 
26
- it 'should create a new RAM disk and save a file to it' do
26
+ it 'should create a new RAM disk and save a file to it', focus: true do
27
27
  size = '100 MB'
28
28
 
29
29
  wrapper = Ramdisk::Factory.get
@@ -31,7 +31,6 @@ describe Ramdisk::Factory do
31
31
 
32
32
  expect(disk).to be_an(Ramdisk::Instance)
33
33
  expect { IO.write("#{disk.path}/test.bin", IO.read('/dev/urandom', 100000)) }.not_to raise_error
34
- expect(disk.size).to eq(Filesize.from(size))
35
34
  end
36
35
 
37
36
  it 'should remove a RAM disk' do
@@ -54,7 +53,6 @@ describe Ramdisk::Factory do
54
53
  expect(list.first.device).not_to be_empty
55
54
  expect(File.exist?(list.first.device)).to be_truthy
56
55
  expect(Dir.exist?(list.first.path)).to be_truthy
57
- expect(list.first.size).to eq(Filesize.from('100 MB'))
58
56
 
59
57
  disk = wrapper.create('200 MB')
60
58
 
@@ -63,6 +61,5 @@ describe Ramdisk::Factory do
63
61
  expect(list.last.device).not_to be_empty
64
62
  expect(File.exist?(list.last.device)).to be_truthy
65
63
  expect(Dir.exist?(list.last.path)).to be_truthy
66
- expect(list.last.size).to eq(Filesize.from('200 MB'))
67
64
  end
68
65
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ramdo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Franken
@@ -108,13 +108,14 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
- description: Fast temporary store supported by RAM disks
111
+ description: Fast temporary store powered by RAM disks
112
112
  email:
113
113
  - p.franken@aisler.net
114
114
  executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
+ - ".gitignore"
118
119
  - Gemfile
119
120
  - Gemfile.lock
120
121
  - LICENSE.txt
@@ -156,9 +157,8 @@ rubyforge_project:
156
157
  rubygems_version: 2.4.5.1
157
158
  signing_key:
158
159
  specification_version: 4
159
- summary: Fast temporary store supported by RAM disks
160
+ summary: Fast temporary store powered by RAM disks
160
161
  test_files:
161
162
  - spec/ramdisk_factory_spec.rb
162
163
  - spec/spec_helper.rb
163
164
  - spec/store_spec.rb
164
- has_rdoc: