user_config 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -3,6 +3,9 @@ require 'yaml'
3
3
  require 'pathname'
4
4
 
5
5
  class UserConfig
6
+ class DirectoryExistenceError < StandardError
7
+ end
8
+
6
9
  def self.default_value
7
10
  unless @default_value
8
11
  @default_value = {}
@@ -20,10 +23,16 @@ class UserConfig
20
23
  # opts[:home] is root directory, of which default value is ENV['HOME'].
21
24
  # opts[:permission] is a file permission of the configuration directory,
22
25
  # of which default value is 0700.
26
+ # If opts[:new_directory] is true and the directory exists
27
+ # then an error raises.
23
28
  def initialize(directory_name, opts = {})
24
29
  @directory = File.expand_path(File.join(opts[:home] || ENV['HOME'], directory_name))
25
30
  @file = {}
26
- unless File.exist?(@directory)
31
+ if File.exist?(@directory)
32
+ if opts[:new_directory]
33
+ raise UserConfig::DirectoryExistenceError, "Can not create new directory: #{@directory}"
34
+ end
35
+ else
27
36
  FileUtils.mkdir_p(@directory)
28
37
  FileUtils.chmod(opts[:permission] || 0700, @directory)
29
38
  end
@@ -20,6 +20,13 @@ describe UserConfig do
20
20
  uconf.directory.should == File.expand_path(File.join(@home, 'dir1'))
21
21
  end
22
22
 
23
+ it "should raise error" do
24
+ UserConfig.new('dir1', :home => @home)
25
+ lambda do
26
+ uconf = UserConfig.new('dir1', :home => @home, :new_directory => true)
27
+ end.should raise_error UserConfig::DirectoryExistenceError
28
+ end
29
+
23
30
  it "should create directory" do
24
31
  uconf = UserConfig.new('dir2', :home => @home)
25
32
  File.exist?(File.join(@home, 'dir2')).should be_true
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{user_config}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Takayuki YAMAGUCHI"]
12
- s.date = %q{2011-07-03}
12
+ s.date = %q{2011-07-08}
13
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
14
  s.email = %q{d@ytak.info}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: user_config
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Takayuki YAMAGUCHI
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-07-03 00:00:00 +09:00
13
+ date: 2011-07-08 00:00:00 +09:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -105,7 +105,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
105
105
  requirements:
106
106
  - - ">="
107
107
  - !ruby/object:Gem::Version
108
- hash: 2431112138724354384
108
+ hash: -3256709702624192472
109
109
  segments:
110
110
  - 0
111
111
  version: "0"