yew 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YmM3YzFiOTNmYTAxYzFjODViNTIzOWJmYjlmMjUwOTJmMDNhYWE0Mg==
4
+ Yjg0MjQ2N2FkYjMyYTkyMWE4YWYxZDI3ZTQ2YWRhY2Q2ZTc0MDliOQ==
5
5
  data.tar.gz: !binary |-
6
- YTE0MWJlNjQzMTNhYjU2NjE2ZmFiMzEzM2M5Zjc5Zjc3MDM2MzI2Ng==
6
+ ODJlOTEyODk0MmQ5OTlmNTU1MTk5Y2QwMWQ5MDYxMmRjZTYzNGViZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MGI5OWFjZGQyZWU5ZTcwM2M0ZTBhNzViMDk2ODZiOTNjNzIzNDAzNTg0YTMw
10
- NzBhN2I2ODE0MjVkZjNmMjFlZmU1Y2M5MGQ0MmRhZjYwMzdjNjQ3YjRkMTg5
11
- OGM1OGEwY2E2MzZhNjM2NjhlOTRhZjcyNGJmNTRmMTM4NWVjODc=
9
+ ZTc5ODU2M2Y4ZmIyOGFhYTgxNzllNmQzMTg3M2ViNjY1MjVkYTM0NTk3YmYw
10
+ NTc1OTRiYjI3MGY4NTgxZDMxZjExNGVhYjY2NmUxNTA3NTY3ODVlNWRmMzlj
11
+ YzkyNmY1MjdlYzA4NmY4ZWE5YTVhOTY3Y2JiNGMxY2Q4YjM0MWM=
12
12
  data.tar.gz: !binary |-
13
- NTBmZGY1NTY2YzU0ZjRiMTI3OGZkMzBkNjU2NWY4MTFkOGZhNzgyNmI3NTgx
14
- N2RjMmQzYjJmNjNhZWE3YjZlMGJmMDMwNTk0ZDAyOTAyZTcxOTI1MjVkNDc4
15
- Y2EzNjQ2MTIwMmY3MzQ4YjVlZTNiMzg5NTBhYmRhYjc2YWMzN2I=
13
+ OTc3MDQxNDBlOWM2MWNkOWM1MTQ3YmIzMGMyOWI3ZmU2NjNiZmJmNjk0YmFj
14
+ NmMyMmU4NjUwZjI3OWI2MTU3ZDMxMjg2YjY4YTRlOTQ1ZTkzMjNlZTcyMWU5
15
+ Zjg2YzI0YzUzN2VmMmIzOGJhNTA4MjIyOWUyYTQ1NGJlZGQ1OTE=
data/README.md CHANGED
@@ -15,8 +15,8 @@ Given the following yml file located at `config/env.yml`:
15
15
 
16
16
  testing:
17
17
  frameworks:
18
- rspec: true
19
- minitest: false
18
+ minitest: true
19
+ rspec: false
20
20
  ```
21
21
 
22
22
 
@@ -38,7 +38,7 @@ Given the following yml file located at `config/env.yml`:
38
38
 
39
39
  ``` ruby
40
40
  Env.testing.frameworks[]
41
- # => {"rspec"=>true, "minitest"=>false}
41
+ # => {"rspec"=>false, "minitest"=>true}
42
42
  ```
43
43
 
44
44
 
data/lib/yew.rb CHANGED
@@ -26,9 +26,7 @@ module Yew
26
26
  end
27
27
 
28
28
  def method_missing(m, *attrs, &block)
29
- key = m.to_s
30
-
31
- Utils.fetch_as_tree(key, @env, @root)
29
+ Utils.fetch_as_tree(m, @env, @root)
32
30
  end
33
31
 
34
32
  if $YEW_DEBUG
@@ -45,12 +43,14 @@ module Yew
45
43
  module Utils
46
44
  def self.fetch_as_tree(key, env, root)
47
45
  value = env.fetch(key) do
48
- raise "Attribute #{key} not found at /#{root}"
46
+ env.fetch(key.to_s) do
47
+ raise "Attribute #{key} not found at /#{root}"
48
+ end
49
49
  end
50
50
 
51
51
  if value.is_a?(Hash)
52
52
  path = key
53
- path = "#{root}." + path if root
53
+ path = "#{root}.#{path}" if root
54
54
 
55
55
  Tree.new(value, path)
56
56
  else
@@ -0,0 +1,77 @@
1
+ require 'test/unit'
2
+
3
+ require 'lib/yew'
4
+
5
+ class TestYew < Test::Unit::TestCase
6
+
7
+ def setup
8
+ @hash = {
9
+ :orientdb => {
10
+ :user => 'root',
11
+ :pass => 'let-me-in'
12
+ },
13
+ 'testing' => {
14
+ 'frameworks' => {
15
+ 'rspec' => false,
16
+ 'minitest' => true
17
+ }
18
+ }
19
+ }
20
+
21
+ @tree = Yew::Tree.new(@hash)
22
+ end
23
+
24
+ def test_lookups_for_symbol_keys
25
+ user = @tree.orientdb.user
26
+
27
+ assert_equal('root', user)
28
+ end
29
+
30
+ def test_lookups_for_string_keys
31
+ minitest = @tree.testing.frameworks.minitest
32
+ rspec = @tree.testing.frameworks.rspec
33
+
34
+ assert minitest
35
+ refute rspec
36
+ end
37
+
38
+ def test_obtains_underlying_hash
39
+ testing_hash = @tree.testing[]
40
+
41
+ assert_equal(@hash['testing'], testing_hash)
42
+ end
43
+
44
+ def test_subtree_can_be_traversed_as_usual
45
+ subtree = @tree.orientdb
46
+
47
+ assert_equal('root', subtree.user)
48
+ end
49
+
50
+ def test_lookups_using_hash_semantics
51
+ user = @tree[:orientdb][:user]
52
+
53
+ assert_equal('root', user)
54
+ end
55
+
56
+ def test_subtree_can_be_obtained_using_hash_semantics
57
+ subtree = @tree[:orientdb]
58
+
59
+ assert_equal('root', subtree.user)
60
+ end
61
+
62
+ def test_raises_an_error_when_accessing_non_existing_paths
63
+ assert_raises(RuntimeError) {
64
+ @tree.orientdb.timeout
65
+ }
66
+ end
67
+
68
+ def test_raises_errors_having_meaningful_messages
69
+ e = nil
70
+
71
+ begin
72
+ @tree.orientdb.timeout
73
+ rescue StandardError => e; end
74
+
75
+ assert_match(/timeout not found at \/orientdb/, e.message)
76
+ end
77
+ end
data/test/ts_yew.rb ADDED
@@ -0,0 +1 @@
1
+ require_relative 'test_yew_tree'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yew
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
  - Gianfranco Zas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-12 00:00:00.000000000 Z
11
+ date: 2013-10-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Reads from .yml files and provides an object for key traversing.
14
14
  email: snmgian@gmail.com
@@ -20,6 +20,8 @@ files:
20
20
  - COPYING
21
21
  - COPYING.LESSER
22
22
  - README.md
23
+ - test/ts_yew.rb
24
+ - test/test_yew_tree.rb
23
25
  homepage: https://github.com/snmgian/yew
24
26
  licenses:
25
27
  - LGPL
@@ -44,5 +46,7 @@ rubygems_version: 2.1.5
44
46
  signing_key:
45
47
  specification_version: 4
46
48
  summary: Offers an object access like interface to hash structures.
47
- test_files: []
49
+ test_files:
50
+ - test/ts_yew.rb
51
+ - test/test_yew_tree.rb
48
52
  has_rdoc: