Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(FEAT) Add quality of life utilities #11

Merged
merged 3 commits into from
Nov 25, 2019
Merged

(FEAT) Add quality of life utilities #11

merged 3 commits into from
Nov 25, 2019

Conversation

michaeltlombardi
Copy link
Contributor

@michaeltlombardi michaeltlombardi commented Nov 25, 2019

This commit adds four new utilities to the gem:

  • snake_case: returns a string which is snake_cased.
  • snake_case_hash_keys: returns a hash in which all of the keys are snake_cased.
  • pascal_case: returns a string which is PascalCased.
  • pascal_case_hash_keys: returns a hash in which all of the keys are PascalCased.
  • escape_quotes: ensures that any string passed will be returned wrapped in double quotes for passing into PowerShell; this is because of the interpolation required when sending code to the PowerShell manager.
  • format_powershell_value: converts ruby data types into strings of their PowerShell representation for interpolation and passing to the PowerShell manager.
  • custom_powershell_property: takes a name and an expression and returns a string which represents a PowerShell custom object property hash. The expression being passed must already be an interpolated string as this method does not do any additional work for interpolation; whatever is passed is what will end up as PowerShell code in the expression script block.

These methods make interaction between Ruby and PowerShell a little easier by handling common translation problems when moving between Ruby and PowerShell objects.

This commit adds four new utilities to the gem:

- snake_case
- snake_case_hash_keys
- pascal_case
- pascal_case_hash_keys

These four methods exist to make tranlating back
and forth between powershell and ruby hashes a
little bit easier as the languages prefer different
casing styles.
This commit adds two new utilities to the gem:

- escape_quotes: this utility ensures that any string passed will be returned wrapped
  in double quotes for passing into PowerShell; this is because of the interpolation
  required when sending code to the PowerShell manager.
- format_powershell_value: this utility converts ruby data types into strings of their
  PowerShell representation for interpolation and passing to the PowerShell manager.

These two methods significantly reduce the amount of code and maintenance required
by consumers of the gem for using ruby to write logic and pass arguments to the
PowerShell commands.
This commit adds a new utility method, custom_powershell_property.
This method takes a name and an expression and returns a string which
represents a PowerShell custom object property hash.

The expression being passed must already be an interpolated string as
this method does not do any additional work for interpolation; whatever
is passed is what will end up as PowerShell code in the expression
script block.
@sanfrancrisko sanfrancrisko merged commit 0e1228d into puppetlabs:master Nov 25, 2019
@michaeltlombardi michaeltlombardi deleted the maint/master/add-case-utils branch December 3, 2019 04:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants