ejectable 0.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ejectable might be problematic. Click here for more details.

checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 394b368e225fb950f8825f542553a9c936943587b6022193b7ff32afd747ab20
4
+ data.tar.gz: 6e7edc8d3e5e8ce739adf77f5302fcf4b7a82c77d3e68cc6b0a52c4ccd79d51e
5
+ SHA512:
6
+ metadata.gz: a9aa11500172f73f54d75ce6d5f99685575f1e6aaa28daac8b296f0059a6800e8b85e5314182e6b836e66af1a10777b044ff37c184cd637bfe9d26c66cc8472e
7
+ data.tar.gz: 8df6a82e6db509d46820f45b98c3c29849106ae4e278aa4e6d1000c098fc6f52549d720c3d6d4e686dcf383d0f56f1c03741b3abe8ae23cbd4ddc989f5c7460b
data/.gitignore ADDED
@@ -0,0 +1,35 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ coverage.data
7
+ InstalledFiles
8
+ lib/bundler/man
9
+ pkg
10
+ rdoc
11
+ spec/reports
12
+ test/tmp
13
+ test/version_tmp
14
+ tmp
15
+
16
+ # bundler
17
+ vendor/
18
+
19
+ # YARD artifacts
20
+ .yardoc
21
+ _yardoc
22
+ doc/
23
+
24
+ # tmp-old
25
+ .old
26
+
27
+ # editor
28
+ *~
29
+ .redcar
30
+
31
+ # other
32
+ *.lock
33
+ *.bak
34
+ tool/
35
+ *\#*
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - ruby-head
5
+ - 2.6
6
+ - 2.5
7
+ - rbx-4
8
+ - jruby-head
9
+
10
+ matrix:
11
+ allow_failures:
12
+ - rvm: ruby-head
13
+ - rvm: rbx-4
14
+ - rvm: jruby-head
15
+
16
+ before_install:
17
+ - gem install bundler
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --readme README.md lib/**/*.rb
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'rake'
7
+ end
8
+
9
+ group :test do
10
+ gem 'rake'
11
+ end
data/MIT-LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ (The MIT X11 License)
2
+
3
+ Copyright (c) 2013 Kenichi Kamiya
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 NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,89 @@
1
+ ejectable
2
+ ============
3
+
4
+ Description
5
+ -----------
6
+
7
+ Eject and close tray on your devices.
8
+
9
+ Features
10
+ --------
11
+
12
+ * Eject tray
13
+ * Close tray
14
+
15
+ Usage
16
+ -----
17
+
18
+ Setup
19
+
20
+ ```ruby
21
+ require 'ejectable'
22
+ ```
23
+
24
+ Use via method
25
+
26
+ ```ruby
27
+ include Ejectable
28
+
29
+ eject_tray
30
+ ```
31
+
32
+ Use device class
33
+
34
+ ```ruby
35
+ device = Ejectable::Device.new
36
+ device.eject_tray
37
+ ```
38
+
39
+ Auto closing after operation
40
+
41
+ ```ruby
42
+ device.eject_tray! do
43
+ sleep 5
44
+ end
45
+ ```
46
+
47
+ Requirements
48
+ -------------
49
+
50
+ * Ruby - [2.5 or later](http://travis-ci.org/#!/kachick/ejectable)
51
+
52
+ Install
53
+ -------
54
+
55
+ git-repos
56
+
57
+ ```bash
58
+ git clone https://github.com/kachick/ejectable.git
59
+ gem build ejectable.gemspec
60
+ gem install ./ejectable
61
+ ```
62
+
63
+ rubygems.org
64
+
65
+ ```bash
66
+ gem install ejectable
67
+ ```
68
+
69
+ Build Status
70
+ -------------
71
+
72
+ [![Build Status](https://secure.travis-ci.org/kachick/ejectable.png)](http://travis-ci.org/kachick/ejectable)
73
+
74
+ Link
75
+ ----
76
+
77
+ * [Home](http://kachick.github.com/ejectable)
78
+ * [code](https://github.com/kachick/ejectable)
79
+ * [API](http://kachick.github.com/ejectable/yard/frames.html)
80
+ * [issues](https://github.com/kachick/ejectable/issues)
81
+ * [CI](http://travis-ci.org/#!/kachick/ejectable)
82
+ * [gem](https://rubygems.org/gems/ejectable)
83
+
84
+ License
85
+ --------
86
+
87
+ The MIT X11 License
88
+ Copyright (c) 2013 Kenichi Kamiya
89
+ See MIT-LICENSE for further details.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
3
+
4
+ require 'rake/testtask'
5
+
6
+ task :default => [:test]
7
+
8
+ Rake::TestTask.new do |tt|
9
+ tt.verbose = true
10
+ end
data/ejectable.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ Gem::Specification.new do |gem|
2
+ gem.name = 'ejectable'
3
+ gem.version = '0.1.0'
4
+ gem.authors = ['Kenichi Kamiya']
5
+ gem.email = ['kachick1+ruby@gmail.com']
6
+ gem.licenses = ['MIT']
7
+ gem.summary = 'Eject and close tray on your devices.'
8
+ gem.description = gem.summary.dup
9
+ gem.homepage = 'http://kachick.github.com/ejectable'
10
+
11
+ gem.files = `git ls-files`.split($/)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.require_paths = ['lib']
15
+
16
+ gem.add_development_dependency 'test-unit', '>= 3.3.3', '< 4'
17
+ gem.add_development_dependency 'yard', '>= 0.9.20', '< 2'
18
+ gem.add_development_dependency 'rake', '>= 10', '< 20'
19
+ end
data/example/README.rb ADDED
@@ -0,0 +1,8 @@
1
+ $VERBOSE = true
2
+
3
+ require_relative '../lib/ejectable'
4
+
5
+ device = Ejectable::Device.new
6
+ device.eject_tray! do
7
+ sleep 5
8
+ end
data/lib/ejectable.rb ADDED
@@ -0,0 +1,48 @@
1
+ # Copyight (c) 2013 Kenichi Kamiya
2
+
3
+ require 'rbconfig'
4
+
5
+ case host_os = RbConfig::CONFIG.fetch('host_os')
6
+ when /darwin/
7
+ raise "unsupported os: #{host_os}"
8
+ when /mswin(?!ce)|mingw|cygwin|bccwin/
9
+ require_relative 'ejectable/windows'
10
+ else
11
+ require_relative 'ejectable/unix'
12
+ end
13
+
14
+ module Ejectable
15
+
16
+ class TrayHandleError < StandardError; end
17
+
18
+ module_function
19
+
20
+ # @param [String] devname
21
+ # @return [void]
22
+ # @raise [TrayHandleError] if failed to eject tray
23
+ # @yield close tray when exit block
24
+ # @yieldreturn [void]
25
+ def eject_tray!(devname=DEFAULT_DEVICE_NAME, &block)
26
+ eject_tray(devname) || raise(TrayHandleError)
27
+
28
+ if block_given?
29
+ begin
30
+ block.call
31
+ ensure
32
+ close_tray! devname
33
+ end
34
+ end
35
+
36
+ nil
37
+ end
38
+
39
+ # @param [String] devname
40
+ # @return [void]
41
+ def close_tray!(devname=DEFAULT_DEVICE_NAME)
42
+ close_tray(devname) || raise(TrayHandleError)
43
+ nil
44
+ end
45
+
46
+ end
47
+
48
+ require_relative 'ejectable/device'
@@ -0,0 +1,26 @@
1
+ module Ejectable
2
+
3
+ # @example
4
+ # device = Ejectable::Device.new '/dev/cdrom'
5
+ # device.eject_tray!
6
+ class Device
7
+
8
+ # @param [String] name
9
+ def initialize(name=DEFAULT_DEVICE_NAME)
10
+ @name = name.dup.freeze
11
+ end
12
+
13
+ # @return [String]
14
+ def name
15
+ @name.dup
16
+ end
17
+
18
+ Ejectable.public_methods(false).grep(/_tray/) do |meth|
19
+ define_method meth do |&block|
20
+ Ejectable.__send__ meth, @name, &block
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+ end
@@ -0,0 +1,21 @@
1
+ module Ejectable
2
+
3
+ # @return [String]
4
+ DEFAULT_DEVICE_NAME = ''.freeze
5
+
6
+ module_function
7
+
8
+ # @param [String] devname
9
+ # @return [Boolean]
10
+ def eject_tray(devname=DEFAULT_DEVICE_NAME)
11
+ system("eject #{devname}")
12
+ end
13
+
14
+ # @param [String] devname
15
+ # @return [Boolean]
16
+ # @raise [TrayHandleError] if failed to open tray
17
+ def close_tray(devname=DEFAULT_DEVICE_NAME)
18
+ system("eject -t #{devname}")
19
+ end
20
+
21
+ end
@@ -0,0 +1,37 @@
1
+ require 'dl/import'
2
+
3
+ module Ejectable
4
+
5
+ # @return [String]
6
+ DEFAULT_DEVICE_NAME = 'cdaudio'.freeze
7
+
8
+ extend DL::Importer
9
+
10
+ # @group for DL
11
+
12
+ dlload 'winmm'
13
+ typealias 'DWORD', 'unsigned long'
14
+ typealias 'HANDLE', 'unsigned long'
15
+ typealias 'LPCSTR', 'unsigned char *'
16
+ typealias 'LPTSTR', 'const char *'
17
+ typealias 'UINT', 'unsigned int'
18
+ extern 'DWORD mciSendString(LPCSTR, LPTSTR, UINT, HANDLE)'
19
+
20
+ # @endgroup
21
+
22
+ module_function
23
+
24
+ # @param [String] devname
25
+ # @return [Boolean]
26
+ def eject_tray(devname=DEFAULT_DEVICE_NAME)
27
+ mciSendString "set #{devname} door open", nil, 0, 0
28
+ end
29
+
30
+ # @param [String] devname
31
+ # @return [Boolean]
32
+ # @raise [TrayHandleError] if failed to open tray
33
+ def close_tray(devname=DEFAULT_DEVICE_NAME)
34
+ mciSendString "set #{devname} door closed", nil, 0, 0
35
+ end
36
+
37
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'test/unit'
2
+
3
+ $VERBOSE = true
4
+
5
+ require_relative '../lib/ejectable'
@@ -0,0 +1,23 @@
1
+ require_relative 'helper'
2
+
3
+ module Test_Ejectable
4
+
5
+ class Test_Topmodule < Test::Unit::TestCase
6
+
7
+ def test_methods
8
+ assert(([:close_tray, :close_tray!, :eject_tray, :eject_tray!] \
9
+ - Ejectable.public_methods).empty?)
10
+ end
11
+
12
+ end
13
+
14
+ class Test_Device < Test::Unit::TestCase
15
+
16
+ def test_methods
17
+ assert(([:close_tray, :close_tray!, :eject_tray, :eject_tray!, :name] \
18
+ - Ejectable::Device.public_instance_methods(false)).empty?)
19
+ end
20
+
21
+ end
22
+
23
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ejectable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kenichi Kamiya
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-07-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: test-unit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.3.3
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '4'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 3.3.3
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '4'
33
+ - !ruby/object:Gem::Dependency
34
+ name: yard
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 0.9.20
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '2'
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 0.9.20
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '2'
53
+ - !ruby/object:Gem::Dependency
54
+ name: rake
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '10'
60
+ - - "<"
61
+ - !ruby/object:Gem::Version
62
+ version: '20'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '10'
70
+ - - "<"
71
+ - !ruby/object:Gem::Version
72
+ version: '20'
73
+ description: Eject and close tray on your devices.
74
+ email:
75
+ - kachick1+ruby@gmail.com
76
+ executables: []
77
+ extensions: []
78
+ extra_rdoc_files: []
79
+ files:
80
+ - ".gitignore"
81
+ - ".travis.yml"
82
+ - ".yardopts"
83
+ - Gemfile
84
+ - MIT-LICENSE
85
+ - README.md
86
+ - Rakefile
87
+ - ejectable.gemspec
88
+ - example/README.rb
89
+ - lib/ejectable.rb
90
+ - lib/ejectable/device.rb
91
+ - lib/ejectable/unix.rb
92
+ - lib/ejectable/windows.rb
93
+ - test/helper.rb
94
+ - test/test_ejectable.rb
95
+ homepage: http://kachick.github.com/ejectable
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.7.6
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Eject and close tray on your devices.
119
+ test_files:
120
+ - test/helper.rb
121
+ - test/test_ejectable.rb