ymlex 1.0.0
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 +7 -0
- data/lib/ymlex/ymlex.rb +100 -0
- data/lib/ymlex.rb +5 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: d58cf8e6242857ce7733c5c3fb8c7e6943e36fff
|
4
|
+
data.tar.gz: 788e86d712d1aa6224a58430edd155241f9a6903
|
5
|
+
!binary "U0hBNTEy":
|
6
|
+
metadata.gz: a8998586d0251f20a9f1dc5410b1fecc70934533b406ec1a88a0cfa4abede86f54a40fe3fa2bc0e6c01a8ccbe631f8afc972e69d9d6fe121c1ce04ab33d84294
|
7
|
+
data.tar.gz: e92d59c7b104c9406fec09c89b23e9ab135bfb8264cbe0aed1e2852099e909109fefba1ce1bb064520fca0fe9c5874711ffd8b47cbe98fefcaebaf19da47c8e7
|
data/lib/ymlex/ymlex.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
class Ymlex
|
4
|
+
|
5
|
+
@log = Logger.new STDOUT
|
6
|
+
|
7
|
+
def self.initLogger logger
|
8
|
+
@log = logger
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.getLogger
|
12
|
+
@log
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.initTptDir dir
|
16
|
+
@tptDir = dir
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.getTptDir
|
20
|
+
@tptDir
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.load_file file
|
24
|
+
@log.debug "start load file: #{file}"
|
25
|
+
input = YAML.load_file file
|
26
|
+
@tptDir ||= File.dirname file
|
27
|
+
input = parse input
|
28
|
+
@log.debug "after parse, #{file} is #{input}"
|
29
|
+
input = verblize input
|
30
|
+
@log.debug "after verblize, #{file} is #{input}"
|
31
|
+
input
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.parse input
|
35
|
+
input.each do |key,value|
|
36
|
+
if value.class == Hash
|
37
|
+
input[key] = parse value
|
38
|
+
end
|
39
|
+
end
|
40
|
+
if input.key? "_inherit"
|
41
|
+
father = load_file File.join(@tptDir,input["_inherit"])
|
42
|
+
input.delete "_inherit"
|
43
|
+
input = merge father, input
|
44
|
+
end
|
45
|
+
input
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.verblize input, ref = nil
|
49
|
+
ref ||= input
|
50
|
+
case
|
51
|
+
when input.class == Hash
|
52
|
+
input.each do |key,value|
|
53
|
+
input[key] = verblize value, ref
|
54
|
+
end
|
55
|
+
when input.class == Array
|
56
|
+
input.each_index do |i|
|
57
|
+
input[i] = verblize input[i], ref
|
58
|
+
end
|
59
|
+
when input.class == String
|
60
|
+
input = verbString input, ref
|
61
|
+
end
|
62
|
+
input
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.verbString input, ref
|
66
|
+
reg = /\${(.*?)}/.match(input)
|
67
|
+
while reg
|
68
|
+
toRep = reg[1] if reg
|
69
|
+
toEval = toRep.gsub(/[\.]/,"\"][\"").sub(/^/,"ref[\"").sub(/$/,"\"]")
|
70
|
+
begin
|
71
|
+
resultEval = eval toEval
|
72
|
+
rescue
|
73
|
+
@log.error "fail to verbString #{input}"
|
74
|
+
raise "fail to verbString #{input}"
|
75
|
+
end
|
76
|
+
input = input.sub(/\${(.*?)}/,resultEval)
|
77
|
+
reg = /\${(.*?)}/.match(input)
|
78
|
+
end
|
79
|
+
input
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.merge father, child
|
83
|
+
father.each do |key,value|
|
84
|
+
if child.key? key
|
85
|
+
if value.class == Hash && child[key].class == Hash
|
86
|
+
father[key] = merge value, child[key]
|
87
|
+
elsif value.class == Array && child[key].class == Array
|
88
|
+
father[key] = (value + child[key]).uniq
|
89
|
+
else
|
90
|
+
father[key] = child[key]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
child.each do |key,value|
|
95
|
+
father[key] ||= value
|
96
|
+
end
|
97
|
+
father
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
data/lib/ymlex.rb
ADDED
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ymlex
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cruel Wen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-14 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: ! 'extend ymal: support inherit and valueize'
|
14
|
+
email:
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/ymlex.rb
|
20
|
+
- lib/ymlex/ymlex.rb
|
21
|
+
homepage: https://github.com/cruelwen/ymlex
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.0.0.preview3.1
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: extend ymal!
|
45
|
+
test_files: []
|