ruby-pwsh 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.pmtignore +2 -0
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +13 -1
- data/Gemfile +1 -1
- data/README.md +4 -0
- data/lib/pwsh/util.rb +47 -25
- data/lib/pwsh/version.rb +1 -1
- data/metadata.json +1 -1
- data/pwshlib.md +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9ff0bf2c8d109926cd0161323e4d49e6b697410883d5c6da7e8beda5cf8de6d
|
4
|
+
data.tar.gz: da85cd63a46c1d75b0b1178d9841f3d3e134ad20dead8847eb724d52bec3a847
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '09007c0add66995ff0a978129c9b3da760d4d5a9a95bad6bf77226afdcbdeab2508ad68ac39c2217bd5bd57be41904b18333dcba14365441c98582291224782a'
|
7
|
+
data.tar.gz: 2157ae9772fefc54271500a3d7d84502d1737e45fc54986405e45da962fb40fd855d482b4e31aa33febb61756f9d6944f9db82a4fb1f6dcea696ec7f6b81beea
|
data/.gitignore
CHANGED
data/.pmtignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -19,7 +19,7 @@ Metrics/AbcSize:
|
|
19
19
|
|
20
20
|
# requires 2.3's squiggly HEREDOC support, which we can't use, yet
|
21
21
|
# see http://www.virtuouscode.com/2016/01/06/about-the-ruby-squiggly-heredoc-syntax/
|
22
|
-
Layout/
|
22
|
+
Layout/HeredocIndentation:
|
23
23
|
Enabled: false
|
24
24
|
# Need to ignore rubocop complaining about the name of the library.
|
25
25
|
Naming/FileName:
|
data/CHANGELOG.md
CHANGED
@@ -2,7 +2,19 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file.The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org).
|
4
4
|
|
5
|
-
## [0.
|
5
|
+
## [0.3.0](https://github.com/puppetlabs/ruby-pwsh/tree/0.3.0) (2019-12-03)
|
6
|
+
|
7
|
+
[Full Changelog](https://github.com/puppetlabs/ruby-pwsh/compare/0.2.0...0.3.0)
|
8
|
+
|
9
|
+
### Added
|
10
|
+
|
11
|
+
- \(FEAT\) Add method for symbolizing hash keys [\#16](https://github.com/puppetlabs/ruby-pwsh/pull/16) ([michaeltlombardi](https://github.com/michaeltlombardi))
|
12
|
+
|
13
|
+
### Fixed
|
14
|
+
|
15
|
+
- \(FEAT\) Ensure hash key casing methods work on arrays [\#15](https://github.com/puppetlabs/ruby-pwsh/pull/15) ([michaeltlombardi](https://github.com/michaeltlombardi))
|
16
|
+
|
17
|
+
## [0.2.0](https://github.com/puppetlabs/ruby-pwsh/tree/0.2.0) (2019-11-26)
|
6
18
|
|
7
19
|
[Full Changelog](https://github.com/puppetlabs/ruby-pwsh/compare/0.1.0...0.2.0)
|
8
20
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -60,6 +60,10 @@ ps_version = posh.execute('[String]$PSVersionTable.PSVersion')[:stdout].strip
|
|
60
60
|
pp("The PowerShell version of the currently running Manager is #{ps_version}")
|
61
61
|
```
|
62
62
|
|
63
|
+
## Reference
|
64
|
+
|
65
|
+
You can find the full reference documentation online, [here](https://rubydoc.info/gems/ruby-pwsh).
|
66
|
+
|
63
67
|
<!-- ## Development
|
64
68
|
|
65
69
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/pwsh/util.rb
CHANGED
@@ -31,50 +31,51 @@ module Pwsh
|
|
31
31
|
invalid_paths
|
32
32
|
end
|
33
33
|
|
34
|
-
# Return a string converted to snake_case
|
34
|
+
# Return a string or symbol converted to snake_case
|
35
35
|
#
|
36
36
|
# @return [String] snake_cased string
|
37
|
-
def snake_case(
|
37
|
+
def snake_case(object)
|
38
38
|
# Implementation copied from: https://github.com/rubyworks/facets/blob/master/lib/core/facets/string/snakecase.rb
|
39
39
|
# gsub(/::/, '/').
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
40
|
+
should_symbolize = object.is_a?(Symbol)
|
41
|
+
raise "snake_case method only handles strings and symbols, passed a #{object.class}: #{object}" unless should_symbolize || object.is_a?(String)
|
42
|
+
|
43
|
+
text = object.to_s
|
44
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
45
|
+
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
46
|
+
.tr('-', '_')
|
47
|
+
.gsub(/\s/, '_')
|
48
|
+
.gsub(/__+/, '_')
|
49
|
+
.downcase
|
50
|
+
should_symbolize ? text.to_sym : text
|
46
51
|
end
|
47
52
|
|
48
53
|
# Iterate through a hashes keys, snake_casing them
|
49
54
|
#
|
50
55
|
# @return [Hash] Hash with all keys snake_cased
|
51
|
-
def snake_case_hash_keys(
|
52
|
-
|
53
|
-
|
54
|
-
value = snake_case_hash_keys(value) if value.is_a?(Hash)
|
55
|
-
modified_hash[snake_case(key.to_s).to_sym] = value
|
56
|
-
end
|
57
|
-
modified_hash
|
56
|
+
def snake_case_hash_keys(object)
|
57
|
+
snake_case_proc = proc { |key| snake_case(key) }
|
58
|
+
apply_key_mutator(object, snake_case_proc)
|
58
59
|
end
|
59
60
|
|
60
|
-
# Return a string converted to PascalCase
|
61
|
+
# Return a string or symbol converted to PascalCase
|
61
62
|
#
|
62
63
|
# @return [String] PascalCased string
|
63
|
-
def pascal_case(
|
64
|
+
def pascal_case(object)
|
65
|
+
should_symbolize = object.is_a?(Symbol)
|
66
|
+
raise "snake_case method only handles strings and symbols, passed a #{object.class}: #{object}" unless should_symbolize || object.is_a?(String)
|
67
|
+
|
64
68
|
# Break word boundaries to snake case first
|
65
|
-
snake_case(
|
69
|
+
text = snake_case(object.to_s).split('_').collect(&:capitalize).join
|
70
|
+
should_symbolize ? text.to_sym : text
|
66
71
|
end
|
67
72
|
|
68
73
|
# Iterate through a hashes keys, PascalCasing them
|
69
74
|
#
|
70
75
|
# @return [Hash] Hash with all keys PascalCased
|
71
|
-
def pascal_case_hash_keys(
|
72
|
-
|
73
|
-
|
74
|
-
value = pascal_case_hash_keys(value) if value.is_a?(Hash)
|
75
|
-
modified_hash[pascal_case(key.to_s).to_sym] = value
|
76
|
-
end
|
77
|
-
modified_hash
|
76
|
+
def pascal_case_hash_keys(object)
|
77
|
+
pascal_case_proc = proc { |key| pascal_case(key) }
|
78
|
+
apply_key_mutator(object, pascal_case_proc)
|
78
79
|
end
|
79
80
|
|
80
81
|
# Ensure that quotes inside a passed string will continue to be passed
|
@@ -84,6 +85,27 @@ module Pwsh
|
|
84
85
|
text.gsub("'", "''")
|
85
86
|
end
|
86
87
|
|
88
|
+
# Ensure that all keys in a hash are symbols, not strings.
|
89
|
+
#
|
90
|
+
# @return [Hash] a hash whose keys have been converted to symbols.
|
91
|
+
def symbolize_hash_keys(object)
|
92
|
+
symbolize_proc = proc(&:to_sym)
|
93
|
+
apply_key_mutator(object, symbolize_proc)
|
94
|
+
end
|
95
|
+
|
96
|
+
def apply_key_mutator(object, proc)
|
97
|
+
return object.map { |item| apply_key_mutator(item, proc) } if object.is_a?(Array)
|
98
|
+
return object unless object.is_a?(Hash)
|
99
|
+
|
100
|
+
modified_hash = {}
|
101
|
+
object.each do |key, value|
|
102
|
+
modified_hash[proc.call(key)] = apply_key_mutator(value, proc)
|
103
|
+
end
|
104
|
+
modified_hash
|
105
|
+
end
|
106
|
+
|
107
|
+
private_class_method :apply_key_mutator
|
108
|
+
|
87
109
|
# Convert a ruby value into a string to be passed along to PowerShell for interpolation in a command
|
88
110
|
# Handles:
|
89
111
|
# - Strings
|
data/lib/pwsh/version.rb
CHANGED
data/metadata.json
CHANGED
data/pwshlib.md
CHANGED
@@ -88,3 +88,5 @@ Puppet.debug(posh.execute('[String]$PSVersionTable.PSVersion'))
|
|
88
88
|
ps_version = posh.execute('[String]$PSVersionTable.PSVersion')[:stdout].strip
|
89
89
|
Puppet.debug("The PowerShell version of the currently running Manager is #{ps_version}")
|
90
90
|
```
|
91
|
+
|
92
|
+
For more information, please review the [online reference documentation for the gem](https://rubydoc.info/gems/ruby-pwsh).
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-pwsh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puppet, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: PowerShell code manager for ruby.
|
14
14
|
email:
|