configru 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -23,13 +23,13 @@ Configru.load do
23
23
  end
24
24
  ```
25
25
 
26
- At the very least, the block passed to `Configru.load` must tell Configru
27
- which files it should load. There are two different methods of loading
28
- configuration files available.
26
+ At the very least, the block passed to `Configru.load` must tell Configru which
27
+ files it should load. There are two different methods of loading configuration
28
+ files available.
29
29
 
30
30
  #### Just load a file already!
31
31
 
32
- This is the simplest method of loading. It just loads a file, already!
32
+ This is the simplest method of loading. It just loads a file.
33
33
 
34
34
  ```ruby
35
35
  Configru.load do
@@ -49,9 +49,9 @@ end
49
49
 
50
50
  #### Cascading Loading
51
51
 
52
- This method of loading loads each file given (if it exists) and cascades
53
- their values. The values in the first given file have highest priority,
54
- and the values in the last file have lowest priority.
52
+ This method loads every file that exists in reverse order. Files listed first
53
+ overwrite the values from files listed later. (Files are listed in high to low
54
+ cascade priority)
55
55
 
56
56
  ```ruby
57
57
  Configru.load do
@@ -59,16 +59,10 @@ Configru.load do
59
59
  end
60
60
  ```
61
61
 
62
- This will load `/etc/foo.yml` first, then `~/foo.yml`. The values in
63
- `~/foo.yml` will overwrite the values in `/etc/foo.yml`. If a configuration
64
- option is omitted in `~/foo.yml`, it will default to the value in
65
- `/etc/foo.yml`.
66
-
67
62
  ### Accessing Options
68
63
 
69
- Configru aims to make accessing configuration values as simple as possible.
70
- All configuration options can be accessed as methods on the module
71
- `Configru`.
64
+ Configuration options can be accessed as methods of the `Configru` module, or
65
+ `Configru` can be used as a Hash.
72
66
 
73
67
  ##### foo.yml
74
68
  ```yaml
@@ -84,29 +78,28 @@ require 'configru'
84
78
  require 'socket'
85
79
 
86
80
  Configru.load do
87
- first_of 'foo.yml', '~/foo.yml'
81
+ just 'foo.yml'
88
82
  end
89
83
 
90
- s = TCPSocket.new(Configru.server.address, Configru.server.port)
84
+ s = TCPSocket.new(Configru.server.address, Configru['server']['port'])
91
85
  s.puts "Hello, I am #{Configru.nick}"
92
86
  ```
93
87
 
94
- Configuration options can also be accessed the old-fashioned way like a
95
- Hash. `Configru['server']['port']` is equivalent to `Configru.server.port`.
96
-
97
- Configuration optiosn with hyphens (ie. `foo-bar`) can be accessed either
98
- using the old-fashioned way (ie. `Configru['foo-bar']`), or by replacing
99
- the hyphens with underscores for the method way (ie. `Configru.foo_bar`).
88
+ Configuration options with hyphens can be accessed as methods by replacing the
89
+ hyphens with underscores.
100
90
 
101
91
  ### Defaults
102
92
 
103
- Configru's load DSL allows for setting configuration defaults.
93
+ Configru's load DSL allows for setting configuration defaults using a block.
94
+ If no configuration files are found or if the configuration file omits an
95
+ option, the values in `defaults` will be used.
96
+
104
97
 
105
98
  ```ruby
106
99
  require 'configru'
107
100
 
108
101
  Configru.load do
109
- first_of 'foo.yml', '~/foo.yml'
102
+ just 'foo.yml'
110
103
  defaults do
111
104
  nick 'Dr. Nader'
112
105
  server do
@@ -126,8 +119,25 @@ server:
126
119
  port: 1111
127
120
  ```
128
121
 
129
- If no configuration files are found or if the configuration file omits an
130
- option, the values in `defaults` will be used.
122
+ Defaults can also be set using a Hash instead of a block.
123
+
124
+ ```ruby
125
+ Configru.load do
126
+ just 'foo.yml'
127
+ defaults 'nick' => 'Dr. Nader',
128
+ 'server' => {'address' => 'abcd.com', 'port' => 1111}
129
+ end
130
+ ```
131
+
132
+ Defaults can also be loaded from a YAML file by passing the filename to
133
+ `default`.
134
+
135
+ ```ruby
136
+ Configru.load do
137
+ just 'foo.yml'
138
+ defaults 'foo.yml.dist'
139
+ end
140
+ ```
131
141
 
132
142
  ## License
133
143
 
data/lib/configru/dsl.rb CHANGED
@@ -23,9 +23,11 @@ module Configru
23
23
  @files_array = args
24
24
  end
25
25
 
26
- def defaults(hash=nil, &block)
27
- if hash
28
- @defaults_hash = hash
26
+ def defaults(arg=nil, &block)
27
+ if arg.is_a? String
28
+ @defaults_hash = YAML.load_file(arg)
29
+ elsif arg
30
+ @defaults_hash = arg
29
31
  elsif block
30
32
  @defaults_hash = HashDSL.new(block).hash
31
33
  end
@@ -1,3 +1,3 @@
1
1
  module Configru
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
7
+ - 2
8
8
  - 0
9
- version: 0.1.0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Curtis McEnroe
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-07-17 00:00:00 -04:00
17
+ date: 2011-07-19 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies: []
20
20