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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 48c32e67a2354968eb59c5e23d98eb148ee4cd40
4
- data.tar.gz: fa3d2c5b847a084389bb79ad1d0eeb6532f92d3a
3
+ metadata.gz: 2969dd1b70dd7a226f8c3aeaaf4d875d75f19483
4
+ data.tar.gz: 2d7b8ac14dadaae652fc1be2fe29051d4a9601c2
5
5
  SHA512:
6
- metadata.gz: 9015197b8f1ceaf5132f76a27f31780cff2ad956f985ba1164d8973bc3971fc7002bceab61cd7e1f9ad2589446d9ffcfd6c77d70a847eab1d3e3f079c071d5ae
7
- data.tar.gz: 28008da318804191037ae4c122d75d0662f2f36fb4648182e55ab3b92f3b7a1805281e0c35d336260552dfea5a69ac6839214f14ea8535d54e91fdf9cbfe5b1c
6
+ metadata.gz: fd5cc659aae6edc8754d1d6a31292a297e374e7b3972c96c2d6fbeae0279bcf436500ff1b7e740eed4a3a5250e2165adf604d9ba7824aa93c8fc34f00b33da91
7
+ data.tar.gz: 911e7edfb512ab75929e8b34dd3474aafb469a0f6c647e119b990691f78c243a1a60faf9c2e76d0e0c1680b3f7ad7db83053e558bdfbd7080b052337748d848b
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
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'
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.4"
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
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