Build command text based on multiple filters
This is framework to build command strings based on current context.
- initialize(priorities_array)- sets up initial context, execute all methods on this instance, try priorities:- [:first, nil, :last]
- filter(priority, options) { code }- create priority based filter for given options with the code bloc to execute
- context(options) { code }- build new context, options are for matching filters, all code will be executes in context of given options
- local_filter(filter_block) { code }- define local- filter_blockto take effect for the given- codeblock, it's tricky as it takes two lambdas, try:- local_filter(Proc.new{|cmd| "cd path && #{cmd}"}) { code }
- command(name, *args)- build command by evaluate global and local filters in the order of given priority, local filters are called after the- nilpriority or on the end
subject = CommandDesigner::Dsl.new([:first, nil, :last])
subject.filter(:last,  {:server => "::2" }) {|cmd| "command #{cmd}" }
subject.filter(:first, {:target => "true"}) {|cmd| "env #{cmd}" }
subject.local_filter(Proc.new{|cmd| "cd /path && #{cmd}" }) do
  subject.command("true")  # => "cd /path && env true"
  subject.command("false") # => "cd /path && false"
end
subject.context(:server => "::2") do |server2|
  # the :last filter with "command" was applied on the end
  server2.command("true") # => "command env false"
  # you do not have to use the block variable, subject works fine too
  subject.command("false") # => "command false"
end



