Skip to content

Instantly share code, notes, and snippets.

@thinkerbot
Created January 3, 2010 22:27
Show Gist options
  • Save thinkerbot/268156 to your computer and use it in GitHub Desktop.
Save thinkerbot/268156 to your computer and use it in GitHub Desktop.
outdated howtos
h2. Use an older version of Tap (or any gem)
Rubygems makes it very easy to use an older version of tap:
<notextile><pre><code>% tap _version_ ...</pre></code></notextile>
As you can see, all you have to do is specify the version in the first argument. This trick can also be useful for fixing the version of tap used if it gets called from another process.
<notextile><pre><code>% tap _0.10.3_
usage: tap <command> {options} [args]
examples:
tap generate root . # generates a root dir
tap run taskname --option input # runs the 'taskname' task
help:
tap help # prints this help
tap command --help # prints help for 'command'
available commands:
console
destroy
generate
help
run
version 0.10.3 -- http://tap.rubyforge.org</pre></code></notextile>
h2. Enter newlines, escape characters into configurations
Sometimes you need escaped characters in a configuration, for instance when formatting csv output. To do so, use the string validation then write them in as you would in a script:
<notextile><pre><code># StringConfig::manifest
class StringConfig < Tap::Task
config :a, "", &c.string
config :b, "", &c.string
config :c, "", &c.string
config :d, "", &c.string
config :e, "", &c.string
def process
[:a,:b,:c,:d,:e].each do |key|
type = case config[key]
when "\n" then 'newline'
when '\n' then 'backslash, n'
else 'other'
end
puts "#{key}: #{type}"
end
end
end</pre></code></notextile>
Now check out what happens:
% tap run -- string_config --a '\n' --b '\\n' --c "\n" --d "\\n" --e "\\\n"
a: newline
b: backslash, n
c: newline
d: newline
e: backslash, n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment