gem_configurator 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.md +50 -2
- data/lib/gem_configurator/version.rb +1 -1
- data/lib/gem_configurator.rb +3 -5
- metadata +4 -4
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# GemConfigurator
|
2
2
|
|
3
|
-
|
3
|
+
Provides a simple, uniform way to configure a gem with a yaml file. Designed to work within a Rails app.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,7 +18,55 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
Include the module into a class that you wish to configure via YAML.
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
class Foo
|
25
|
+
include GemConfigurator
|
26
|
+
|
27
|
+
def initialize()
|
28
|
+
configure
|
29
|
+
...
|
30
|
+
end
|
31
|
+
|
32
|
+
...
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
Within your rails app, place a config file in the /config directory. The config file's name must match the class's name. For example, to configure Foo, name the file foo.yml.
|
37
|
+
|
38
|
+
Example yaml file:
|
39
|
+
|
40
|
+
```yaml
|
41
|
+
development:
|
42
|
+
[setting name]: [setting value]
|
43
|
+
...
|
44
|
+
|
45
|
+
test:
|
46
|
+
...
|
47
|
+
```
|
48
|
+
|
49
|
+
On instantiation, the settings for your current environment are placed in an instance variable called @settings. Retrieve the settings with `@settings[:setting_name]`
|
50
|
+
|
51
|
+
### Default Settings
|
52
|
+
|
53
|
+
If you want your object to have default settings, simply define a `default_settings` instance method.
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
class Foo
|
57
|
+
include GemConfigurator
|
58
|
+
|
59
|
+
def initialize()
|
60
|
+
configure
|
61
|
+
...
|
62
|
+
end
|
63
|
+
|
64
|
+
def defualt_settings
|
65
|
+
{:setting_name => setting_value}
|
66
|
+
end
|
67
|
+
```
|
68
|
+
|
69
|
+
Default settings will be merged with any settings defined in the YAML file. YAML file settings will overwrite a default setting of the same name.
|
22
70
|
|
23
71
|
## Contributing
|
24
72
|
|
data/lib/gem_configurator.rb
CHANGED
@@ -2,9 +2,11 @@ require "gem_configurator/version"
|
|
2
2
|
require 'active_support/inflector'
|
3
3
|
|
4
4
|
module GemConfigurator
|
5
|
-
|
5
|
+
|
6
6
|
attr_reader :settings
|
7
7
|
|
8
|
+
private
|
9
|
+
|
8
10
|
def config_path
|
9
11
|
config_file_name = "#{self.class.to_s.underscore}.yml"
|
10
12
|
if defined?(Rails) && File.exists?(Rails.root.join("config",config_file_name))
|
@@ -30,10 +32,6 @@ module GemConfigurator
|
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
33
|
-
def test
|
34
|
-
self.private_methods.sort
|
35
|
-
end
|
36
|
-
|
37
35
|
def parse_yaml(path)
|
38
36
|
path ? YAML.load_file(path) : nil
|
39
37
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gem_configurator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-27 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: active_support
|
16
|
-
requirement: &
|
16
|
+
requirement: &2164680820 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: 3.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2164680820
|
25
25
|
description: Implements a standard way of using yml files to configure gems.
|
26
26
|
email:
|
27
27
|
- ian@ianwhitney.com
|