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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 461a867f01c932c2baaaee8211f32cec09921d1e1b8f706fc7abe9dba7489d7b
4
- data.tar.gz: 9086a7408096976b332b8b1fe97771de8d86788d3ac2a87421493b89b9215311
3
+ metadata.gz: b9ff0bf2c8d109926cd0161323e4d49e6b697410883d5c6da7e8beda5cf8de6d
4
+ data.tar.gz: da85cd63a46c1d75b0b1178d9841f3d3e134ad20dead8847eb724d52bec3a847
5
5
  SHA512:
6
- metadata.gz: ed6bff68ed27bcb1db20103cf7105bea51776456073f457177c029251aa0c2c0b9d7aec1085f86141b1c88ce0c06da4e7cf5ac6a3375b7aca5684c06c575b2fb
7
- data.tar.gz: 29a9c33098583b09e10ed5c18f706da954e5ce1d1b1f5fdf24ba086128da851d1e24e954ae9b0735abc3cd95d9bc4faaec61d327c78595fac04c50c9123b4d5c
6
+ metadata.gz: '09007c0add66995ff0a978129c9b3da760d4d5a9a95bad6bf77226afdcbdeab2508ad68ac39c2217bd5bd57be41904b18333dcba14365441c98582291224782a'
7
+ data.tar.gz: 2157ae9772fefc54271500a3d7d84502d1737e45fc54986405e45da962fb40fd855d482b4e31aa33febb61756f9d6944f9db82a4fb1f6dcea696ec7f6b81beea
data/.gitignore CHANGED
@@ -13,3 +13,6 @@
13
13
 
14
14
  Gemfile.local
15
15
  Gemfile.lock
16
+
17
+ # build output
18
+ /ruby-pwsh-*.gem
data/.pmtignore CHANGED
@@ -13,7 +13,9 @@ CODEOWNERS
13
13
  CONTRIBUTING.md
14
14
  design-comms.png
15
15
  DESIGN.md
16
+ pwshlib.md
16
17
  Gemfile
17
18
  Gemfile.lock
18
19
  Rakefile
19
20
  ruby-pwsh.gemspec
21
+ *.gem
@@ -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/IndentHeredoc:
22
+ Layout/HeredocIndentation:
23
23
  Enabled: false
24
24
  # Need to ignore rubocop complaining about the name of the library.
25
25
  Naming/FileName:
@@ -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.2.0](https://github.com/puppetlabs/ruby-pwsh/tree/0.2.0) (2019-11-25)
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
@@ -11,7 +11,7 @@ group :test do
11
11
  gem 'rspec', '~> 3.0'
12
12
  gem 'rspec-collection_matchers', '~> 1.0'
13
13
  gem 'rspec-its', '~> 1.0'
14
- gem 'rubocop'
14
+ gem 'rubocop', '>= 0.77'
15
15
  gem 'rubocop-rspec'
16
16
  gem 'simplecov'
17
17
  end
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.
@@ -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(string)
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
- string.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
41
- .gsub(/([a-z\d])([A-Z])/, '\1_\2')
42
- .tr('-', '_')
43
- .gsub(/\s/, '_')
44
- .gsub(/__+/, '_')
45
- .downcase
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(hash)
52
- modified_hash = {}
53
- hash.each do |key, value|
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(string)
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(string).split('_').collect(&:capitalize).join
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(hash)
72
- modified_hash = {}
73
- hash.each do |key, value|
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
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Pwsh
4
4
  # The version of the ruby-pwsh gem
5
- VERSION = '0.2.0'
5
+ VERSION = '0.3.0'
6
6
  end
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "puppetlabs-pwshlib",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "author": "puppetlabs",
5
5
  "summary": "Provide library code for interoperating with PowerShell.",
6
6
  "license": "MIT",
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.2.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-26 00:00:00.000000000 Z
11
+ date: 2019-12-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: PowerShell code manager for ruby.
14
14
  email: