lib/tap/generator/generators/file_task/templates/task.erb in tap-0.8.0 vs lib/tap/generator/generators/file_task/templates/task.erb in tap-0.9.0
- old
+ new
@@ -1,34 +1,40 @@
# == Description
-# Replace with a description for <%= class_name_without_nesting %>
+# Replace with a description. The default task reads
+# in the lines of a text file and dumps them as YAML
+# into a yaml file.
# === Usage
# Replace with usage instructions
#
class <%= class_name_without_nesting %> < Tap::FileTask
- # uncomment to:
- # - pass all inputs to process at once
- # - define a task that takes no inputs
-
- #do_not_iterate
-
# use config to set task configurations
# configs have accessors by default
- #config :key, 'value' # config documentation
+ config :key, 'value' # a sample config
+
+ # process defines what the task does; use the
+ # same number of inputs to enque the task
+ # as specified here
+ def process(filepath)
- def process(input)
- # The process logic goes here.
- output = filepath(:data, input)
+ # infer an output filepath relative to the :data directory,
+ # (this is convenient for testing) while changing the
+ # basename of filepath to 'yml'. See FileTask#filepath
+ # for filepaths based on the task name.
+ target = app.filepath(:data, basename(filepath, '.yml') )
- # prepare ensures the parent directory for
- # output exists, and marks it for rollback
+ # prepare ensures the parent directory for
+ # output exists, and that output does not;
+ # any existing file is backed up and reverts
# in the event of an error
- prepare(output)
-
- File.open(input) do |source|
- File.open(output, "w") do |target|
- # ... do something ...
- end
+ prepare(target)
+
+ # now perform the task...
+ array = File.read(filepath).split(/\r?\n/)
+ File.open(target, "wb") do |file|
+ file << array.to_yaml
end
+
+ target
end
-end
\ No newline at end of file
+end