Skip to content

remote-exec/command-designer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Command Designer

Gem Version Build Status Dependency Status Code Climate Coverage Status Inline docs Yard Docs Github Code

Build command text based on multiple filters

About

This is framework to build command strings based on current context.

DSL Methods

  • 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_block to take effect for the given code block, 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 nil priority or on the end

Example

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

About

Build command text based on multiple filters

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages