user_config 0.0.2 → 0.0.3
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 +9 -0
- data/Gemfile +2 -12
- data/Rakefile +1 -33
- data/lib/user_config/version.rb +3 -0
- data/lib/user_config.rb +22 -7
- data/spec/user_config_spec.rb +33 -2
- data/user_config.gemspec +18 -57
- metadata +43 -86
data/.gitignore
ADDED
data/Gemfile
CHANGED
@@ -1,14 +1,4 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
|
-
# Add dependencies required to use your gem here.
|
3
|
-
# Example:
|
4
|
-
# gem "activesupport", ">= 2.3.5"
|
5
2
|
|
6
|
-
#
|
7
|
-
|
8
|
-
group :development do
|
9
|
-
gem "rspec", ">= 2.6.0"
|
10
|
-
gem "yard", ">= 0.7.2"
|
11
|
-
gem "bundler", ">= 1.0.0"
|
12
|
-
gem "jeweler", ">= 1.6.2"
|
13
|
-
gem "rcov", ">= 0"
|
14
|
-
end
|
3
|
+
# Specify your gem's dependencies in user_config.gemspec
|
4
|
+
gemspec
|
data/Rakefile
CHANGED
@@ -1,29 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'bundler'
|
5
|
-
begin
|
6
|
-
Bundler.setup(:default, :development)
|
7
|
-
rescue Bundler::BundlerError => e
|
8
|
-
$stderr.puts e.message
|
9
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
-
exit e.status_code
|
11
|
-
end
|
12
|
-
require 'rake'
|
13
|
-
|
14
|
-
require 'jeweler'
|
15
|
-
Jeweler::Tasks.new do |gem|
|
16
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
-
gem.name = "user_config"
|
18
|
-
gem.homepage = "http://github.com/ytaka/user_config"
|
19
|
-
gem.license = "GPLv3"
|
20
|
-
gem.summary = "Management of configuration files in a user's home directory"
|
21
|
-
gem.description = "The library creates, saves, and loads configuration files, which are in a user's home directory or a specified directory."
|
22
|
-
gem.email = "d@ytak.info"
|
23
|
-
gem.authors = ["Takayuki YAMAGUCHI"]
|
24
|
-
# dependencies defined in Gemfile
|
25
|
-
end
|
26
|
-
Jeweler::RubygemsDotOrgTasks.new
|
1
|
+
require "bundler/gem_tasks"
|
27
2
|
|
28
3
|
require 'rspec/core'
|
29
4
|
require 'rspec/core/rake_task'
|
@@ -31,12 +6,5 @@ RSpec::Core::RakeTask.new(:spec) do |spec|
|
|
31
6
|
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
7
|
end
|
33
8
|
|
34
|
-
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
-
spec.rcov = true
|
37
|
-
end
|
38
|
-
|
39
|
-
task :default => :spec
|
40
|
-
|
41
9
|
require 'yard'
|
42
10
|
YARD::Rake::YardocTask.new
|
data/lib/user_config.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
require 'yaml'
|
3
3
|
require 'pathname'
|
4
|
+
require 'user_config/version'
|
4
5
|
|
5
6
|
class UserConfig
|
6
7
|
class DirectoryExistenceError < StandardError
|
@@ -38,11 +39,15 @@ class UserConfig
|
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
41
|
-
def file_path(path)
|
42
|
+
def file_path(path, create_directory = nil)
|
42
43
|
if Pathname(path).absolute?
|
43
44
|
raise ArgumentError, "Path '#{path}' is absolute."
|
44
45
|
end
|
45
|
-
File.join(@directory, path)
|
46
|
+
fpath = File.join(@directory, path)
|
47
|
+
if create_directory && !File.exist?((dir = File.dirname(fpath)))
|
48
|
+
FileUtils.mkdir_p(dir)
|
49
|
+
end
|
50
|
+
fpath
|
46
51
|
end
|
47
52
|
|
48
53
|
def default_value(path)
|
@@ -132,17 +137,15 @@ class UserConfig
|
|
132
137
|
|
133
138
|
# Open file of +path+ with +mode+.
|
134
139
|
def open(path, mode, &block)
|
135
|
-
|
136
|
-
|
137
|
-
FileUtils.mkdir_p(dir)
|
138
|
-
end
|
139
|
-
f = Kernel.open(fpath, mode)
|
140
|
+
full_path = file_path(path, true)
|
141
|
+
f = Kernel.open(full_path, mode)
|
140
142
|
if block_given?
|
141
143
|
begin
|
142
144
|
yield(f)
|
143
145
|
ensure
|
144
146
|
f.close
|
145
147
|
end
|
148
|
+
full_path
|
146
149
|
else
|
147
150
|
f
|
148
151
|
end
|
@@ -186,6 +189,10 @@ class UserConfig
|
|
186
189
|
YAML.dump(@cache)
|
187
190
|
end
|
188
191
|
|
192
|
+
def to_hash
|
193
|
+
@cache
|
194
|
+
end
|
195
|
+
|
189
196
|
# Save cached values to the path of file.
|
190
197
|
def save
|
191
198
|
unless File.exist?((dir = File.dirname(path)))
|
@@ -203,5 +210,13 @@ class UserConfig
|
|
203
210
|
def []=(key, val)
|
204
211
|
@cache[key] = val
|
205
212
|
end
|
213
|
+
|
214
|
+
def delete(key)
|
215
|
+
@cache.delete(key)
|
216
|
+
end
|
217
|
+
|
218
|
+
def set?(key)
|
219
|
+
@cache.has_key?(key)
|
220
|
+
end
|
206
221
|
end
|
207
222
|
end
|
data/spec/user_config_spec.rb
CHANGED
@@ -37,6 +37,18 @@ describe UserConfig do
|
|
37
37
|
uconf.file_path('path.yaml').should == File.join(@home, 'dir3', 'path.yaml')
|
38
38
|
end
|
39
39
|
|
40
|
+
it "should create parent directory" do
|
41
|
+
uconf = UserConfig.new('dir4', :home => @home)
|
42
|
+
uconf.file_path('path/to/file.yaml', true)
|
43
|
+
File.exist?(uconf.file_path('path/to')).should be_true
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should create without parent directory" do
|
47
|
+
uconf = UserConfig.new('dir5', :home => @home)
|
48
|
+
uconf.file_path('path/to/file.yaml')
|
49
|
+
File.exist?(uconf.file_path('path/to')).should be_false
|
50
|
+
end
|
51
|
+
|
40
52
|
it "should raise error" do
|
41
53
|
lambda do
|
42
54
|
subject.file_path('/abc/def.yaml')
|
@@ -102,6 +114,23 @@ describe UserConfig do
|
|
102
114
|
File.read(full_path).should match(/^third/)
|
103
115
|
end
|
104
116
|
|
117
|
+
it "should check set." do
|
118
|
+
yaml_path = 'set/test.yaml'
|
119
|
+
yaml = subject[yaml_path]
|
120
|
+
lambda do
|
121
|
+
yaml['key'] = 'value'
|
122
|
+
end.should change { yaml.set?('key') }
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should delete value of key." do
|
126
|
+
yaml_path = 'delete/test.yaml'
|
127
|
+
yaml = subject[yaml_path]
|
128
|
+
yaml['to_be_deleted'] = 123
|
129
|
+
lambda do
|
130
|
+
yaml.delete('to_be_deleted')
|
131
|
+
end.should change { yaml.set?('to_be_deleted') }
|
132
|
+
end
|
133
|
+
|
105
134
|
it "should return false" do
|
106
135
|
subject.exist?('not_exist/file.yaml').should_not be_true
|
107
136
|
end
|
@@ -145,20 +174,22 @@ describe UserConfig do
|
|
145
174
|
|
146
175
|
it "should save a raw file" do
|
147
176
|
path ='save/raw/hello.txt'
|
148
|
-
subject.open(path, 'w') do |f|
|
177
|
+
full_path = subject.open(path, 'w') do |f|
|
149
178
|
f.puts 'hello world'
|
150
179
|
end
|
151
180
|
fpath = File.join(subject.directory, path)
|
181
|
+
full_path.should == fpath
|
152
182
|
File.exist?(fpath).should be_true
|
153
183
|
File.read(fpath).strip.should == 'hello world'
|
154
184
|
end
|
155
185
|
|
156
186
|
it "should read a file" do
|
157
187
|
path ='save/raw/hello.txt'
|
158
|
-
subject.open(path, 'w') do |f|
|
188
|
+
full_path = subject.open(path, 'w') do |f|
|
159
189
|
f.puts 'hello world'
|
160
190
|
end
|
161
191
|
fpath = File.join(subject.directory, path)
|
192
|
+
full_path.should == fpath
|
162
193
|
subject.read(path).should == File.read(fpath)
|
163
194
|
end
|
164
195
|
|
data/user_config.gemspec
CHANGED
@@ -1,64 +1,25 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "user_config/version"
|
5
4
|
|
6
5
|
Gem::Specification.new do |s|
|
7
|
-
s.name
|
8
|
-
s.version
|
6
|
+
s.name = "user_config"
|
7
|
+
s.version = UserConfig::VERSION
|
8
|
+
s.authors = ["Takayuki YAMAGUCHI"]
|
9
|
+
s.email = ["d@ytak.info"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = "Management of configuration files in a user's home directory"
|
12
|
+
s.description = "The library creates, saves, and loads configuration files, which are in a user's home directory or a specified directory."
|
9
13
|
|
10
|
-
s.
|
11
|
-
s.authors = ["Takayuki YAMAGUCHI"]
|
12
|
-
s.date = %q{2011-07-08}
|
13
|
-
s.description = %q{The library creates, saves, and loads configuration files, which are in a user's home directory or a specified directory.}
|
14
|
-
s.email = %q{d@ytak.info}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE.txt",
|
17
|
-
"README.md"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".document",
|
21
|
-
".rspec",
|
22
|
-
"Gemfile",
|
23
|
-
"LICENSE.txt",
|
24
|
-
"README.md",
|
25
|
-
"Rakefile",
|
26
|
-
"VERSION",
|
27
|
-
"lib/user_config.rb",
|
28
|
-
"spec/spec_helper.rb",
|
29
|
-
"spec/user_config_spec.rb",
|
30
|
-
"spec/yaml/test_load.yaml",
|
31
|
-
"spec/yaml_file_spec.rb",
|
32
|
-
"user_config.gemspec"
|
33
|
-
]
|
34
|
-
s.homepage = %q{http://github.com/ytaka/user_config}
|
35
|
-
s.licenses = ["GPLv3"]
|
36
|
-
s.require_paths = ["lib"]
|
37
|
-
s.rubygems_version = %q{1.6.2}
|
38
|
-
s.summary = %q{Management of configuration files in a user's home directory}
|
14
|
+
s.rubyforge_project = "user_config"
|
39
15
|
|
40
|
-
|
41
|
-
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
42
20
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
s.add_development_dependency(%q<jeweler>, [">= 1.6.2"])
|
48
|
-
s.add_development_dependency(%q<rcov>, [">= 0"])
|
49
|
-
else
|
50
|
-
s.add_dependency(%q<rspec>, [">= 2.6.0"])
|
51
|
-
s.add_dependency(%q<yard>, [">= 0.7.2"])
|
52
|
-
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
53
|
-
s.add_dependency(%q<jeweler>, [">= 1.6.2"])
|
54
|
-
s.add_dependency(%q<rcov>, [">= 0"])
|
55
|
-
end
|
56
|
-
else
|
57
|
-
s.add_dependency(%q<rspec>, [">= 2.6.0"])
|
58
|
-
s.add_dependency(%q<yard>, [">= 0.7.2"])
|
59
|
-
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
60
|
-
s.add_dependency(%q<jeweler>, [">= 1.6.2"])
|
61
|
-
s.add_dependency(%q<rcov>, [">= 0"])
|
62
|
-
end
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
s.add_development_dependency "rspec"
|
23
|
+
s.add_development_dependency "yard"
|
24
|
+
# s.add_runtime_dependency "rest-client"
|
63
25
|
end
|
64
|
-
|
metadata
CHANGED
@@ -1,84 +1,48 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: user_config
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
4
5
|
prerelease:
|
5
|
-
version: 0.0.2
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Takayuki YAMAGUCHI
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
dependencies:
|
16
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-09-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
17
15
|
name: rspec
|
18
|
-
requirement: &
|
16
|
+
requirement: &19641620 !ruby/object:Gem::Requirement
|
19
17
|
none: false
|
20
|
-
requirements:
|
21
|
-
- -
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version:
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
24
22
|
type: :development
|
25
23
|
prerelease: false
|
26
|
-
version_requirements: *
|
27
|
-
- !ruby/object:Gem::Dependency
|
24
|
+
version_requirements: *19641620
|
25
|
+
- !ruby/object:Gem::Dependency
|
28
26
|
name: yard
|
29
|
-
requirement: &
|
27
|
+
requirement: &19641160 !ruby/object:Gem::Requirement
|
30
28
|
none: false
|
31
|
-
requirements:
|
32
|
-
- -
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: 0
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
35
33
|
type: :development
|
36
34
|
prerelease: false
|
37
|
-
version_requirements: *
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
requirements:
|
43
|
-
- - ">="
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: 1.0.0
|
46
|
-
type: :development
|
47
|
-
prerelease: false
|
48
|
-
version_requirements: *id003
|
49
|
-
- !ruby/object:Gem::Dependency
|
50
|
-
name: jeweler
|
51
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
-
none: false
|
53
|
-
requirements:
|
54
|
-
- - ">="
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: 1.6.2
|
57
|
-
type: :development
|
58
|
-
prerelease: false
|
59
|
-
version_requirements: *id004
|
60
|
-
- !ruby/object:Gem::Dependency
|
61
|
-
name: rcov
|
62
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
63
|
-
none: false
|
64
|
-
requirements:
|
65
|
-
- - ">="
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version: "0"
|
68
|
-
type: :development
|
69
|
-
prerelease: false
|
70
|
-
version_requirements: *id005
|
71
|
-
description: The library creates, saves, and loads configuration files, which are in a user's home directory or a specified directory.
|
72
|
-
email: d@ytak.info
|
35
|
+
version_requirements: *19641160
|
36
|
+
description: The library creates, saves, and loads configuration files, which are
|
37
|
+
in a user's home directory or a specified directory.
|
38
|
+
email:
|
39
|
+
- d@ytak.info
|
73
40
|
executables: []
|
74
|
-
|
75
41
|
extensions: []
|
76
|
-
|
77
|
-
|
78
|
-
- LICENSE.txt
|
79
|
-
- README.md
|
80
|
-
files:
|
42
|
+
extra_rdoc_files: []
|
43
|
+
files:
|
81
44
|
- .document
|
45
|
+
- .gitignore
|
82
46
|
- .rspec
|
83
47
|
- Gemfile
|
84
48
|
- LICENSE.txt
|
@@ -86,41 +50,34 @@ files:
|
|
86
50
|
- Rakefile
|
87
51
|
- VERSION
|
88
52
|
- lib/user_config.rb
|
53
|
+
- lib/user_config/version.rb
|
89
54
|
- spec/spec_helper.rb
|
90
55
|
- spec/user_config_spec.rb
|
91
56
|
- spec/yaml/test_load.yaml
|
92
57
|
- spec/yaml_file_spec.rb
|
93
58
|
- user_config.gemspec
|
94
|
-
|
95
|
-
|
96
|
-
licenses:
|
97
|
-
- GPLv3
|
59
|
+
homepage: ''
|
60
|
+
licenses: []
|
98
61
|
post_install_message:
|
99
62
|
rdoc_options: []
|
100
|
-
|
101
|
-
require_paths:
|
63
|
+
require_paths:
|
102
64
|
- lib
|
103
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
66
|
none: false
|
105
|
-
requirements:
|
106
|
-
- -
|
107
|
-
- !ruby/object:Gem::Version
|
108
|
-
|
109
|
-
|
110
|
-
- 0
|
111
|
-
version: "0"
|
112
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
72
|
none: false
|
114
|
-
requirements:
|
115
|
-
- -
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version:
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
118
77
|
requirements: []
|
119
|
-
|
120
|
-
|
121
|
-
rubygems_version: 1.6.2
|
78
|
+
rubyforge_project: user_config
|
79
|
+
rubygems_version: 1.8.5
|
122
80
|
signing_key:
|
123
81
|
specification_version: 3
|
124
82
|
summary: Management of configuration files in a user's home directory
|
125
83
|
test_files: []
|
126
|
-
|