lib/tap/tasks/load.rb in tap-0.11.1 vs lib/tap/tasks/load.rb in tap-0.12.0
- old
+ new
@@ -1,29 +1,29 @@
-module Tap
- module Tasks
- # :startdoc::manifest the default load task
- #
- # Load YAML-formatted data, as may be produced using Tap::Dump,
- # and makes this data available for other tasks. Load is often
- # used as a gateway task to other tasks.
- #
- # % tap run -- load FILEPATH --: [task]
+module Tap
+ module Tasks
+ # :startdoc::manifest the default load task
#
- # Load can select items from Hash or Array objects using one or
- # more keys when only a subset is desired. By default items are
- # selected using []. For more flexible selection, use match.
+ # Load YAML-formatted data, as may be produced using Dump, and makes this
+ # data available for other tasks. Load is often used as a gateway task
+ # to other tasks.
+ #
+ # % tap run -- load FILEPATH --: [task]
+ #
+ # Load can select items from Hash or Array objects using one or more keys
+ # when only a subset is desired. By default items are selected using [].
+ # For more flexible selection, use match.
#
- # Match converts each of the keys to a Regexp. For hashes, all
- # values with a matching key will be selected. For arrays, any
- # item matching a regexp will be selected.
+ # Match converts each of the keys to a Regexp. For hashes, all values
+ # with a matching key will be selected. For arrays, any item matching
+ # a regexp will be selected.
#
- # Use the flags to flatten, compact, sort (etc) results before
- # passing them on to the next task.
+ # Use the flags to flatten, compact, sort (etc) results before passing
+ # them on to the next task.
class Load < Tap::Task
config :match, false, :short => :m, &c.switch # match keys
- config :flatten, false, :short => :f, &c.switch # flatten results
+ config :flatten, false, :short => :f, &c.switch # flatten results
config :compact, false, :short => :c, &c.switch # compact results
config :unique, false, :short => :u, &c.switch # uniq results
config :sort, false, :short => :s, &c.switch # sort results
#config :preview, false, :short => :p, &c.switch # logs result
@@ -52,17 +52,17 @@
# order) using flatten, compact, unique, and sort, each performing as
# you would expect.
#
def process(input, *keys)
- # load the input
- obj = case input
+ # load the input
+ obj = case input
when StringIO, IO
- YAML.load(input.read)
- else
- log :load, input
- YAML.load_file(input)
+ YAML.load(input.read)
+ else
+ log :load, input
+ YAML.load_file(input)
end
# select results by key
results = case
when keys.empty? then obj
@@ -85,11 +85,11 @@
#if preview
# should be a log or something
#puts results.inspect
#end
- results
+ results
end
protected
# selects items from obj which match one of the regexps.
@@ -104,9 +104,9 @@
end
results
else
raise ArgumentError, "cannot match keys from a #{obj.class}"
end
- end
- end
- end
-end
+ end
+ end
+ end
+end