configulations 0.1.4 → 0.1.5
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/VERSION +1 -1
- data/config/singles/first.yml +1 -0
- data/config/singles/fourth.json +1 -0
- data/config/singles/second.yml +1 -0
- data/config/singles/third.js +1 -0
- data/configulations.gemspec +7 -2
- data/lib/configulations.rb +31 -17
- data/spec/inclusive_spec.rb +40 -0
- metadata +8 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.5
|
@@ -0,0 +1 @@
|
|
1
|
+
name: "Leon"
|
@@ -0,0 +1 @@
|
|
1
|
+
{ "name": "Mike" }
|
@@ -0,0 +1 @@
|
|
1
|
+
name: "Marc"
|
@@ -0,0 +1 @@
|
|
1
|
+
{ "name": "Felix" }
|
data/configulations.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{configulations}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Leon Gersing"]
|
12
|
-
s.date = %q{2011-07-
|
12
|
+
s.date = %q{2011-07-06}
|
13
13
|
s.description = %q{Auto-create configuration objects for your applications from yml and json files.}
|
14
14
|
s.email = %q{leongersing@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -28,10 +28,15 @@ Gem::Specification.new do |s|
|
|
28
28
|
"config/development.yml",
|
29
29
|
"config/foo.json",
|
30
30
|
"config/server.yml",
|
31
|
+
"config/singles/first.yml",
|
32
|
+
"config/singles/fourth.json",
|
33
|
+
"config/singles/second.yml",
|
34
|
+
"config/singles/third.js",
|
31
35
|
"configulations.gemspec",
|
32
36
|
"lib/configulations.rb",
|
33
37
|
"lib/magic_hash.rb",
|
34
38
|
"spec/configurator_spec.rb",
|
39
|
+
"spec/inclusive_spec.rb",
|
35
40
|
"spec/magic_hash_spec.rb",
|
36
41
|
"spec/sample_spec.rb",
|
37
42
|
"spec/spec_helper.rb"
|
data/lib/configulations.rb
CHANGED
@@ -4,41 +4,55 @@ require 'magic_hash'
|
|
4
4
|
|
5
5
|
class Configulations
|
6
6
|
attr_accessor :properties
|
7
|
+
attr_accessor :include_pattern
|
7
8
|
|
8
9
|
def initialize
|
10
|
+
@include_pattern = File.expand_path(".") << "/config/**/*.{yml,json}"
|
11
|
+
find_properties
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.configure(&blk)
|
15
|
+
me = Configulations.new
|
16
|
+
blk.call(me)
|
17
|
+
me.find_properties
|
18
|
+
me
|
19
|
+
end
|
20
|
+
|
21
|
+
def find_properties
|
9
22
|
@properties = {}
|
10
23
|
@properties.extend(MagicHash)
|
11
24
|
|
12
|
-
|
13
|
-
|
25
|
+
Dir[@include_pattern].each do |file|
|
26
|
+
ext = File.extname(file)
|
27
|
+
base = File.basename(file, ext)
|
28
|
+
parser = parser_for_extname(ext)
|
29
|
+
@properties[base]= parser.send(:load, File.read(file))
|
30
|
+
end
|
14
31
|
|
15
32
|
@properties.objectify
|
16
|
-
yield self if block_given?
|
17
|
-
self
|
18
33
|
end
|
19
34
|
|
20
|
-
def
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
Dir[File.expand_path(".") << "/config/**/*.yml"].each do |yaml_file|
|
28
|
-
@properties[File.basename(yaml_file, ".yml")] = YAML.load(File.read(yaml_file))
|
35
|
+
def parser_for_extname(extname)
|
36
|
+
if(extname =~ /\.js(?:on)?/i)
|
37
|
+
return JSON
|
38
|
+
elsif(extname =~ /\.ya?ml/i)
|
39
|
+
return YAML
|
40
|
+
else
|
41
|
+
raise "Only files ending in .js, .json, .yml, .yaml have parsers at the moment."
|
29
42
|
end
|
30
43
|
end
|
31
44
|
|
32
45
|
def method_missing(message_name, *message_arguments, &optional_block)
|
33
|
-
result = properties.send message_name.to_sym, *message_arguments
|
34
|
-
return result if result
|
35
46
|
message = message_name.to_s.strip.gsub(/-/,"_")
|
36
47
|
if message =~ /=/
|
37
|
-
properties[message.gsub(/=/,"").to_sym] = message_arguments.flatten.first
|
48
|
+
@properties[message.gsub(/=/,"").to_sym] = message_arguments.flatten.first
|
38
49
|
return
|
39
50
|
elsif message =~ /\?/
|
40
|
-
return !!(properties[message.gsub(/\?/,"").to_sym])
|
51
|
+
return !!(@properties[message.gsub(/\?/,"").to_sym])
|
52
|
+
else
|
53
|
+
return @properties[message.to_sym] if @properties.has_key? message.to_sym
|
41
54
|
end
|
55
|
+
|
42
56
|
super message_name, *message_arguments, &optional_block
|
43
57
|
end
|
44
58
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
YamlSingleConfig = Configulations.configure do |config|
|
4
|
+
config.include_pattern = File.expand_path(".") << "/config/singles/*.yml"
|
5
|
+
end
|
6
|
+
|
7
|
+
JsonSingleConfig = Configulations.configure do |config|
|
8
|
+
config.include_pattern = File.expand_path(".") << "/config/singles/*.js*"
|
9
|
+
end
|
10
|
+
|
11
|
+
SingleConfig = Configulations.configure do |config|
|
12
|
+
config.include_pattern = File.expand_path(".") << "/config/singles/*.*" #DANGER WILL ROBINSON!
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "Inclusion" do
|
16
|
+
describe "yaml" do
|
17
|
+
it "finds first and second" do
|
18
|
+
YamlSingleConfig.first.name.should == "Leon"
|
19
|
+
YamlSingleConfig.second.name.should == "Marc"
|
20
|
+
lambda{ YamlSingleConfig.third }.should raise_error
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "json" do
|
25
|
+
it "finds third and fourth" do
|
26
|
+
JsonSingleConfig.third.name.should == "Felix"
|
27
|
+
JsonSingleConfig.fourth.name.should == "Mike"
|
28
|
+
lambda{ JsonSingleConfig.first }.should raise_error
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "mixing json and yml" do
|
33
|
+
it "finds eveything" do
|
34
|
+
SingleConfig.first.name.should == "Leon"
|
35
|
+
SingleConfig.second.name.should == "Marc"
|
36
|
+
SingleConfig.third.name.should == "Felix"
|
37
|
+
SingleConfig.fourth.name.should == "Mike"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: configulations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Leon Gersing
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-07-
|
13
|
+
date: 2011-07-06 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -78,10 +78,15 @@ files:
|
|
78
78
|
- config/development.yml
|
79
79
|
- config/foo.json
|
80
80
|
- config/server.yml
|
81
|
+
- config/singles/first.yml
|
82
|
+
- config/singles/fourth.json
|
83
|
+
- config/singles/second.yml
|
84
|
+
- config/singles/third.js
|
81
85
|
- configulations.gemspec
|
82
86
|
- lib/configulations.rb
|
83
87
|
- lib/magic_hash.rb
|
84
88
|
- spec/configurator_spec.rb
|
89
|
+
- spec/inclusive_spec.rb
|
85
90
|
- spec/magic_hash_spec.rb
|
86
91
|
- spec/sample_spec.rb
|
87
92
|
- spec/spec_helper.rb
|
@@ -99,7 +104,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
104
|
requirements:
|
100
105
|
- - ">="
|
101
106
|
- !ruby/object:Gem::Version
|
102
|
-
hash:
|
107
|
+
hash: 2698804338379669907
|
103
108
|
segments:
|
104
109
|
- 0
|
105
110
|
version: "0"
|