No commit activity in last 3 years
No release in over 3 years
Build command text based on multiple filters
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.6
~> 5.4
~> 1.1
~> 10.3

Runtime

 Project Readme

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