fuguta 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.travis.yml +9 -0
- data/Gemfile +7 -0
- data/README.md +3 -1
- data/lib/fuguta.rb +44 -0
- data/lib/fuguta/version.rb +1 -1
- data/spec/configuration_spec.rb +26 -0
- data/spec/nest-test1.conf +4 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/test1.conf +2 -0
- data/spec/test2.conf +2 -0
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dcf23c4ee6d9c6af1146a8cb392a5268720c54f3
|
4
|
+
data.tar.gz: bbf9e13a00e1a04e007d8ef2ae0142a4f6566adf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a0c305f4447833807a98f463d6e7843e9c9f854784a5f782209a57bc1bd52e12732daf9c911d6e87fdbef36a63c102913263380628b32d74555ca74c9ba8e36
|
7
|
+
data.tar.gz: 1d13e29e31dfa597f197272b32f4ff3a5716132ac40d1d48628719ac70ed8f582d3de316e7c7366ac7393ebef4ab7bcd51e7b93c54c00b8fb52b4e8d5251eaf6
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
Fuguta
|
2
2
|
======
|
3
3
|
|
4
|
-
[![Gem Version](https://badge.fury.io/rb/fuguta.png)](http://badge.fury.io/rb/fuguta)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/fuguta.png)](http://badge.fury.io/rb/fuguta)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/axsh/fuguta.png)](https://codeclimate.com/github/axsh/fuguta)
|
6
|
+
[![Build Status](https://travis-ci.org/axsh/fuguta.png?branch=master)](https://travis-ci.org/axsh/fuguta)
|
5
7
|
|
6
8
|
Configuration framework for Ruby programs
|
data/lib/fuguta.rb
CHANGED
@@ -45,7 +45,9 @@ module Fuguta
|
|
45
45
|
end
|
46
46
|
|
47
47
|
@conf.parse_dsl do |me|
|
48
|
+
me.instance_variable_set(:@loading_path, path.to_s)
|
48
49
|
me.instance_eval(buf, path.to_s)
|
50
|
+
me.instance_variable_set(:@loading_path, nil)
|
49
51
|
end
|
50
52
|
end
|
51
53
|
|
@@ -62,11 +64,38 @@ module Fuguta
|
|
62
64
|
def initialize(subject)
|
63
65
|
@subject = subject
|
64
66
|
@config = subject.config
|
67
|
+
@loading_path = nil
|
65
68
|
end
|
66
69
|
|
67
70
|
def config
|
68
71
|
self
|
69
72
|
end
|
73
|
+
|
74
|
+
# Load separate configuration files from the file.
|
75
|
+
#
|
76
|
+
# Load relative path file.
|
77
|
+
# ----------------
|
78
|
+
# load 'test2.conf'
|
79
|
+
#
|
80
|
+
# Load absolute path file.
|
81
|
+
# ----------------
|
82
|
+
# load '/etc/test2.conf'
|
83
|
+
def load(*paths)
|
84
|
+
l = Loader.new(@subject)
|
85
|
+
paths.each { |path|
|
86
|
+
if path =~ %r{^/}
|
87
|
+
# Load absolute path
|
88
|
+
l.load(path)
|
89
|
+
else
|
90
|
+
# Load relative path
|
91
|
+
base_conf_dir = (@loading_path.nil? ? Dir.pwd : File.dirname(@loading_path))
|
92
|
+
l.load(File.expand_path(path, base_conf_dir))
|
93
|
+
end
|
94
|
+
}
|
95
|
+
l.validate
|
96
|
+
|
97
|
+
self
|
98
|
+
end
|
70
99
|
end
|
71
100
|
|
72
101
|
module ConfigurationMethods
|
@@ -247,6 +276,21 @@ module Fuguta
|
|
247
276
|
@on_param_create_hooks.clear
|
248
277
|
end
|
249
278
|
|
279
|
+
# Load configuration file
|
280
|
+
#
|
281
|
+
# 1. Simply loads single configuration file.
|
282
|
+
# conf = ConfigurationClass.load('1.conf')
|
283
|
+
#
|
284
|
+
# 2. Loads multiple files and merge.
|
285
|
+
#
|
286
|
+
# file1.conf:
|
287
|
+
# config.param1 = 1
|
288
|
+
#
|
289
|
+
# file2.conf:
|
290
|
+
# config.param1 = 2
|
291
|
+
#
|
292
|
+
# conf = ConfigurationClass.load('file1.conf', 'file2.conf')
|
293
|
+
# conf.param1 == 2
|
250
294
|
def load(*paths)
|
251
295
|
c = self.new
|
252
296
|
|
data/lib/fuguta/version.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Fuguta::Configuration do
|
4
|
+
class Test1 < Fuguta::Configuration
|
5
|
+
param :param1
|
6
|
+
param :param2
|
7
|
+
end
|
8
|
+
|
9
|
+
it "loads conf file" do
|
10
|
+
conf = Test1.load(File.expand_path('../test1.conf', __FILE__))
|
11
|
+
expect(conf.param1).to eq(1)
|
12
|
+
expect(conf.param2).to eq(2)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "loads multiple conf files" do
|
16
|
+
conf = Test1.load(File.expand_path('../test1.conf', __FILE__), File.expand_path('../test2.conf', __FILE__))
|
17
|
+
expect(conf.param1).to eq(10)
|
18
|
+
expect(conf.param2).to eq(20)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "allows nested imports/loads" do
|
22
|
+
conf = Test1.load(File.expand_path('../nest-test1.conf', __FILE__))
|
23
|
+
expect(conf.param1).to eq(10)
|
24
|
+
expect(conf.param2).to eq(20)
|
25
|
+
end
|
26
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/spec/test1.conf
ADDED
data/spec/test2.conf
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fuguta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Axsh co. LTD
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A configuration framework for Ruby programs
|
14
14
|
email:
|
@@ -16,11 +16,19 @@ executables: []
|
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
|
+
- .gitignore
|
20
|
+
- .travis.yml
|
21
|
+
- Gemfile
|
19
22
|
- LICENSE
|
20
23
|
- README.md
|
21
24
|
- fuguta.gemspec
|
22
25
|
- lib/fuguta.rb
|
23
26
|
- lib/fuguta/version.rb
|
27
|
+
- spec/configuration_spec.rb
|
28
|
+
- spec/nest-test1.conf
|
29
|
+
- spec/spec_helper.rb
|
30
|
+
- spec/test1.conf
|
31
|
+
- spec/test2.conf
|
24
32
|
homepage: https://github.com/axsh/fuguta
|
25
33
|
licenses: []
|
26
34
|
metadata: {}
|