fuguta 1.0.1 → 1.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 92905485ce6e06ca93109c369479aacbcc7def95
4
- data.tar.gz: 1f647bae465d7c80bdb6f5a432f8ea39f794f314
3
+ metadata.gz: dcf23c4ee6d9c6af1146a8cb392a5268720c54f3
4
+ data.tar.gz: bbf9e13a00e1a04e007d8ef2ae0142a4f6566adf
5
5
  SHA512:
6
- metadata.gz: c02eae631c8525de8dc26a8af4d7c884184818a0a607937f593a2be4571d8b1b95b7e043d2eccf020844eaf087488fd919e3337f4ef94229fcd3f4c0389adcf2
7
- data.tar.gz: 84057e454169cd33420b6e740e0a2883432deba7abcb60eb75bb0712697044e37b70fdafdbb80ada8c2a2009e4ef5b9c26e2be7085ad96991090036cdb5d9a93
6
+ metadata.gz: 7a0c305f4447833807a98f463d6e7843e9c9f854784a5f782209a57bc1bd52e12732daf9c911d6e87fdbef36a63c102913263380628b32d74555ca74c9ba8e36
7
+ data.tar.gz: 1d13e29e31dfa597f197272b32f4ff3a5716132ac40d1d48628719ac70ed8f582d3de316e7c7366ac7393ebef4ab7bcd51e7b93c54c00b8fb52b4e8d5251eaf6
@@ -0,0 +1,3 @@
1
+ pkg/
2
+ .bundle
3
+ Gemfile.lock
@@ -0,0 +1,9 @@
1
+ script: bundle exec rspec
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - ruby-head
6
+
7
+ matrix:
8
+ allow_failures:
9
+ - rvm: ruby-head
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem 'rspec'
7
+ end
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) [![Code Climate](https://codeclimate.com/github/axsh/fuguta.png)](https://codeclimate.com/github/axsh/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
@@ -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
 
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Fuguta
3
- VERSION='1.0.1'
3
+ VERSION='1.0.2'
4
4
  end
@@ -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
@@ -0,0 +1,4 @@
1
+ config.param1 = 1
2
+ config.param2 = 2
3
+
4
+ load 'test2.conf'
@@ -0,0 +1,11 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler/setup'
5
+ $:.unshift File.expand_path('../../lib', __FILE__)
6
+
7
+ require 'rspec'
8
+ require 'fuguta'
9
+
10
+ RSpec.configure do |config|
11
+ end
@@ -0,0 +1,2 @@
1
+ config.param1 = 1
2
+ config.param2 = 2
@@ -0,0 +1,2 @@
1
+ config.param1 = 10
2
+ config.param2 = 20
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.1
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-07-05 00:00:00.000000000 Z
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: {}