mutaconf 0.0.4 → 0.0.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.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/mutaconf.rb +13 -1
- data/mutaconf.gemspec +2 -1
- data/spec/extract_spec.rb +38 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2969dd1b70dd7a226f8c3aeaaf4d875d75f19483
|
4
|
+
data.tar.gz: 2d7b8ac14dadaae652fc1be2fe29051d4a9601c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd5cc659aae6edc8754d1d6a31292a297e374e7b3972c96c2d6fbeae0279bcf436500ff1b7e740eed4a3a5250e2165adf604d9ba7824aa93c8fc34f00b33da91
|
7
|
+
data.tar.gz: 911e7edfb512ab75929e8b34dd3474aafb469a0f6c647e119b990691f78c243a1a60faf9c2e76d0e0c1680b3f7ad7db83053e558bdfbd7080b052337748d848b
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
data/lib/mutaconf.rb
CHANGED
@@ -1,11 +1,23 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
3
|
module Mutaconf
|
4
|
-
VERSION = '0.0.
|
4
|
+
VERSION = '0.0.5'
|
5
5
|
|
6
6
|
def self.dsl *args
|
7
7
|
DSL.new *args
|
8
8
|
end
|
9
|
+
|
10
|
+
def self.extract source, key
|
11
|
+
if source.kind_of? Hash
|
12
|
+
source[key.to_sym]
|
13
|
+
elsif source.kind_of? OpenStruct
|
14
|
+
source.send key.to_sym
|
15
|
+
elsif source.kind_of?(String) or source.kind_of?(Symbol)
|
16
|
+
source
|
17
|
+
elsif source
|
18
|
+
source.send key.to_sym
|
19
|
+
end
|
20
|
+
end
|
9
21
|
end
|
10
22
|
|
11
23
|
Dir[File.join File.dirname(__FILE__), File.basename(__FILE__, '.*'), '*.rb'].each{ |lib| require lib }
|
data/mutaconf.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "mutaconf"
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["AlphaHydrae"]
|
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
|
|
33
33
|
"lib/mutaconf/target.rb",
|
34
34
|
"mutaconf.gemspec",
|
35
35
|
"spec/block_spec.rb",
|
36
|
+
"spec/extract_spec.rb",
|
36
37
|
"spec/fixtures/eval.rb",
|
37
38
|
"spec/helper.rb",
|
38
39
|
"spec/source_spec.rb",
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe "Mutaconf.extract" do
|
4
|
+
|
5
|
+
class Source
|
6
|
+
attr_accessor :a, :c
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@a, @c = 'b', 'd'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should extract properties from a hash" do
|
14
|
+
s = { a: 'b', c: 'd' }
|
15
|
+
Mutaconf.extract(s, :a).should == 'b'
|
16
|
+
Mutaconf.extract(s, :c).should == 'd'
|
17
|
+
Mutaconf.extract(s, :e).should be_nil
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should extract properties from an open struct" do
|
21
|
+
s = OpenStruct.new a: 'b', c: 'd'
|
22
|
+
Mutaconf.extract(s, :a).should == 'b'
|
23
|
+
Mutaconf.extract(s, :c).should == 'd'
|
24
|
+
Mutaconf.extract(s, :e).should be_nil
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should extract properties from an object" do
|
28
|
+
s = Source.new
|
29
|
+
Mutaconf.extract(s, :a).should == 'b'
|
30
|
+
Mutaconf.extract(s, :c).should == 'd'
|
31
|
+
lambda{ Mutaconf.extract s, :e }.should raise_error(NoMethodError)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return a string or symbol" do
|
35
|
+
Mutaconf.extract('string', :a).should == 'string'
|
36
|
+
Mutaconf.extract(:symbol, :c).should == :symbol
|
37
|
+
end
|
38
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mutaconf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AlphaHydrae
|
@@ -146,6 +146,7 @@ files:
|
|
146
146
|
- lib/mutaconf/target.rb
|
147
147
|
- mutaconf.gemspec
|
148
148
|
- spec/block_spec.rb
|
149
|
+
- spec/extract_spec.rb
|
149
150
|
- spec/fixtures/eval.rb
|
150
151
|
- spec/helper.rb
|
151
152
|
- spec/source_spec.rb
|