easyconf-rails 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/README.md +60 -0
- data/lib/easyconf-rails.rb +31 -1
- metadata +5 -4
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
easyconf-rails
|
2
|
+
==============
|
3
|
+
|
4
|
+
easyconf-rails makes customizing your Rails application easy. (Surprise!) To use
|
5
|
+
it, follow these simple steps:
|
6
|
+
|
7
|
+
1.
|
8
|
+
Add the following line to your project's `Gemfile`:
|
9
|
+
|
10
|
+
gem 'easyconf-rails'
|
11
|
+
|
12
|
+
2.
|
13
|
+
Run `bundle update`.
|
14
|
+
|
15
|
+
3.
|
16
|
+
Create a YAML file called `defaults.yml` in your project's `config`
|
17
|
+
directory. This file will contain your project's default configuration values.
|
18
|
+
Individual installations SHOULD NOT change this file. For example:
|
19
|
+
|
20
|
+
---
|
21
|
+
should_donate: 10
|
22
|
+
awesomeness:
|
23
|
+
ruby: true
|
24
|
+
rspec: true
|
25
|
+
|
26
|
+
4.
|
27
|
+
Create a YAML file called `config.yml` in your project's root directory. These
|
28
|
+
settings will take precedence over the settings in `defaults.yml`, so you should
|
29
|
+
instruct your users to change their settings here. For example:
|
30
|
+
|
31
|
+
---
|
32
|
+
should_support_easyconf: true
|
33
|
+
should_donate: 5
|
34
|
+
donate_to: 1A9hGUYswsMLNdaeH9qMrjoJKQGnYKgmT2
|
35
|
+
awesomeness:
|
36
|
+
easyconf: true
|
37
|
+
rails: true
|
38
|
+
perl: false
|
39
|
+
rspec: false
|
40
|
+
|
41
|
+
why_easyconf_is_awesome:
|
42
|
+
- its_easiness
|
43
|
+
- YAML
|
44
|
+
-
|
45
|
+
recursive_processing: true
|
46
|
+
|
47
|
+
5.
|
48
|
+
Now you're ready to use `config` in your application.
|
49
|
+
|
50
|
+
$config.should_support_easyconf # true
|
51
|
+
$config.should_donate # 5
|
52
|
+
$config.awesomeness.easyconf # true
|
53
|
+
$config.awesomeness.ruby # true
|
54
|
+
$config.awesomeness.rspec # false
|
55
|
+
$config.why_easyconf_is_awesome[0] # 'its_easiness'
|
56
|
+
$config.why_easyconf_is_awesome[2].recursive_processing # true
|
57
|
+
$config.variable_that_was_never_defined # raises NameError
|
58
|
+
|
59
|
+
# You can reload your configuration file by with .reload!.
|
60
|
+
$config.reload!
|
data/lib/easyconf-rails.rb
CHANGED
@@ -3,11 +3,34 @@ require 'ostruct'
|
|
3
3
|
# SemiOpenStruct is like OpenStruct, except that accessing an uninitialized key
|
4
4
|
# will raise a KeyError.
|
5
5
|
class SemiOpenStruct < OpenStruct
|
6
|
+
# Return the value corresponding to +key.to_sym+, or raise +KeyError+ if no
|
7
|
+
# such value exists.
|
8
|
+
def [](key)
|
9
|
+
@table.fetch(key.to_sym)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Set +key.to_sym+ to +val+.
|
13
|
+
def []=(key, val)
|
14
|
+
@table[key.to_sym] = val
|
15
|
+
end
|
16
|
+
|
6
17
|
# Return true if the given key is present.
|
7
18
|
def has_key?(key)
|
8
19
|
singleton_methods.grep(/[^=]$/).include?(key)
|
9
20
|
end
|
10
21
|
|
22
|
+
# Return a new array populated with our keys.
|
23
|
+
def keys
|
24
|
+
@table.keys
|
25
|
+
end
|
26
|
+
|
27
|
+
# Call the given block for every key and value we have.
|
28
|
+
def each # :yields: key, val
|
29
|
+
@table.each do |key, val|
|
30
|
+
yield(key, val)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
11
34
|
def method_missing(key, *val)
|
12
35
|
if key.to_s.end_with?('=') and (val.length == 1)
|
13
36
|
super(key, val.first)
|
@@ -73,7 +96,14 @@ class EasyConfRails < Rails::Railtie
|
|
73
96
|
hash_to_openstruct(merge_hashes(config_hash, defaults_hash))
|
74
97
|
end
|
75
98
|
|
76
|
-
config.
|
99
|
+
# Assign $config to the result of load_config().
|
100
|
+
def assign_config()
|
77
101
|
$config = load_config()
|
102
|
+
$config.define_singleton_method(:reload!, &method(:assign_config))
|
103
|
+
$config
|
104
|
+
end
|
105
|
+
|
106
|
+
config.before_initialize do
|
107
|
+
assign_config()
|
78
108
|
end
|
79
109
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easyconf-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.2'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -50,11 +50,11 @@ cert_chain:
|
|
50
50
|
-----END CERTIFICATE-----
|
51
51
|
|
52
52
|
'
|
53
|
-
date: 2012-
|
53
|
+
date: 2012-02-25 00:00:00.000000000 Z
|
54
54
|
dependencies:
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rails
|
57
|
-
requirement: &
|
57
|
+
requirement: &78323930 !ruby/object:Gem::Requirement
|
58
58
|
none: false
|
59
59
|
requirements:
|
60
60
|
- - ! '>='
|
@@ -62,7 +62,7 @@ dependencies:
|
|
62
62
|
version: '0'
|
63
63
|
type: :runtime
|
64
64
|
prerelease: false
|
65
|
-
version_requirements: *
|
65
|
+
version_requirements: *78323930
|
66
66
|
description: Configure Rails apps with a simple YAML file.
|
67
67
|
email: the.magical.kat@gmail.com
|
68
68
|
executables: []
|
@@ -70,6 +70,7 @@ extensions: []
|
|
70
70
|
extra_rdoc_files: []
|
71
71
|
files:
|
72
72
|
- lib/easyconf-rails.rb
|
73
|
+
- README.md
|
73
74
|
homepage: https://github.com/katmagic/easyconf-rails
|
74
75
|
licenses: []
|
75
76
|
post_install_message:
|
metadata.gz.sig
CHANGED
Binary file
|