<commit_before># Command Designer

[![Gem Version](https://badge.fury.io/rb/command-designer.png)](https://rubygems.org/gems/command-designer)
[![Build Status](https://secure.travis-ci.org/remote-exec/command-designer.png?branch=master)](https://travis-ci.org/remote-exec/command-designer)
[![Dependency Status](https://gemnasium.com/remote-exec/command-designer.png)](https://gemnasium.com/remote-exec/command-designer)
[![Code Climate](https://codeclimate.com/github/remote-exec/command-designer.png)](https://codeclimate.com/github/remote-exec/command-designer)
[![Coverage Status](https://img.shields.io/coveralls/remote-exec/command-designer.svg)](https://coveralls.io/r/remote-exec/command-designer?branch=master)
[![Inline docs](http://inch-ci.org/github/remote-exec/command-designer.png)](http://inch-ci.org/github/remote-exec/command-designer)
[![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/github/remote-exec/command-designer/master/frames)
[![Github Code](http://img.shields.io/badge/github-code-blue.svg)](https://github.com/remote-exec/command-designer)

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
- `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 }`
- `context(options) { code }` - build new context, options are for
  matching filters, all code will be executes in context of given options
- `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

```ruby
subject = CommandDesigner::Dsl.new([:first, nil, :last])

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
```<commit_msg>add example for commands in context<commit_after># Command Designer

[![Gem Version](https://badge.fury.io/rb/command-designer.png)](https://rubygems.org/gems/command-designer)
[![Build Status](https://secure.travis-ci.org/remote-exec/command-designer.png?branch=master)](https://travis-ci.org/remote-exec/command-designer)
[![Dependency Status](https://gemnasium.com/remote-exec/command-designer.png)](https://gemnasium.com/remote-exec/command-designer)
[![Code Climate](https://codeclimate.com/github/remote-exec/command-designer.png)](https://codeclimate.com/github/remote-exec/command-designer)
[![Coverage Status](https://img.shields.io/coveralls/remote-exec/command-designer.svg)](https://coveralls.io/r/remote-exec/command-designer?branch=master)
[![Inline docs](http://inch-ci.org/github/remote-exec/command-designer.png)](http://inch-ci.org/github/remote-exec/command-designer)
[![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/github/remote-exec/command-designer/master/frames)
[![Github Code](http://img.shields.io/badge/github-code-blue.svg)](https://github.com/remote-exec/command-designer)

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
- `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 }`
- `context(options) { code }` - build new context, options are for
  matching filters, all code will be executes in context of given options
- `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

```ruby
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"
  server2.command("false") # => "command false"

end
```
{'fraction_non_alphanumeric': 0.17057779530664563, 'fraction_numerical': 0.0009859988168014198, 'mean_word_length': 4.995271867612293, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 22, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2691022', 'n_tokens_mistral': 1670, 'n_tokens_neox': 1615, 'n_words': 379}