asetus 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4fabf93268fce1615b09c0169c1c7b7d580ba66f
4
- data.tar.gz: c83d026f4830c955396495de0c5ff9bcb752a540
3
+ metadata.gz: 93b4b06e484007e5694fcf0a6f812f00cb4cbef0
4
+ data.tar.gz: 33f3b1205a98c67ab7c1cd7815c22c8616ee318e
5
5
  SHA512:
6
- metadata.gz: a345a668e8a0362fcb38d1257f4f49243253401d0b3d66c3959cbdfc0ce3e4d6a90b39436378f1b640904f89ecdccd8043e93f2cc48f47f20ee1738a68717382
7
- data.tar.gz: 1856d311d47d76a8eb739601d1181bb95b89a1aa68480c7eb0e0987e6d3db6715d872722df78f92ccb1f2f49abafa4936a86e4ab3d30258caa4716828278bf34
6
+ metadata.gz: 51fcad0a5a96eca586fc80af0d36ba609cc50745cdfb75cdb8774984125869870156f841eafcb48618a7ce15b22c6ebe153872f8780b79cadaf8043f0013dd6f
7
+ data.tar.gz: 2ded6f137ebbae0ba0589d1f0ef697fcf353345e7f723b13996bb52f0cffac4e63cf29155cfe24b4f7fada719da02203f9c1c45df67f2be6ab11d87f937399bd
data/asetus.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'asetus'
3
- s.version = '0.0.3'
3
+ s.version = '0.0.4'
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.authors = [ 'Saku Ytti' ]
6
6
  s.email = %w( saku@ytti.fi )
data/lib/asetus.rb CHANGED
@@ -5,6 +5,7 @@ require 'fileutils'
5
5
 
6
6
  class AsetusError < StandardError; end
7
7
  class NoName < AsetusError; end
8
+ class UnknownOption < AsetusError; end
8
9
 
9
10
  class Asetus
10
11
  CONFIG_FILE = 'config'
@@ -52,13 +53,15 @@ class Asetus
52
53
  @cfg = ConfigStruct.new
53
54
  @load = true
54
55
  @load = opts.delete(:load) if opts.has_key?(:load)
56
+ @key_to_s = opts.delete(:key_to_s)
57
+ raise UnknownOption, "option '#{opts}' not recognized" unless opts.empty?
55
58
  load :all if @load
56
59
  end
57
60
 
58
61
  def load_cfg dir
59
62
  file = File.join dir, CONFIG_FILE
60
63
  file = File.read file
61
- ConfigStruct.new from(@adapter, file)
64
+ ConfigStruct.new(from(@adapter, file), :key_to_s=>@key_to_s)
62
65
  rescue Errno::ENOENT
63
66
  ConfigStruct.new
64
67
  end
@@ -7,6 +7,7 @@ class Asetus
7
7
  if value.class == ConfigStruct
8
8
  value = value._asetus_to_hash
9
9
  end
10
+ key = key.to_s if @key_to_s
10
11
  hash[key] = value
11
12
  end
12
13
  hash
@@ -16,9 +17,22 @@ class Asetus
16
17
  @cfg.empty?
17
18
  end
18
19
 
20
+ def each &block
21
+ @cfg.each(&block)
22
+ end
23
+
24
+ def key? key
25
+ @cfg.has_key? key
26
+ end
27
+
28
+ def [] key
29
+ @cfg[key]
30
+ end
31
+
19
32
  private
20
33
 
21
- def initialize hash=nil
34
+ def initialize hash=nil, opts={}
35
+ @key_to_s = opts.delete :key_to_s
22
36
  @cfg = hash ? _asetus_from_hash(hash) : {}
23
37
  end
24
38
 
@@ -48,7 +62,7 @@ class Asetus
48
62
  cfg = {}
49
63
  hash.each do |key, value|
50
64
  if value.class == Hash
51
- value = ConfigStruct.new value
65
+ value = ConfigStruct.new value, :key_to_s=>@key_to_s
52
66
  end
53
67
  cfg[key] = value
54
68
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asetus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saku Ytti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-30 00:00:00.000000000 Z
11
+ date: 2014-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slop
@@ -59,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
59
  version: '0'
60
60
  requirements: []
61
61
  rubyforge_project: asetus
62
- rubygems_version: 2.0.7
62
+ rubygems_version: 2.0.3
63
63
  signing_key:
64
64
  specification_version: 4
65
65
  summary: configuration library