configue 0.1.2 → 0.1.3
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 +4 -4
- data/README.md +29 -0
- data/configue.gemspec +2 -2
- data/lib/configue/container.rb +6 -7
- data/lib/configue/importer.rb +38 -0
- data/lib/configue/node.rb +30 -4
- data/lib/configue/setting.rb +15 -0
- data/lib/configue.rb +1 -1
- data/spec/samples/triple_yaml/base.yml +10 -0
- data/spec/samples/triple_yaml/development.yml +5 -0
- data/spec/samples/triple_yaml/production.yml +5 -0
- data/spec/samples/triple_yaml_conf.rb +10 -0
- metadata +11 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86aff7ac75739e3642c097da1e578ba446fb9cdf
|
4
|
+
data.tar.gz: 13da63cb35000679ab923d6de5f608ca61f97623
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73a694a548c2e4a3d0f0e6d5ddb45af82759281289ad18ddb5b22e11415d634cf0df90890841872ac217bf4fc8adc6787587420042645ee2e0a3bfd37455b594
|
7
|
+
data.tar.gz: 91a904450a5a18a26eacef5910289a2aebdf2e30e4198b6d521cd37049f2a0e573ef1105cf538d84b68718ffece338e6be652d878cfc20f69c54ac218b492f7d
|
data/README.md
CHANGED
@@ -50,6 +50,7 @@ accounts:
|
|
50
50
|
You can specify `namespace` and `base_namespace`.
|
51
51
|
|
52
52
|
When you write settings as follows:
|
53
|
+
|
53
54
|
```yaml
|
54
55
|
# config/settings/base.yml
|
55
56
|
base:
|
@@ -99,3 +100,31 @@ you can access it in the following manner:
|
|
99
100
|
>> MyConf.foo.baz
|
100
101
|
=> ["one", "two", "three"]
|
101
102
|
```
|
103
|
+
|
104
|
+
### source_file
|
105
|
+
You can specify files that you want to load into your class in the following manner:
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
class MyConf < Configue::Container
|
109
|
+
config.source_file "#{File.dirname(__FILE__)}/config/settings/base.yml"
|
110
|
+
config.source_file "#{File.dirname(__FILE__)}/config/settings/dev.yml"
|
111
|
+
config.source_file "#{File.dirname(__FILE__)}/config/settings/test.yml"
|
112
|
+
|
113
|
+
...
|
114
|
+
```
|
115
|
+
|
116
|
+
### import_config
|
117
|
+
You can import a configuration into an object as one of its attributes without
|
118
|
+
defining a class for that.
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
class Foo
|
122
|
+
include Configue::Importer
|
123
|
+
import_config from_dir: "#{File.dirname(__FILE__)}/config/settings",
|
124
|
+
as: :settings,
|
125
|
+
namespace: :dev
|
126
|
+
...
|
127
|
+
def foo
|
128
|
+
if settings.foo.baa == ...
|
129
|
+
...
|
130
|
+
```
|
data/configue.gemspec
CHANGED
@@ -12,8 +12,8 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.files = `git ls-files`.split("\n")
|
13
13
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
14
|
s.require_paths = ["lib"]
|
15
|
-
s.version = "0.1.
|
16
|
-
s.license = "MIT"
|
15
|
+
s.version = "0.1.3"
|
16
|
+
s.license = "MIT"
|
17
17
|
|
18
18
|
s.add_development_dependency 'rspec'
|
19
19
|
end
|
data/lib/configue/container.rb
CHANGED
@@ -4,8 +4,6 @@ require "configue/container_adapter"
|
|
4
4
|
require "configue/criteria"
|
5
5
|
|
6
6
|
module Configue
|
7
|
-
# +Configue::Container+ is a setting solution using a YAML file.
|
8
|
-
#
|
9
7
|
# When you have such configuration files:
|
10
8
|
#
|
11
9
|
# # config/accounts/admin_users.yml
|
@@ -20,7 +18,7 @@ module Configue
|
|
20
18
|
# - sleepy
|
21
19
|
# - dopey
|
22
20
|
#
|
23
|
-
#
|
21
|
+
# you can load them into your class in the following ways:
|
24
22
|
#
|
25
23
|
# class Foo < Configue::Container
|
26
24
|
# config.source_dir "#{File.dirname(__FILE__)}/config"
|
@@ -34,9 +32,9 @@ module Configue
|
|
34
32
|
#
|
35
33
|
class Container < Node
|
36
34
|
|
37
|
-
# When you do not know
|
38
|
-
# specify and want to avoid +NoMethodError+,
|
39
|
-
# +query+ and +retrieve+.
|
35
|
+
# When you do not know whether your setting object has keys
|
36
|
+
# that you want to specify and want to avoid +NoMethodError+,
|
37
|
+
# you can use +query+ and +retrieve+.
|
40
38
|
#
|
41
39
|
# Foo.query("accounts.admin_users").retrieve
|
42
40
|
# # => ["grumpy", "sneezy"]
|
@@ -54,12 +52,13 @@ module Configue
|
|
54
52
|
end
|
55
53
|
|
56
54
|
class << self
|
57
|
-
# +config+ allows you to access the object for setting container.
|
55
|
+
# +config+ allows you to access the object for setting up container.
|
58
56
|
def config
|
59
57
|
@config_access_name = "config"
|
60
58
|
@setting ||= Setting.new(ContainerAdapter.new(self))
|
61
59
|
end
|
62
60
|
|
61
|
+
# +config_setting+ is the same with +config+.
|
63
62
|
def config_setting
|
64
63
|
@config_access_name = "config_setting"
|
65
64
|
@setting ||= Setting.new(ContainerAdapter.new(self))
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Configue
|
4
|
+
module Importer
|
5
|
+
def self.included(clazz)
|
6
|
+
clazz.extend(ClassMethod)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethod
|
11
|
+
# Imports a configuration as one of attributes.
|
12
|
+
#
|
13
|
+
# The following keys are available:
|
14
|
+
#
|
15
|
+
# +as+:: (required) a name of an attribute for the configuration.
|
16
|
+
# +from_dir+:: a path of a directory that the configuration file is in.
|
17
|
+
# +from_file+:: a path of the configuration file.
|
18
|
+
# +namespace+:: a name of namespace.
|
19
|
+
# +base_namespace+:: a name of base namespace.
|
20
|
+
#
|
21
|
+
def import_config(args)
|
22
|
+
raise ArgumentError unless args.respond_to?(:[])
|
23
|
+
var = args.delete(:as)
|
24
|
+
raise if var.nil?
|
25
|
+
|
26
|
+
dirs = args.delete(:from_dir)
|
27
|
+
files = args.delete(:from_file)
|
28
|
+
args[:source_dir] = dirs if dirs
|
29
|
+
args[:source_file] = files if files
|
30
|
+
|
31
|
+
config = Class.new(Container)
|
32
|
+
args.each {|k, v| config.config.__send__(k, *Array(v)) }
|
33
|
+
|
34
|
+
define_method(var, -> { config })
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/configue/node.rb
CHANGED
@@ -32,17 +32,43 @@ module Configue
|
|
32
32
|
@hash.key?(k)
|
33
33
|
end
|
34
34
|
alias_method :has_key?, :key?
|
35
|
+
alias_method :include?, :key?
|
36
|
+
alias_method :member?, :key?
|
35
37
|
|
36
|
-
def
|
37
|
-
|
38
|
+
def assoc(key)
|
39
|
+
k = key.to_s
|
40
|
+
@hash.assoc(k)
|
38
41
|
end
|
39
42
|
|
40
43
|
def to_hash
|
41
44
|
@hash.dup
|
42
45
|
end
|
43
46
|
|
44
|
-
def
|
45
|
-
|
47
|
+
def values_at(*keys)
|
48
|
+
ks = keys.map {|k| k.to_s }
|
49
|
+
@hash.values_at(*ks)
|
50
|
+
end
|
51
|
+
|
52
|
+
[ :keys,
|
53
|
+
:to_s,
|
54
|
+
:each,
|
55
|
+
:each_pair,
|
56
|
+
:each_key,
|
57
|
+
:empty?,
|
58
|
+
:value?,
|
59
|
+
:size,
|
60
|
+
:length,
|
61
|
+
:merge,
|
62
|
+
:rassoc,
|
63
|
+
:reject,
|
64
|
+
:select,
|
65
|
+
:sort,
|
66
|
+
:to_a,
|
67
|
+
:values,
|
68
|
+
].each do |m|
|
69
|
+
define_method(m, ->(*args, &block) {
|
70
|
+
@hash.__send__(m, *args, &block)
|
71
|
+
})
|
46
72
|
end
|
47
73
|
end
|
48
74
|
end
|
data/lib/configue/setting.rb
CHANGED
@@ -43,12 +43,27 @@ module Configue
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
+
# Specifies files that you want to load into your class.
|
47
|
+
#
|
48
|
+
# You can call this method many times.
|
49
|
+
#
|
50
|
+
# ====Arguments
|
51
|
+
# - +files+: files that you want to load into your class.
|
52
|
+
#
|
46
53
|
def source_file(*files)
|
47
54
|
@sources ||= []
|
48
55
|
@sources += files.map {|f| {file: f}} unless files.empty?
|
49
56
|
@sources
|
50
57
|
end
|
51
58
|
|
59
|
+
def source_file=(file)
|
60
|
+
if file.is_a?(Array)
|
61
|
+
source_file(*file)
|
62
|
+
else
|
63
|
+
source_file(file)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
52
67
|
def load!
|
53
68
|
@owner.instance ? @owner.instance : @owner.new_container(load_sources)
|
54
69
|
end
|
data/lib/configue.rb
CHANGED
@@ -0,0 +1,10 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
class TripleYamlConf < Configue::Container
|
4
|
+
config.source_file "#{File.dirname(__FILE__)}/triple_yaml/base.yml"
|
5
|
+
config.source_file "#{File.dirname(__FILE__)}/triple_yaml/production.yml"
|
6
|
+
config.source_file "#{File.dirname(__FILE__)}/triple_yaml/development.yml"
|
7
|
+
|
8
|
+
config.base_namespace :base
|
9
|
+
config.namespace :development
|
10
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hosim
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -40,6 +40,7 @@ files:
|
|
40
40
|
- lib/configue/container.rb
|
41
41
|
- lib/configue/container_adapter.rb
|
42
42
|
- lib/configue/criteria.rb
|
43
|
+
- lib/configue/importer.rb
|
43
44
|
- lib/configue/merger.rb
|
44
45
|
- lib/configue/node.rb
|
45
46
|
- lib/configue/setting.rb
|
@@ -67,6 +68,10 @@ files:
|
|
67
68
|
- spec/samples/single_source_conf.rb
|
68
69
|
- spec/samples/single_yaml/conf.yml
|
69
70
|
- spec/samples/single_yaml_conf.rb
|
71
|
+
- spec/samples/triple_yaml/base.yml
|
72
|
+
- spec/samples/triple_yaml/development.yml
|
73
|
+
- spec/samples/triple_yaml/production.yml
|
74
|
+
- spec/samples/triple_yaml_conf.rb
|
70
75
|
- spec/signs_spec.rb
|
71
76
|
- spec/spec_helper.rb
|
72
77
|
- spec/support/inner_hash.rb
|
@@ -117,6 +122,10 @@ test_files:
|
|
117
122
|
- spec/samples/single_source_conf.rb
|
118
123
|
- spec/samples/single_yaml/conf.yml
|
119
124
|
- spec/samples/single_yaml_conf.rb
|
125
|
+
- spec/samples/triple_yaml/base.yml
|
126
|
+
- spec/samples/triple_yaml/development.yml
|
127
|
+
- spec/samples/triple_yaml/production.yml
|
128
|
+
- spec/samples/triple_yaml_conf.rb
|
120
129
|
- spec/signs_spec.rb
|
121
130
|
- spec/spec_helper.rb
|
122
131
|
- spec/support/inner_hash.rb
|