yew 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +53 -0
- data/lib/yew.rb +43 -9
- data/test/test_yew_tree.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MDgyM2U4N2M0NTNkZmU3MzUyZmY0MzRjYzEwMmZkZmZhZjgzYzg4NQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MDMyNzA0ZGNlNWY3NTJlMTI1YzA2NTEwOWUzMjA4YTBmOTJjYmVhZg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YzZkMWJkYjA5N2YwYTEwZjhlYTA5YmNmY2Q3NGNjYWIyMmU4ZTlkMzhlOTM5
|
10
|
+
YmY4MTg1OTBjNWNmYWZlZDkxYTNlYzUyZDU1M2UyNDFhYmJhYWY4YTMyOTIx
|
11
|
+
MmQ0YTEyNjAzYjRlOTVlOGY2ZmRlMzcwNTM5ODBiOTE3ZTdiM2E=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YmRiNzdjNjM0MjFmNTE2MjZhMzI3OTEwMmZjMWU0OWYyNjQyMDY2YTAwNGY1
|
14
|
+
NDIxNWNhZmE0YjI0YTc2NmRkNzI4M2I4NmFlNWFiMTg3NjI2NzlkNzBlN2Zi
|
15
|
+
ODBmMjBjYjZjNjc2NzRkMTQ2NjA3MTE2ZWZkOGVjZTE1YWYyZjQ=
|
data/README.md
CHANGED
@@ -86,8 +86,61 @@ There are two options for installation: packaged gem and source file.
|
|
86
86
|
curl "https://raw.github.com/snmgian/yew/master/lib/yew.rb" 2>/dev/null -o "yew.rb"
|
87
87
|
```
|
88
88
|
|
89
|
+
## Running tests
|
90
|
+
|
91
|
+
Tests are written in MiniTest. To run them all just execute the following from your command line:
|
92
|
+
|
93
|
+
``` shell
|
94
|
+
ruby -I. test/ts_yew.rb
|
95
|
+
```
|
96
|
+
|
97
|
+
## Badges
|
98
|
+
|
99
|
+
[![Build Status](https://travis-ci.org/snmgian/yew.svg?branch=master)](https://travis-ci.org/snmgian/yew) [![Code Climate](https://codeclimate.com/github/snmgian/yew.png)](https://codeclimate.com/github/snmgian/yew)
|
100
|
+
|
89
101
|
## License
|
90
102
|
|
91
103
|
This software is licensed under the [LGPL][lgpl] license.
|
92
104
|
|
93
105
|
[lgpl]: https://www.gnu.org/licenses/lgpl.html
|
106
|
+
|
107
|
+
## Art
|
108
|
+
|
109
|
+
``` markdown
|
110
|
+
|
111
|
+
.: ,~ :
|
112
|
+
+7Z?~+$Z$. .
|
113
|
+
~$ZZZZ7$OZ$.,::~:~.
|
114
|
+
.::IZ$$O8Z$ZZZ$$$7OOO7.
|
115
|
+
7$$$$Z$$OZZOZZZOOZOOZ$$$:.+,~
|
116
|
+
.. . $Z$ZZZ$$$OZZOZ$O88$OOO8OO8ZZ~
|
117
|
+
:,?$ZOOZZ88$OOZ$OOOO8OZOOOOO88OZ~+~,
|
118
|
+
.=ZZOOOOZOO8OOZOZOO8Z8OZO8OOOOO888ZZ::.
|
119
|
+
~7ZOZOOZOO8O8O8O8D8OOZOOZDDD8ZO8O888O?I
|
120
|
+
. +..$OZOOO8O88D8Z88OOD8ZOOO8OZOO8$O88OOZ$O:~. .
|
121
|
+
. .?.?+7ZZOOO8888D888DDO88888O8ZO88Z88Z888888OZ~.:.
|
122
|
+
?~7$ZZZOZOZOOO88D888ZDD888D8888888OOOOODZ8OO8OZ88OZ7$+
|
123
|
+
IZOO$OZO8ZZOOD$ZO8DZ8D88888ZD8D8OD88OO8OZOO$OOOOOO8O+:
|
124
|
+
.,.$OZOZOZZZZ88O88O88OO888ON88DO888ZD8O88~7ZOO$$Z88OOO+
|
125
|
+
~ZZ?ZZZZOZO8O8ZOZOZO888888888O8O8888D88D8~8888O88O8ZO8$.=
|
126
|
+
?ZZZ8OZOO8O8OOO8OOO8888888DD8O8O88ODO8D88DD88DZ8888O88$ZI ..
|
127
|
+
.. ?$?O8OOO8OZ8D8OZ8ZOODOOO8888D8ODZDDD8ONDO888OO8O88D8OOZOZZ7.~..
|
128
|
+
,+.7ZO8O8888O88O888888OO7?DD888888D88O8888OOOD88OZD8Z88888OOOZ+: ,
|
129
|
+
?.I$ZOO8OO8OZ88D8OO8OOO8DDZ7?88NO88O88DD888DO88888DO8888888888O8ZZO~
|
130
|
+
.I=8OOO$8$7.I$888888888D88DDDO8DO8DD8D8D8DD8DD8D88OODZD8DO88O8888O.
|
131
|
+
.$7O888888888O8888D8DOO878D88$O78888D8888?ZOO87O8888D8DD888$O8OO8OI=.
|
132
|
+
=~O8OO87O88OIDDZ7Z=?D88DZN8D8OO8O88DD88DO88O8D8ODDZDD888DO+OZ8O8O88$=:.
|
133
|
+
.:OZO7OO88$D8Z+8~8ZD$88DDNO8$8ODO,OD8DODNOZO8D8DOOO88D8OO8888888Z8ZZO.
|
134
|
+
:Z7888DD88D8DODD$D~~,Z?OONDNI?ZDDDNDD8D8D+7Z~:DD8I8888888888DO88OOO$.
|
135
|
+
.~8O8D8O88D8ZO8Z$8Z:OZO$=88DDDDDDDDOOD8DDDDDNN~~,~DD88O88DD88OZ$O+,.
|
136
|
+
.=DDNNDD88O+ZDDI88OO,,88DDDDDNDDDNN?7Z:ZDNNDN7+$+Z?8888OZO$$,.~ .
|
137
|
+
.DND+7+,,I~~=7$:Z=IO=?Z$DONDDD88OZ.:?ZNNNNDDDD8888Z7=7+I+ ,
|
138
|
+
.+=, .:=~:.II....Z8DD88DOOO:.,=+::+~8OD88OZ~=ZZ+.
|
139
|
+
.I,/ZO?7O8OZD$$Z:$: +I7+$\\7+8ZI.
|
140
|
+
//~,.==7Z?$Z$=$ ~,$ \\~.
|
141
|
+
/: ~=.7Z?OO?$$,
|
142
|
+
.-+--$-?--?--..++::=~, +7I7ZO7I7$,
|
143
|
+
,,. .,:,,=~+..??.:I?,.?+-,,-.,,../7I7ZO7I7$.,,,,..,,,..=.+~..7:7,.7.,-~.+,
|
144
|
+
../7Z+=ZZ077Z$~,,..,.,,. ,:,???+?+.:+.,.+.=I=.=:.
|
145
|
+
.... . .. .
|
146
|
+
|
data/lib/yew.rb
CHANGED
@@ -1,24 +1,43 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
|
3
3
|
module Yew
|
4
|
+
|
5
|
+
# Creates an object tree based on a given list of yml files.
|
6
|
+
#
|
7
|
+
# @param [*String] Yaml source files
|
8
|
+
#
|
9
|
+
# @return [Yew::Tree]
|
4
10
|
def self.load(*yml_files)
|
5
11
|
env_hash = yml_files.inject({}) do |memo, yml|
|
6
|
-
memo.merge!
|
12
|
+
memo.merge!(YAML.load(File.read(yml)))
|
7
13
|
end
|
8
14
|
|
9
15
|
Tree.new(env_hash)
|
10
16
|
end
|
11
17
|
|
18
|
+
# The object tree. Allows root-to-leave navigation in the form of ordinary method calls.
|
12
19
|
class Tree < BasicObject
|
20
|
+
|
21
|
+
# @param [Hash] env
|
22
|
+
# @param root Tree's root. Used for notifying a not found entry at an exact path point.
|
13
23
|
def initialize(env, root = nil)
|
14
24
|
@env = env
|
15
25
|
@root = root
|
16
26
|
end
|
17
27
|
|
28
|
+
# Fetches a branch or leaf.
|
29
|
+
#
|
30
|
+
# If no key is received, returns the underlying Hash.
|
31
|
+
#
|
32
|
+
# @param key Node's name.
|
33
|
+
#
|
34
|
+
# @return [Yew::Tree] When the request node is still a tree.
|
35
|
+
# @return [Hash] Underlying Hash.
|
36
|
+
# @return [Object] When the requested node is a leaf.
|
18
37
|
def [](*key)
|
19
38
|
if key.any?
|
20
39
|
key = key.first
|
21
|
-
Utils.
|
40
|
+
Utils.fetch(key, @env, @root)
|
22
41
|
|
23
42
|
else
|
24
43
|
@env
|
@@ -26,9 +45,10 @@ module Yew
|
|
26
45
|
end
|
27
46
|
|
28
47
|
def method_missing(m, *attrs, &block)
|
29
|
-
Utils.
|
48
|
+
Utils.fetch(m, @env, @root)
|
30
49
|
end
|
31
50
|
|
51
|
+
# Define methods for printing inspection.
|
32
52
|
if $YEW_DEBUG
|
33
53
|
def inspect
|
34
54
|
"<Envy::Env:#{__id__} -> #@env>"
|
@@ -41,12 +61,15 @@ module Yew
|
|
41
61
|
end
|
42
62
|
|
43
63
|
module Utils
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
64
|
+
|
65
|
+
# Fetches the key's value.
|
66
|
+
#
|
67
|
+
# Returns a tree if the value is a hash. Otherwise it returns the raw value.
|
68
|
+
#
|
69
|
+
# @return [Yew::Tree]
|
70
|
+
# @return [Object]
|
71
|
+
def self.fetch(key, env, root)
|
72
|
+
value = raw_fetch(key, env, root)
|
50
73
|
|
51
74
|
if value.is_a?(Hash)
|
52
75
|
path = key
|
@@ -57,5 +80,16 @@ module Yew
|
|
57
80
|
value
|
58
81
|
end
|
59
82
|
end
|
83
|
+
|
84
|
+
# Fetches a value from the env.
|
85
|
+
#
|
86
|
+
# @raise [RuntimeError] When key not found.
|
87
|
+
def self.raw_fetch(key, env, root)
|
88
|
+
env.fetch(key) do
|
89
|
+
env.fetch(key.to_s) do
|
90
|
+
raise "Attribute #{key} not found at /#{root}"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
60
94
|
end
|
61
95
|
end
|
data/test/test_yew_tree.rb
CHANGED
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
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gianfranco Zas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-03-28 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
|