confit 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +12 -0
- data/lib/confit.rb +59 -0
- data/test/confit_test.rb +18 -0
- data/test/test.yml +4 -0
- metadata +73 -0
data/README
ADDED
data/lib/confit.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
module Confit
|
4
|
+
|
5
|
+
@@app_config = nil
|
6
|
+
@@verbose = nil
|
7
|
+
|
8
|
+
def self.verbose
|
9
|
+
@@verbose
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.confit(file=nil, env=nil, verbose=false)
|
13
|
+
|
14
|
+
@@app_config ? (return @@app_config) : @@app_config = OpenStruct.new
|
15
|
+
|
16
|
+
@@verbose = verbose ? true : false
|
17
|
+
|
18
|
+
if File.exist?(file)
|
19
|
+
yaml = env ? YAML.load_file(file)[env] : YAML.load_file(file)
|
20
|
+
yaml.each do |key, val|
|
21
|
+
@@app_config.send("#{key}=", val)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
@@app_config
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
module Kernel
|
31
|
+
|
32
|
+
def confit(file=nil, env=nil, verbose=false)
|
33
|
+
Confit::confit(file, env, verbose)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
class OpenStruct
|
39
|
+
|
40
|
+
def method_missing(mid, *args)
|
41
|
+
mname = mid.id2name
|
42
|
+
if mname !~ /=/
|
43
|
+
raise NoMethodError, "Confit variable not defined! #{mname}" if Confit.verbose
|
44
|
+
else
|
45
|
+
len = args.length
|
46
|
+
if mname.chomp!('=')
|
47
|
+
if len != 1
|
48
|
+
raise ArgumentError, "wrong number of arguments (#{len} for 1)", caller(1)
|
49
|
+
end
|
50
|
+
modifiable[new_ostruct_member(mname)] = args[0]
|
51
|
+
elsif len == 0
|
52
|
+
@table[mid]
|
53
|
+
else
|
54
|
+
raise NoMethodError, "undefined method `#{mname}' for #{self}", caller(1)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
data/test/confit_test.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.join(File.expand_path(File.join(File.dirname(__FILE__))), '..', 'lib', 'confit')
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'rubygems'
|
5
|
+
|
6
|
+
include Confit
|
7
|
+
|
8
|
+
class ConfitTest < Test::Unit::TestCase
|
9
|
+
|
10
|
+
def test_main_methods
|
11
|
+
file = File.join(File.expand_path(File.join(File.dirname(__FILE__))), '..', 'test', 'test.yml')
|
12
|
+
puts file
|
13
|
+
confit(file, 'dev', true)
|
14
|
+
|
15
|
+
assert_equal("twitterpoeks@gmail.com", confit.email)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/test/test.yml
ADDED
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: confit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jen Oslislo
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-11-13 00:00:00 -08:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: A teeny, tiny configuration manager.
|
23
|
+
email:
|
24
|
+
- twitterpoeks@gmail.com
|
25
|
+
executables: []
|
26
|
+
|
27
|
+
extensions: []
|
28
|
+
|
29
|
+
extra_rdoc_files: []
|
30
|
+
|
31
|
+
files:
|
32
|
+
- lib/confit.rb
|
33
|
+
- test/confit_test.rb
|
34
|
+
- test/test.yml
|
35
|
+
- README
|
36
|
+
has_rdoc: true
|
37
|
+
homepage: https://github.com/poeks/confit
|
38
|
+
licenses: []
|
39
|
+
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
hash: 3
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 21
|
60
|
+
segments:
|
61
|
+
- 1
|
62
|
+
- 3
|
63
|
+
- 7
|
64
|
+
version: 1.3.7
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project: confit
|
68
|
+
rubygems_version: 1.3.7
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: A teeny, tiny configuration manager.
|
72
|
+
test_files: []
|
73
|
+
|