ytools 0.1.9 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +10 -0
- data/Gemfile.lock +27 -0
- data/Rakefile +4 -6
- data/lib/VERSION +1 -1
- data/lib/ytools/basecli.rb +47 -44
- data/lib/ytools/path/cli.rb +28 -109
- data/lib/ytools/path/executor.rb +16 -9
- data/lib/ytools/templates/cli.rb +24 -123
- data/lib/ytools/templates/executor.rb +12 -1
- data/lib/ytools/utils.rb +26 -0
- data/lib/ytools/yaml_object.rb +11 -4
- metadata +121 -34
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
ZenTest (4.5.0)
|
5
|
+
autotest (4.4.6)
|
6
|
+
ZenTest (>= 4.4.1)
|
7
|
+
autotest-notification (2.3.1)
|
8
|
+
autotest (~> 4.3)
|
9
|
+
choosy (0.2.5)
|
10
|
+
diff-lcs (1.1.2)
|
11
|
+
rspec (2.5.0)
|
12
|
+
rspec-core (~> 2.5.0)
|
13
|
+
rspec-expectations (~> 2.5.0)
|
14
|
+
rspec-mocks (~> 2.5.0)
|
15
|
+
rspec-core (2.5.1)
|
16
|
+
rspec-expectations (2.5.0)
|
17
|
+
diff-lcs (~> 1.1.2)
|
18
|
+
rspec-mocks (2.5.0)
|
19
|
+
|
20
|
+
PLATFORMS
|
21
|
+
ruby
|
22
|
+
|
23
|
+
DEPENDENCIES
|
24
|
+
autotest
|
25
|
+
autotest-notification
|
26
|
+
choosy (~> 0.2.4)
|
27
|
+
rspec
|
data/Rakefile
CHANGED
@@ -10,10 +10,7 @@ require 'ytools/version'
|
|
10
10
|
task :default => :spec
|
11
11
|
|
12
12
|
desc "Run the RSpec tests"
|
13
|
-
RSpec::Core::RakeTask.new
|
14
|
-
t.rspec_opts = ['-b', '-c', '-f', 'p']
|
15
|
-
t.fail_on_error = false
|
16
|
-
end
|
13
|
+
RSpec::Core::RakeTask.new
|
17
14
|
|
18
15
|
begin
|
19
16
|
require 'jeweler'
|
@@ -27,8 +24,9 @@ begin
|
|
27
24
|
gem.authors = ['Gabe McArthur']
|
28
25
|
gem.homepage = 'http://github.com/gabemc/ytools'
|
29
26
|
gem.files = FileList["[A-Z]*", "{bin,lib,spec}/**/*"]
|
30
|
-
|
31
|
-
gem.
|
27
|
+
|
28
|
+
gem.add_dependency 'choosy', '>=0.2.5'
|
29
|
+
gem.add_development_dependency 'rspec', '>=2.5.0'
|
32
30
|
end
|
33
31
|
rescue LoadError
|
34
32
|
puts "Jeweler or dependencies are not available. Install it with: sudo gem install jeweler"
|
data/lib/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/ytools/basecli.rb
CHANGED
@@ -1,67 +1,70 @@
|
|
1
|
-
require 'optparse'
|
2
1
|
require 'ytools/errors'
|
2
|
+
require 'ytools/utils'
|
3
3
|
require 'ytools/version'
|
4
4
|
|
5
5
|
module YTools
|
6
|
-
|
7
6
|
class BaseCLI
|
8
|
-
attr_reader :options, :args
|
9
|
-
|
10
7
|
def initialize(args)
|
11
|
-
@args = args
|
12
|
-
@options = {}
|
8
|
+
@args = args.dup
|
13
9
|
end
|
14
10
|
|
15
11
|
def execute!
|
16
|
-
|
17
|
-
sargs = args.dup
|
18
|
-
parse(sargs)
|
19
|
-
validate(sargs)
|
20
|
-
execute(sargs)
|
21
|
-
rescue SystemExit => e
|
22
|
-
raise
|
23
|
-
rescue YTools::ConfigurationError => e
|
24
|
-
print_error(e.message)
|
25
|
-
rescue OptionParser::InvalidOption => e
|
26
|
-
print_error(e.message)
|
27
|
-
rescue Exception => e
|
28
|
-
STDERR.puts e.backtrace
|
29
|
-
print_error(e.message)
|
30
|
-
end
|
12
|
+
tail(command).execute!(@args)
|
31
13
|
end
|
32
14
|
|
33
|
-
|
34
|
-
|
35
|
-
# To override
|
15
|
+
def parse(propagate=nil)
|
16
|
+
tail(command).parse!(@args, propagate)
|
36
17
|
end
|
37
18
|
|
38
|
-
def
|
39
|
-
#
|
19
|
+
def command
|
20
|
+
# overridden
|
40
21
|
end
|
41
22
|
|
42
|
-
|
43
|
-
|
44
|
-
|
23
|
+
protected
|
24
|
+
def tail(command)
|
25
|
+
command.alter do
|
26
|
+
string :literal, "Evaluate a literal string in addition to any file paths."
|
27
|
+
boolean :strict, "Checks to make sure all of the YAML files exist before proceeding."
|
28
|
+
boolean :examples, "Show some examples on how to use the path syntax." do
|
29
|
+
validate do |show, options|
|
30
|
+
if show
|
31
|
+
YTools::Utils.print_example(File.join(File.dirname(__FILE__), command.name.to_s.gsub(/^y/, '')))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
boolean_ :debug, "Prints out the merged YAML as a ruby object to STDERR."
|
36
|
+
version YTools::Version
|
37
|
+
help
|
38
|
+
|
39
|
+
arguments do
|
40
|
+
metaname 'YAML_FILES'
|
41
|
+
count :at_least => 0
|
45
42
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
43
|
+
validate do |files, options|
|
44
|
+
if files.length == 0 && options[:literal].nil? && !YTools::Utils.stdin?
|
45
|
+
die "no YAML files given as arguments"
|
46
|
+
end
|
50
47
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
48
|
+
begin
|
49
|
+
yaml_object = YTools::YamlObject.from_files(files, options[:strict])
|
50
|
+
if options[:literal]
|
51
|
+
yaml_object.merge(YAML::load(options[:literal]))
|
52
|
+
end
|
53
|
+
if YTools::Utils.stdin?
|
54
|
+
yaml_object.merge(YAML::load(STDIN.read))
|
55
|
+
end
|
56
|
+
options[:yaml_object] = yaml_object
|
57
|
+
rescue Exception => e
|
58
|
+
if options[:debug]
|
59
|
+
STDERR.puts e.stacktrace
|
60
|
+
end
|
61
|
+
die e.message
|
62
|
+
end
|
63
|
+
end
|
56
64
|
end
|
57
65
|
end
|
58
|
-
exit 0
|
59
|
-
end
|
60
66
|
|
61
|
-
|
62
|
-
STDERR.puts "ERROR: #{File.basename($0)}: #{e}"
|
63
|
-
STDERR.puts "ERROR: #{File.basename($0)}: Try '--help' for more information"
|
64
|
-
exit 1
|
67
|
+
command
|
65
68
|
end
|
66
69
|
end
|
67
70
|
end
|
data/lib/ytools/path/cli.rb
CHANGED
@@ -1,120 +1,39 @@
|
|
1
|
-
require '
|
1
|
+
require 'rubygems'
|
2
|
+
require 'choosy'
|
2
3
|
require 'ytools/basecli'
|
3
|
-
require 'ytools/errors'
|
4
4
|
require 'ytools/path/executor'
|
5
|
-
require '
|
5
|
+
require 'ytools/path/parser'
|
6
6
|
|
7
7
|
module YTools::Path
|
8
8
|
class CLI < YTools::BaseCLI
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
def parse(args)
|
36
|
-
OptionParser.new do |opts|
|
37
|
-
opts.banner = "Usage: #{File.basename($0)} [OPTIONS] YAML_FILES"
|
38
|
-
opts.separator <<EOF
|
39
|
-
Description:
|
40
|
-
This tool uses a kind of XPath syntax for locating and printing elements
|
41
|
-
from within YAML files. Check out the '--examples' flag for details
|
42
|
-
on the exact path syntax.
|
43
|
-
|
44
|
-
It accepts multiple yaml files, and will merge their contents in the
|
45
|
-
order in which they are given. Thus, files listed later, if their
|
46
|
-
keys conflict with ones listed earlier, override the earlier listed
|
47
|
-
values. If you pass in files that don't exist, no error will be
|
48
|
-
raised unless the '--strict' flag is passed.
|
49
|
-
|
50
|
-
Options:
|
51
|
-
EOF
|
52
|
-
|
53
|
-
opts.on('-p', '--path PATTERN',
|
54
|
-
"The pattern to use to access the",
|
55
|
-
"configuration.") do |p|
|
56
|
-
options[:path] = p
|
57
|
-
end
|
58
|
-
opts.on('-l', '--literal STRING',
|
59
|
-
"Evaluate a literal string in addition",
|
60
|
-
"to any file paths") do |l|
|
61
|
-
options[:literal] = l
|
62
|
-
end
|
63
|
-
opts.on('-s', '--strict',
|
64
|
-
"Checks to make sure all of the YAML files",
|
65
|
-
"exist before proceeding.") do |s|
|
66
|
-
options[:strict] = true
|
67
|
-
end
|
68
|
-
opts.separator ""
|
69
|
-
|
70
|
-
opts.on('-e', '--examples',
|
71
|
-
"Show some examples on how to use the",
|
72
|
-
"path syntax.") do
|
73
|
-
print_examples(File.dirname(__FILE__))
|
74
|
-
end
|
75
|
-
opts.on('-v', '--version',
|
76
|
-
"Show the version information") do |v|
|
77
|
-
print_version
|
78
|
-
end
|
79
|
-
opts.on('-d', '--debug',
|
80
|
-
"Prints out the merged yaml as a",
|
81
|
-
"ruby object to STDERR.") do |d|
|
82
|
-
options[:debug] = true
|
83
|
-
end
|
84
|
-
opts.on('-h', '--help',
|
85
|
-
"Show this help message.") do
|
86
|
-
puts opts
|
87
|
-
exit 0
|
88
|
-
end
|
89
|
-
end.parse!(args)
|
90
|
-
end
|
91
|
-
|
92
|
-
def validate(args)
|
93
|
-
if options[:path].nil?
|
94
|
-
raise YTools::ConfigurationError.new("The path expression was empty.")
|
95
|
-
end
|
96
|
-
if args.length == 0 && options[:literal].nil?
|
97
|
-
raise YTools::ConfigurationError.new("No YAML files given as arguments")
|
98
|
-
end
|
99
|
-
|
100
|
-
if options[:strict]
|
101
|
-
args.each do |arg|
|
102
|
-
if !File.exists?(arg)
|
103
|
-
raise YTools::ConfigurationError.new("Non-existant YAML file: #{arg}")
|
9
|
+
def command
|
10
|
+
Choosy::Command.new :ypath do
|
11
|
+
printer :standard, :max_width => 80
|
12
|
+
executor Executor.new
|
13
|
+
|
14
|
+
header 'Description:'
|
15
|
+
para "This tool uses a kind of XPath syntax for locating and printing elements from within YAML files. Check out the '--examples' flag for details on the exact path syntax."
|
16
|
+
para "It accepts multiple yaml files, and will merge their contents in the order in which they are given. Thus, files listed later, if their keys conflict with ones listed earlier, override the earlier listed values. If you pass in files that don't exist, no error will be raised unless the '--strict' flag is passed."
|
17
|
+
|
18
|
+
header 'Option:'
|
19
|
+
string :path, "The YAML Path pattern syntax to run against the input." do
|
20
|
+
required
|
21
|
+
depends_on :examples
|
22
|
+
validate do |path, options|
|
23
|
+
begin
|
24
|
+
options[:selector] = YTools::Path::Parser.new(path).parse!
|
25
|
+
rescue YTools::Path::ParseError => e
|
26
|
+
if e.token.path == ""
|
27
|
+
die "error parsing expression: #{e.message}"
|
28
|
+
else
|
29
|
+
die "error parsing expression: #{e.message}
|
30
|
+
#{e.token.path}
|
31
|
+
#{' ' * e.token.offset}^"
|
32
|
+
end
|
33
|
+
end
|
104
34
|
end
|
105
35
|
end
|
106
36
|
end
|
107
37
|
end
|
108
|
-
|
109
|
-
def print_path_error(e)
|
110
|
-
STDERR.puts "ERROR: Path error: #{e.token.path}"
|
111
|
-
spacer = "ERROR: "
|
112
|
-
e.token.offset.downto(1) do
|
113
|
-
spacer << " "
|
114
|
-
end
|
115
|
-
spacer << "^"
|
116
|
-
STDERR.puts spacer
|
117
|
-
print_error("Path expression parsing error - #{e.message}")
|
118
|
-
end
|
119
38
|
end # CLI
|
120
39
|
end
|
data/lib/ytools/path/executor.rb
CHANGED
@@ -2,20 +2,28 @@ require 'ytools/yaml_object'
|
|
2
2
|
require 'ytools/path/parser'
|
3
3
|
|
4
4
|
module YTools::Path
|
5
|
-
|
6
5
|
class Executor
|
7
|
-
attr_reader :
|
6
|
+
attr_reader :selector, :yaml_object
|
8
7
|
|
9
|
-
def initialize(path, yaml_object)
|
10
|
-
@
|
8
|
+
def initialize(path=nil, yaml_object=nil)
|
9
|
+
@selector = Parser.new(path).parse! if path
|
11
10
|
@yaml_object = yaml_object
|
12
11
|
end
|
13
12
|
|
14
|
-
def
|
15
|
-
|
16
|
-
|
13
|
+
def execute!(yaml_files, options)
|
14
|
+
@yaml_object = options[:yaml_object]
|
15
|
+
|
16
|
+
if options[:debug]
|
17
|
+
STDERR.puts @yaml_object.to_s
|
18
|
+
end
|
17
19
|
|
18
|
-
|
20
|
+
@selector = options[:selector]
|
21
|
+
output = process!
|
22
|
+
puts output if !output.empty?
|
23
|
+
end
|
24
|
+
|
25
|
+
def process!
|
26
|
+
found = @selector.select(yaml_object)
|
19
27
|
if found.is_a?(YTools::YamlObject)
|
20
28
|
show_yaml_object(found)
|
21
29
|
elsif found.is_a?(Array)
|
@@ -53,6 +61,5 @@ module YTools::Path
|
|
53
61
|
end
|
54
62
|
output
|
55
63
|
end
|
56
|
-
|
57
64
|
end
|
58
65
|
end
|
data/lib/ytools/templates/cli.rb
CHANGED
@@ -1,133 +1,34 @@
|
|
1
|
-
require 'optparse'
|
2
|
-
require 'ytools/basecli'
|
3
1
|
require 'ytools/errors'
|
2
|
+
require 'ytools/basecli'
|
4
3
|
require 'ytools/templates/executor'
|
4
|
+
require 'rubygems'
|
5
|
+
require 'choosy'
|
5
6
|
|
6
7
|
module YTools::Templates
|
7
8
|
class CLI < YTools::BaseCLI
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
STDERR.puts yaml_object
|
29
|
-
end
|
30
|
-
|
31
|
-
executor.write!(options[:output])
|
32
|
-
end
|
33
|
-
|
34
|
-
def parse(args)
|
35
|
-
OptionParser.new do |opts|
|
36
|
-
opts.banner = "Usage: #{File.basename($0)} [OPTIONS] YAML_FILES"
|
37
|
-
opts.separator <<EOF
|
38
|
-
Description:
|
39
|
-
This tool uses an ERB template file and a set of YAML files to
|
40
|
-
generate a merged file. For convenience, all of the keys in
|
41
|
-
hashes in regular YAML can work like methods in the ERB templates.
|
42
|
-
Thus, the YAML "{ 'a' : {'b' : 3 } }" could be used in an
|
43
|
-
ERB template with "<%= a.b %>" instead of the more verbose hash
|
44
|
-
syntax. Indeed, the root hash values can only be accessed by
|
45
|
-
those method attributes, because the root YAML context object
|
46
|
-
is simply assumed.
|
47
|
-
|
48
|
-
It accepts multiple yaml files, and will merge their contents in the
|
49
|
-
order in which they are given. Thus, files listed later, if their
|
50
|
-
keys conflict with ones listed earlier, override the earlier listed
|
51
|
-
values. If you pass in files that don't exist, no error will be
|
52
|
-
raised unless the '--strict' flag is passed.
|
53
|
-
|
54
|
-
Check out the '--examples' flag for more details.
|
55
|
-
|
56
|
-
Options:
|
57
|
-
EOF
|
58
|
-
opts.on('-t', '--template ERB',
|
59
|
-
"The ERB template file to use for generation") do |t|
|
60
|
-
options[:template] = t
|
61
|
-
end
|
62
|
-
opts.on('-e', '--expression EXPR',
|
63
|
-
"The ERB expression to use for generation",
|
64
|
-
"overrides --template") do |e|
|
65
|
-
options[:expression] = e
|
66
|
-
end
|
67
|
-
opts.on('-l', '--literal STRING',
|
68
|
-
"Evaluate a literal string in addition",
|
69
|
-
"to any file paths") do |l|
|
70
|
-
options[:literal] = l
|
71
|
-
end
|
72
|
-
opts.on('-o', '--output FILE',
|
73
|
-
"Write the generated output to a file instead",
|
74
|
-
"of STDOUT") do |o|
|
75
|
-
options[:output] = o
|
76
|
-
end
|
77
|
-
opts.on('-s', '--strict',
|
78
|
-
"Checks to make sure all of the YAML files",
|
79
|
-
"exist before proceeding.") do |s|
|
80
|
-
options[:strict] = true
|
81
|
-
end
|
82
|
-
opts.separator ""
|
83
|
-
|
84
|
-
opts.on('--examples',
|
85
|
-
"Show some examples on how to use the",
|
86
|
-
"path syntax.") do
|
87
|
-
print_examples(File.dirname(__FILE__))
|
88
|
-
end
|
89
|
-
opts.on('-v', '--version',
|
90
|
-
"Show the version information") do |v|
|
91
|
-
print_version
|
92
|
-
end
|
93
|
-
opts.on('-d', '--debug',
|
94
|
-
"Prints out the merged yaml as a",
|
95
|
-
"ruby object to STDERR.") do |d|
|
96
|
-
options[:debug] = true
|
97
|
-
end
|
98
|
-
opts.on('-h', '--help',
|
99
|
-
"Show this help message.") do
|
100
|
-
puts opts
|
101
|
-
exit 0
|
102
|
-
end
|
103
|
-
end.parse!(args)
|
104
|
-
end
|
105
|
-
|
106
|
-
def validate(args)
|
107
|
-
if options[:expression].nil? && options[:template].nil?
|
108
|
-
raise YTools::ConfigurationError.new("No template expression or file was indicated")
|
109
|
-
end
|
110
|
-
|
111
|
-
if options[:expression].nil? && !File.exists?(options[:template])
|
112
|
-
raise YTools::ConfigurationError.new("Unable to locate the template file: #{options[:template]}")
|
113
|
-
end
|
114
|
-
|
115
|
-
if options[:output] &&
|
116
|
-
!File.exists?(File.dirname(options[:output]))
|
117
|
-
raise YTools::ConfigurationError.new("The output directory doesn't exist: #{option[:output]}")
|
118
|
-
end
|
119
|
-
|
120
|
-
if args.length == 0 && options[:literal].nil?
|
121
|
-
raise YTools::ConfigurationError.new("No YAML files were given")
|
122
|
-
end
|
123
|
-
|
124
|
-
if options[:strict]
|
125
|
-
args.each do |file|
|
126
|
-
if !File.exists?(file)
|
127
|
-
raise YTools::ConfigurationError.new("Unable to locate YAML file: #{file}")
|
9
|
+
def command
|
10
|
+
Choosy::Command.new :ytemplates do
|
11
|
+
executor Executor.new
|
12
|
+
printer :standard, :max_width => 80
|
13
|
+
|
14
|
+
header 'Description:'
|
15
|
+
para 'This tool uses an ERB template file and a set of YAML files to generate a merged file. For convenience, all of the keys in hashes in regular YAML can work like methods in the ERB templates. Thus, the YAML "{ \'a\' : {\'b\' : 3 } }" could be used in an ERB template with "<%= a.b %>" instead of the more verbose hash syntax. Indeed, the root hash values can only be accessed by those method attributes, because the root YAML context object is simply assumed.'
|
16
|
+
para "It accepts multiple yaml files, and will merge their contents in the order in which they are given. Thus, files listed later, if their keys conflict with ones listed earlier, override the earlier listed values. If you pass in files that don't exist, no error will be raised unless the '--strict' flag is passed."
|
17
|
+
para "Check out the '--examples' flag for more details."
|
18
|
+
|
19
|
+
header 'Options:'
|
20
|
+
file :template, "The ERB template file to use for generation" do
|
21
|
+
required
|
22
|
+
depends_on :examples
|
23
|
+
end
|
24
|
+
string :output, "Write the generated output to a file instead of STDOUT" do
|
25
|
+
validate do |path, options|
|
26
|
+
if !File.exists?(File.dirname(options[:output]))
|
27
|
+
die "The output directory doesn't exist: #{option[:output]}"
|
28
|
+
end
|
128
29
|
end
|
129
30
|
end
|
130
31
|
end
|
131
32
|
end
|
132
|
-
end
|
33
|
+
end # CLI
|
133
34
|
end
|
@@ -6,11 +6,22 @@ module YTools::Templates
|
|
6
6
|
class Executor
|
7
7
|
attr_reader :template, :yaml_object
|
8
8
|
|
9
|
-
def initialize(template, yaml_object)
|
9
|
+
def initialize(template=nil, yaml_object=nil)
|
10
10
|
@template = template
|
11
11
|
@yaml_object = yaml_object
|
12
12
|
end
|
13
13
|
|
14
|
+
def execute!(yaml_files, options)
|
15
|
+
@template = options[:template]
|
16
|
+
@yaml_object = options[:yaml_object]
|
17
|
+
|
18
|
+
if options[:debug]
|
19
|
+
STDERR.puts @yaml_object.to_s
|
20
|
+
end
|
21
|
+
|
22
|
+
write!(options[:output])
|
23
|
+
end
|
24
|
+
|
14
25
|
def write!(outfile)
|
15
26
|
generator = ERB.new(template)
|
16
27
|
output = generator.result(yaml_object.erb_binding)
|
data/lib/ytools/utils.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'ytools/errors'
|
3
|
+
require 'ytools/version'
|
4
|
+
|
5
|
+
module YTools
|
6
|
+
module Utils
|
7
|
+
def self.print_example(basedir)
|
8
|
+
examples = File.join(basedir, 'examples.txt')
|
9
|
+
File.open(examples, 'r') do |f|
|
10
|
+
f.each_line do |line|
|
11
|
+
puts line
|
12
|
+
end
|
13
|
+
end
|
14
|
+
exit 0
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.stdin?
|
18
|
+
begin
|
19
|
+
require 'fcntl'
|
20
|
+
STDIN.fcntl(Fcntl::F_GETFL, 0) == 0
|
21
|
+
rescue
|
22
|
+
$stdin.stat.size != 0
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/ytools/yaml_object.rb
CHANGED
@@ -2,13 +2,15 @@ require 'yaml'
|
|
2
2
|
|
3
3
|
module YTools
|
4
4
|
class YamlObject
|
5
|
-
def self.from_files(files)
|
5
|
+
def self.from_files(files, strict=nil)
|
6
6
|
yo = YTools::YamlObject.new
|
7
7
|
files.each do |file|
|
8
8
|
if File.exists?(file)
|
9
9
|
contents = nil
|
10
10
|
File.open(file, 'r') { |f| contents = f.read}
|
11
11
|
yo.merge(YAML::load(contents))
|
12
|
+
elsif strict
|
13
|
+
raise YTools::PathError.new("non-existant YAML file: #{file}")
|
12
14
|
end
|
13
15
|
end
|
14
16
|
yo
|
@@ -30,7 +32,12 @@ module YTools
|
|
30
32
|
merge(@yhash)
|
31
33
|
end
|
32
34
|
|
33
|
-
def merge(hash)
|
35
|
+
def merge(hash)
|
36
|
+
return if hash.nil?
|
37
|
+
if !hash.is_a?(Hash)
|
38
|
+
raise YTools::PathError.new("malformed YAML:\n#{hash}")
|
39
|
+
end
|
40
|
+
|
34
41
|
hash.each do |key, value|
|
35
42
|
add_entry(key, value)
|
36
43
|
end
|
@@ -41,7 +48,7 @@ module YTools
|
|
41
48
|
hash_key = @methods[method_name]
|
42
49
|
|
43
50
|
if hash_key.nil?
|
44
|
-
raise YTools::PathError.new("
|
51
|
+
raise YTools::PathError.new("unable to locate attribute: '#{relative_ypath}/#{method_name}'")
|
45
52
|
else
|
46
53
|
@yhash[hash_key]
|
47
54
|
end
|
@@ -50,7 +57,7 @@ module YTools
|
|
50
57
|
def [](key)
|
51
58
|
value = @yhash[key]
|
52
59
|
if value.nil?
|
53
|
-
raise YTools::PathError.new("
|
60
|
+
raise YTools::PathError.new("unable to locate key: \"#{relative_ypath}@['#{key}']\"")
|
54
61
|
end
|
55
62
|
value
|
56
63
|
end
|
metadata
CHANGED
@@ -1,40 +1,119 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: ytools
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
6
10
|
platform: ruby
|
7
|
-
authors:
|
11
|
+
authors:
|
8
12
|
- Gabe McArthur
|
9
13
|
autorequire:
|
10
14
|
bindir: bin
|
11
15
|
cert_chain: []
|
12
|
-
|
16
|
+
|
17
|
+
date: 2011-03-10 00:00:00 -08:00
|
13
18
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
17
|
-
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: choosy
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
18
24
|
none: false
|
19
|
-
requirements:
|
25
|
+
requirements:
|
20
26
|
- - ~>
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
- 2
|
31
|
+
- 4
|
32
|
+
version: 0.2.4
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rspec
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: autotest
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
23
59
|
type: :development
|
60
|
+
version_requirements: *id003
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: autotest-notification
|
24
63
|
prerelease: false
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
64
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
type: :development
|
73
|
+
version_requirements: *id004
|
74
|
+
- !ruby/object:Gem::Dependency
|
75
|
+
name: choosy
|
76
|
+
prerelease: false
|
77
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
- 2
|
85
|
+
- 5
|
86
|
+
version: 0.2.5
|
87
|
+
type: :runtime
|
88
|
+
version_requirements: *id005
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: rspec
|
91
|
+
prerelease: false
|
92
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
segments:
|
98
|
+
- 2
|
99
|
+
- 5
|
100
|
+
- 0
|
101
|
+
version: 2.5.0
|
102
|
+
type: :development
|
103
|
+
version_requirements: *id006
|
104
|
+
description: Installs the ypath tool for reading YAML files using an XPath-like syntax. Installs the ytemplates tool for writing ERB templates using YAML files as the template binding object.
|
105
|
+
email:
|
30
106
|
- madeonamac@gmail.com
|
31
|
-
executables:
|
107
|
+
executables:
|
32
108
|
- ypath
|
33
109
|
- ytemplates
|
34
110
|
extensions: []
|
35
|
-
|
111
|
+
|
112
|
+
extra_rdoc_files:
|
36
113
|
- README.markdown
|
37
|
-
files:
|
114
|
+
files:
|
115
|
+
- Gemfile
|
116
|
+
- Gemfile.lock
|
38
117
|
- README.markdown
|
39
118
|
- Rakefile
|
40
119
|
- bin/ypath
|
@@ -52,6 +131,7 @@ files:
|
|
52
131
|
- lib/ytools/templates/examples.txt
|
53
132
|
- lib/ytools/templates/executor.rb
|
54
133
|
- lib/ytools/templates/yaml_object.rb
|
134
|
+
- lib/ytools/utils.rb
|
55
135
|
- lib/ytools/version.rb
|
56
136
|
- lib/ytools/yaml_object.rb
|
57
137
|
- lib/ytools/yreader.rb
|
@@ -70,29 +150,36 @@ files:
|
|
70
150
|
has_rdoc: true
|
71
151
|
homepage: http://github.com/gabemc/ytools
|
72
152
|
licenses: []
|
153
|
+
|
73
154
|
post_install_message:
|
74
155
|
rdoc_options: []
|
75
|
-
|
156
|
+
|
157
|
+
require_paths:
|
76
158
|
- lib
|
77
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
159
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
160
|
none: false
|
79
|
-
requirements:
|
80
|
-
- -
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
|
83
|
-
|
161
|
+
requirements:
|
162
|
+
- - ">="
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
segments:
|
165
|
+
- 0
|
166
|
+
version: "0"
|
167
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
168
|
none: false
|
85
|
-
requirements:
|
86
|
-
- -
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
segments:
|
173
|
+
- 0
|
174
|
+
version: "0"
|
89
175
|
requirements: []
|
176
|
+
|
90
177
|
rubyforge_project:
|
91
|
-
rubygems_version: 1.
|
178
|
+
rubygems_version: 1.3.7
|
92
179
|
signing_key:
|
93
180
|
specification_version: 3
|
94
181
|
summary: For reading or writing configuration files using YAML.
|
95
|
-
test_files:
|
182
|
+
test_files:
|
96
183
|
- spec/helpers.rb
|
97
184
|
- spec/path/executor_spec.rb
|
98
185
|
- spec/path/lexer_spec.rb
|