bini 0.5.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.
- data/.gitignore +4 -0
- data/.rspec +2 -0
- data/.travis.yml +11 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +22 -0
- data/README.md +71 -0
- data/Rakefile +7 -0
- data/bini.gemspec +20 -0
- data/lib/bini.rb +92 -0
- data/lib/bini/config.rb +9 -0
- data/lib/bini/filemagic.rb +15 -0
- data/lib/bini/mixins.rb +5 -0
- data/lib/bini/optparser.rb +53 -0
- data/lib/bini/sash.rb +98 -0
- data/lib/bini/version.rb +3 -0
- data/spec/bini_spec.rb +92 -0
- data/spec/config_spec.rb +15 -0
- data/spec/filemagic_spec.rb +7 -0
- data/spec/mixins_spec.rb +9 -0
- data/spec/optparser_spec.rb +51 -0
- data/spec/sash_spec.rb +78 -0
- data/spec/spec_helper.rb +27 -0
- metadata +98 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Ernie Brodeur
|
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,71 @@
|
|
1
|
+
# Bini
|
2
|
+
|
3
|
+
A toolbox to help me rapidly build/deploy a cli. Filled with assumptions about how I think a CLI should behave.
|
4
|
+
|
5
|
+
#### Build Status
|
6
|
+
<table border="0">
|
7
|
+
<tr>
|
8
|
+
<td>master</td>
|
9
|
+
<td><a href=http://travis-ci.org/erniebrodeur/bini?branch=master><img src="https://secure.travis-ci.org/erniebrodeur/bini.png?branch=master"/></h> </td>
|
10
|
+
</tr>
|
11
|
+
<tr>
|
12
|
+
<td>development</td>
|
13
|
+
<td><a href=http://travis-ci.org/erniebrodeur/bini?branch=development><img src="https://secure.travis-ci.org/erniebrodeur/bini.png?branch=development"/></h> </td>
|
14
|
+
</tr>
|
15
|
+
</table>
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
To install:
|
20
|
+
|
21
|
+
% gem install bini
|
22
|
+
|
23
|
+
To use inside of an application, add this to the your gemfile:
|
24
|
+
|
25
|
+
% gem 'bini'
|
26
|
+
|
27
|
+
and run bundle to make it available:
|
28
|
+
|
29
|
+
% bundle
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
Bini is broken up into a few pieces, always include this first:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
require 'bini'
|
37
|
+
```
|
38
|
+
|
39
|
+
Optional components can be loaded like this:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
require 'bini/config'
|
43
|
+
require 'bini/optparser'
|
44
|
+
require 'bini/log'
|
45
|
+
```
|
46
|
+
|
47
|
+
### API
|
48
|
+
|
49
|
+
Generated documentation is available via ```yard```.
|
50
|
+
|
51
|
+
Examples and wiki coming if they are ever needed.
|
52
|
+
|
53
|
+
## Testing
|
54
|
+
|
55
|
+
In theory, testing is complete, in practice it's a work in progress.
|
56
|
+
|
57
|
+
## Design philosophy
|
58
|
+
|
59
|
+
If such a thing can be said.
|
60
|
+
|
61
|
+
* Whenever possible, sane defaults will be supplied.
|
62
|
+
* A minimum amount of configuration before execution.
|
63
|
+
* If it requires a large chunk of requires, put it in a sub gem.
|
64
|
+
* Speed is of the utmost importance.
|
65
|
+
* Whenever possible, use stuff out of the stdlib.
|
66
|
+
|
67
|
+
## Contributing
|
68
|
+
|
69
|
+
I don't have rules here, more guidelines.
|
70
|
+
|
71
|
+
* Try to make the branch name clear, words like feature/issue/bug help.
|
data/Rakefile
ADDED
data/bini.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bini/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "bini"
|
8
|
+
gem.version = Bini::VERSION
|
9
|
+
gem.authors = ["Ernie Brodeur"]
|
10
|
+
gem.email = ["ebrodeur@ujami.net"]
|
11
|
+
gem.description = "Bini needs no description."
|
12
|
+
gem.summary = "Bini is a gem that helps me build CLI tools. It's not thor, trollop, or any of the other major frameworks. It makes lots and lots of assumptions. It's probably not for you."
|
13
|
+
gem.homepage = "https://github.com/erniebrodeur/bini"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
gem.add_runtime_dependency "sys-proctable"
|
20
|
+
end
|
data/lib/bini.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'sys/proctable'
|
2
|
+
|
3
|
+
require "bini/sash"
|
4
|
+
require "bini/version"
|
5
|
+
require "bini/filemagic"
|
6
|
+
|
7
|
+
module Bini
|
8
|
+
extend self
|
9
|
+
|
10
|
+
attr_accessor :defaults
|
11
|
+
|
12
|
+
# I break this out so that I can use long name right away, this allows methods
|
13
|
+
# like configure to work.
|
14
|
+
|
15
|
+
@defaults = {}
|
16
|
+
@defaults[:long_name] = $0.split("/").last
|
17
|
+
@defaults[:cache_dir] = "#{Dir.home}/.cache/bini/#{@long_name}/"
|
18
|
+
@defaults[:config_dir] = "#{Dir.home}/.config/bini/#{@long_name}/"
|
19
|
+
|
20
|
+
# Dynamic attribute's based off the keys.
|
21
|
+
def keys
|
22
|
+
[:long_name, :cache_dir, :config_dir]
|
23
|
+
end
|
24
|
+
|
25
|
+
keys.each do |key|
|
26
|
+
define_method(key) do
|
27
|
+
v = instance_variable_get "@#{key}"
|
28
|
+
return @defaults[key] if !v
|
29
|
+
return v
|
30
|
+
end
|
31
|
+
define_method("#{key}=".to_sym) do |dir|
|
32
|
+
instance_variable_set "@#{key}", dir
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def pids
|
37
|
+
a = Sys::ProcTable.ps.select{|x| x.cmdline =~ /.*#{@name}.*-[dD].*/}.map {|x| x.pid}
|
38
|
+
a.delete $$
|
39
|
+
return a if a.any?
|
40
|
+
nil
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
def daemonize(*params, &block)
|
45
|
+
if params[0] && !params[0][:multiple_pids] && pids
|
46
|
+
puts :info, "#{@name} appears to be running (#{pids}), only one allowed, exiting."
|
47
|
+
exit
|
48
|
+
end
|
49
|
+
puts :info, "Forking to background."
|
50
|
+
|
51
|
+
Process.daemon
|
52
|
+
block.call
|
53
|
+
end
|
54
|
+
|
55
|
+
def kill_daemon
|
56
|
+
if !pids
|
57
|
+
puts :fatal, "No pids found, exiting."
|
58
|
+
end
|
59
|
+
|
60
|
+
pids.each do |p|
|
61
|
+
puts :info, "Killing #{p}"
|
62
|
+
`kill -TERM #{p}`
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Adds a rails style configure method (@benwoody's unknown contribution)
|
67
|
+
def configure
|
68
|
+
yield self
|
69
|
+
parameters
|
70
|
+
end
|
71
|
+
|
72
|
+
# List available parameters and values in those params
|
73
|
+
def parameters
|
74
|
+
@values = {}
|
75
|
+
keys.each { |k| @values.merge! k => Bini.send(k) }
|
76
|
+
@values
|
77
|
+
end
|
78
|
+
alias_method :params, :parameters
|
79
|
+
|
80
|
+
# Returns true or false if all parameters are set.
|
81
|
+
def parameters?
|
82
|
+
parameters.values.all?
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
# Helper to clean up recursive method in #parameters
|
88
|
+
def get_var(var)
|
89
|
+
self.instance_variable_get(var)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
data/lib/bini/config.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Bini
|
2
|
+
module FileMagic
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def mime_type(file)
|
6
|
+
return `file -bk --mime-type "#{file}"`.chomp! if File.exist? file
|
7
|
+
return nil
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
def filemagic_version
|
12
|
+
`file -v`.split(/^file-(.*)\nmagic file from (.*)\n/)[1]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/bini/mixins.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module Bini
|
4
|
+
class OptionParser < ::OptionParser
|
5
|
+
def initialize
|
6
|
+
super
|
7
|
+
@options = {}
|
8
|
+
|
9
|
+
on("-V", "--version", "Print version") { |version| @options[:version] = true}
|
10
|
+
end
|
11
|
+
|
12
|
+
def parse!
|
13
|
+
super
|
14
|
+
|
15
|
+
if @options[:version]
|
16
|
+
if Bini.version
|
17
|
+
puts Bini.version
|
18
|
+
else
|
19
|
+
puts "No version supplied."
|
20
|
+
end
|
21
|
+
exit 0
|
22
|
+
end
|
23
|
+
|
24
|
+
mash Bini.config if Bini.config
|
25
|
+
end
|
26
|
+
|
27
|
+
# These are the hash like bits.
|
28
|
+
|
29
|
+
def clear
|
30
|
+
@options.clear
|
31
|
+
end
|
32
|
+
|
33
|
+
def [](k = nil)
|
34
|
+
return @options[k] if k
|
35
|
+
return @options if @options.any?
|
36
|
+
{}
|
37
|
+
end
|
38
|
+
|
39
|
+
def []=(k,v)
|
40
|
+
@options[k] = v
|
41
|
+
end
|
42
|
+
|
43
|
+
# merge takes in a set of values and overwrites the previous values.
|
44
|
+
# mash does this in reverse.
|
45
|
+
def mash(h)
|
46
|
+
h.merge! @options
|
47
|
+
@options.clear
|
48
|
+
h.each {|k,v| self[k] = v}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
Options = OptionParser.new
|
52
|
+
end
|
53
|
+
|
data/lib/bini/sash.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module Bini
|
5
|
+
# This is a savable hash, it can be configured and used to store whatever the# contents of the hash are for loading later. Will serialize in yaml to keep all
|
6
|
+
# the dependencies in ruby stdlib.
|
7
|
+
class Sash < Hash
|
8
|
+
|
9
|
+
attr_accessor :file
|
10
|
+
attr_accessor :backup
|
11
|
+
attr_accessor :mode
|
12
|
+
attr_accessor :auto_load
|
13
|
+
attr_accessor :auto_save
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
# initialization sets the values of the class Sash, not the contents of the Hash.
|
18
|
+
def initialize(params = {})
|
19
|
+
params.each { |k,v| instance_variable_set "@" + k.to_s,v}
|
20
|
+
load if @auto_load
|
21
|
+
end
|
22
|
+
|
23
|
+
# The base directory of the save file.
|
24
|
+
def basedir
|
25
|
+
return nil if !file
|
26
|
+
File.dirname File.absolute_path @file
|
27
|
+
end
|
28
|
+
|
29
|
+
# The save file plus an extension.
|
30
|
+
def backup_file
|
31
|
+
"#{@file}.bak"
|
32
|
+
end
|
33
|
+
|
34
|
+
# Save the hash to the file, check for backup and set_mode.
|
35
|
+
def save
|
36
|
+
if any?
|
37
|
+
FileUtils.mkdir_p basedir if !Dir.exist? basedir
|
38
|
+
backup if @backup
|
39
|
+
|
40
|
+
# I do this the long way because I want an immediate sync.
|
41
|
+
f = open(@file, 'w')
|
42
|
+
f.write YAML::dump self
|
43
|
+
f.sync
|
44
|
+
f.close
|
45
|
+
|
46
|
+
set_mode if @mode
|
47
|
+
end
|
48
|
+
true
|
49
|
+
end
|
50
|
+
|
51
|
+
def []=(key,value)
|
52
|
+
store key, value
|
53
|
+
save! if @auto_save == true
|
54
|
+
end
|
55
|
+
# Save the hash to a file, overwriting if necessary.
|
56
|
+
def save!
|
57
|
+
delete_file
|
58
|
+
save
|
59
|
+
end
|
60
|
+
|
61
|
+
# Load the save file into self.
|
62
|
+
def load
|
63
|
+
self.clear
|
64
|
+
if @file && File.exist?(@file) && File.stat(@file).size > 0
|
65
|
+
h = YAML::load open(@file, 'r').read
|
66
|
+
h.each { |k,v| self[k.to_sym] = v}
|
67
|
+
return true
|
68
|
+
end
|
69
|
+
false
|
70
|
+
end
|
71
|
+
|
72
|
+
# Generate a backup file real quick.
|
73
|
+
def backup
|
74
|
+
FileUtils.cp @file, backup_file if File.file? @file
|
75
|
+
end
|
76
|
+
|
77
|
+
# Set the mode of both the save file and backup file.
|
78
|
+
def set_mode
|
79
|
+
# Why are we trying to set_mode when we don't even have a file?
|
80
|
+
return false if !@file
|
81
|
+
File.chmod @mode, @file if File.exist? @file
|
82
|
+
|
83
|
+
# the backup file may not exist for whatever reason, lets not shit if it doesn't.
|
84
|
+
return true if !backup_file
|
85
|
+
File.chmod @mode, backup_file if File.exist? backup_file
|
86
|
+
true
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
# Delete the save file.
|
92
|
+
def delete_file
|
93
|
+
return false if !@file
|
94
|
+
FileUtils.rm @file if File.file? @file
|
95
|
+
return true
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
data/lib/bini/version.rb
ADDED
data/spec/bini_spec.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# I'm not 100% sure convinvced any of these do what I think they do.
|
4
|
+
describe "Bini" do
|
5
|
+
before (:each) do
|
6
|
+
Bini.long_name = nil
|
7
|
+
@long_name = Bini.long_name
|
8
|
+
Bini.cache_dir = nil
|
9
|
+
@cache_dir = Bini.cache_dir
|
10
|
+
Bini.config_dir = nil
|
11
|
+
@config_dir = Bini.config_dir
|
12
|
+
end
|
13
|
+
|
14
|
+
# I can probably do this dynamically.
|
15
|
+
describe "long_name" do
|
16
|
+
it "can be reset" do
|
17
|
+
Bini.long_name = nil
|
18
|
+
Bini.long_name.should eq Bini.defaults[:long_name]
|
19
|
+
end
|
20
|
+
|
21
|
+
it "provides a default" do
|
22
|
+
Bini.long_name = nil
|
23
|
+
Bini.long_name.should_not be_nil
|
24
|
+
end
|
25
|
+
|
26
|
+
it "can be overridden" do
|
27
|
+
r = random_hex 4
|
28
|
+
Bini.long_name = r
|
29
|
+
Bini.long_name.should eq r
|
30
|
+
end
|
31
|
+
|
32
|
+
it "can be configured via .configure" do
|
33
|
+
r = random_hex 4
|
34
|
+
Bini.configure do |c|
|
35
|
+
c.long_name = r
|
36
|
+
end
|
37
|
+
Bini.long_name.should eq r
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "cache_dir" do
|
42
|
+
it "can be reset" do
|
43
|
+
Bini.cache_dir = nil
|
44
|
+
Bini.cache_dir.should eq @cache_dir
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
it "provides a default" do
|
49
|
+
Bini.cache_dir = nil
|
50
|
+
Bini.cache_dir.should_not be_nil
|
51
|
+
end
|
52
|
+
|
53
|
+
it "can be overridden" do
|
54
|
+
r = random_hex 4
|
55
|
+
Bini.cache_dir = r
|
56
|
+
Bini.cache_dir.should eq r
|
57
|
+
end
|
58
|
+
it "can be configured via .configure" do
|
59
|
+
r = random_hex 4
|
60
|
+
Bini.configure do |c|
|
61
|
+
c.cache_dir = r
|
62
|
+
end
|
63
|
+
Bini.cache_dir.should eq r
|
64
|
+
end
|
65
|
+
end
|
66
|
+
describe "config_dir" do
|
67
|
+
it "can be reset" do
|
68
|
+
Bini.config_dir = nil
|
69
|
+
Bini.config_dir.should eq @config_dir
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
it "provides a default" do
|
74
|
+
Bini.config_dir = nil
|
75
|
+
Bini.config_dir.should_not be_nil
|
76
|
+
end
|
77
|
+
|
78
|
+
it "can be overridden" do
|
79
|
+
r = random_hex 4
|
80
|
+
Bini.config_dir = r
|
81
|
+
Bini.config_dir.should eq r
|
82
|
+
end
|
83
|
+
it "can be configured via .configure" do
|
84
|
+
r = random_hex 4
|
85
|
+
Bini.configure do |c|
|
86
|
+
c.config_dir = r
|
87
|
+
end
|
88
|
+
Bini.config_dir.should eq r
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
data/spec/config_spec.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Bini.config" do
|
4
|
+
it "is a hash." do
|
5
|
+
Bini.config.kind_of?(Hash).should be_true
|
6
|
+
end
|
7
|
+
|
8
|
+
it "which responds to save" do
|
9
|
+
Bini.config.respond_to?(:save).should be_true
|
10
|
+
end
|
11
|
+
|
12
|
+
it "which responds to load" do
|
13
|
+
Bini.config.respond_to?(:load).should be_true
|
14
|
+
end
|
15
|
+
end
|
data/spec/mixins_spec.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "optparser" do
|
4
|
+
before (:each) do
|
5
|
+
Options.clear
|
6
|
+
@key = random_hex 4
|
7
|
+
@value = random_hex 4
|
8
|
+
end
|
9
|
+
|
10
|
+
it "behaves like a OptionParser." do
|
11
|
+
Options.kind_of? OptionParser
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "[Hash]" do
|
15
|
+
it "can clear" do
|
16
|
+
Options[:foo] = :bar
|
17
|
+
Options.clear
|
18
|
+
Options[].any?.should be_false
|
19
|
+
end
|
20
|
+
|
21
|
+
it "can set via []=" do
|
22
|
+
Options[@key] = @value
|
23
|
+
Options[@key].should eq @value
|
24
|
+
end
|
25
|
+
|
26
|
+
it "gets all keys with []" do
|
27
|
+
Options[@key] = @value
|
28
|
+
Options[].include?(@key).should be_true
|
29
|
+
end
|
30
|
+
|
31
|
+
it "gets a value with [:key]" do
|
32
|
+
Options[@key] = @value
|
33
|
+
Options[@key].should eq @value
|
34
|
+
end
|
35
|
+
|
36
|
+
it "can mash values (opposite of merge)." do
|
37
|
+
Options[:mash] = 'mush'
|
38
|
+
h = {mash:'notmush'}
|
39
|
+
Options.mash h
|
40
|
+
Options[:mash].should eq 'mush'
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
describe "parse" do
|
45
|
+
it "will attempt to mash in the Config[]#hash if available." do
|
46
|
+
Bini::config[@key] == @value
|
47
|
+
Options.parse!
|
48
|
+
Options[@key] = @value
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/spec/sash_spec.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'bini'
|
2
|
+
|
3
|
+
include Bini
|
4
|
+
|
5
|
+
describe "Sash" do
|
6
|
+
def random_file
|
7
|
+
"tmp/sash-#{(0...4).map{rand(16).to_s(16)}.join}.yaml"
|
8
|
+
end
|
9
|
+
|
10
|
+
before (:all) do
|
11
|
+
FileUtils.mkdir_p 'tmp'
|
12
|
+
end
|
13
|
+
|
14
|
+
before (:each) do
|
15
|
+
@filename = random_file
|
16
|
+
@s = Sash.new file:@filename
|
17
|
+
@s[:before_each] = true
|
18
|
+
end
|
19
|
+
|
20
|
+
after (:all) do
|
21
|
+
Dir.glob("tmp/sash-*.yaml*").each { |f| FileUtils.rm f}
|
22
|
+
end
|
23
|
+
|
24
|
+
it "can select the filename" do
|
25
|
+
@s.file.should be @filename
|
26
|
+
end
|
27
|
+
|
28
|
+
it "can save" do
|
29
|
+
@s[:foo] = :bar
|
30
|
+
@s.save
|
31
|
+
@s2 = Sash.new file:@filename
|
32
|
+
@s2.load
|
33
|
+
@s2[:foo].should eq :bar
|
34
|
+
end
|
35
|
+
it "can set the mode" do
|
36
|
+
@s.mode = 0600
|
37
|
+
@s.set_mode
|
38
|
+
@s.save
|
39
|
+
# I have no idea why you put in 0600, 0600 becomes 384, and out comes 33152.
|
40
|
+
# when I figure out where the conversion is going wrong, I'll update this.
|
41
|
+
File.stat(@s.file).mode.should eq 33152
|
42
|
+
end
|
43
|
+
|
44
|
+
it "can auto save" do
|
45
|
+
@s = Sash.new file:@filename, auto_save:true
|
46
|
+
@s[:auto_save] = true
|
47
|
+
@s2 = Sash.new file:@filename
|
48
|
+
@s2.load
|
49
|
+
@s2[:auto_save].should be true
|
50
|
+
end
|
51
|
+
|
52
|
+
it "can auto load" do
|
53
|
+
@s[:auto_load] = true
|
54
|
+
@s.save
|
55
|
+
@s2 = Sash.new file:@filename, auto_load:true
|
56
|
+
@s2[:auto_load].should be true
|
57
|
+
end
|
58
|
+
|
59
|
+
# We save twice because in order to produce a backup file, we need an original.
|
60
|
+
it "can make a backup file" do
|
61
|
+
@s.backup = true
|
62
|
+
@s[:backup] = "something"
|
63
|
+
@s.save
|
64
|
+
@s.save
|
65
|
+
File.exist?(@s.backup_file).should be_true
|
66
|
+
end
|
67
|
+
|
68
|
+
it "will behave like a normal Hash" do
|
69
|
+
@s.kind_of?(Hash).should be_true
|
70
|
+
end
|
71
|
+
|
72
|
+
it "will clear before load, destroying previous contents" do
|
73
|
+
@s[:clear] = 'clear'
|
74
|
+
@s.load
|
75
|
+
@s[:clear].should be_nil
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'bini'
|
2
|
+
require 'bini/optparser'
|
3
|
+
require 'bini/config'
|
4
|
+
|
5
|
+
include Bini
|
6
|
+
|
7
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
8
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
9
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
10
|
+
# loaded once.
|
11
|
+
#
|
12
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
15
|
+
config.run_all_when_everything_filtered = true
|
16
|
+
config.filter_run :focus
|
17
|
+
|
18
|
+
# Run specs in random order to surface order dependencies. If you find an
|
19
|
+
# order dependency and want to debug it, you can fix the order by providing
|
20
|
+
# the seed, which is printed after each run.
|
21
|
+
# --seed 1234
|
22
|
+
config.order = 'random'
|
23
|
+
end
|
24
|
+
|
25
|
+
def random_hex(size)
|
26
|
+
(0...size).map{rand(16).to_s(16)}.join
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bini
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ernie Brodeur
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sys-proctable
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: Bini needs no description.
|
31
|
+
email:
|
32
|
+
- ebrodeur@ujami.net
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- .rspec
|
39
|
+
- .travis.yml
|
40
|
+
- Gemfile
|
41
|
+
- LICENSE.txt
|
42
|
+
- README.md
|
43
|
+
- Rakefile
|
44
|
+
- bini.gemspec
|
45
|
+
- lib/bini.rb
|
46
|
+
- lib/bini/config.rb
|
47
|
+
- lib/bini/filemagic.rb
|
48
|
+
- lib/bini/mixins.rb
|
49
|
+
- lib/bini/optparser.rb
|
50
|
+
- lib/bini/sash.rb
|
51
|
+
- lib/bini/version.rb
|
52
|
+
- spec/bini_spec.rb
|
53
|
+
- spec/config_spec.rb
|
54
|
+
- spec/filemagic_spec.rb
|
55
|
+
- spec/mixins_spec.rb
|
56
|
+
- spec/optparser_spec.rb
|
57
|
+
- spec/sash_spec.rb
|
58
|
+
- spec/spec_helper.rb
|
59
|
+
homepage: https://github.com/erniebrodeur/bini
|
60
|
+
licenses: []
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
hash: -247432938325807426
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
segments:
|
81
|
+
- 0
|
82
|
+
hash: -247432938325807426
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 1.8.21
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: Bini is a gem that helps me build CLI tools. It's not thor, trollop, or
|
89
|
+
any of the other major frameworks. It makes lots and lots of assumptions. It's
|
90
|
+
probably not for you.
|
91
|
+
test_files:
|
92
|
+
- spec/bini_spec.rb
|
93
|
+
- spec/config_spec.rb
|
94
|
+
- spec/filemagic_spec.rb
|
95
|
+
- spec/mixins_spec.rb
|
96
|
+
- spec/optparser_spec.rb
|
97
|
+
- spec/sash_spec.rb
|
98
|
+
- spec/spec_helper.rb
|