bashvar 0.1.0 → 0.1.1
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/bashvar.md +7 -3
- data/lib/bashvar/version.rb +1 -1
- data/lib/bashvar.rb +7 -6
- metadata +1 -9
- data/.fasterer.yml +0 -3
- data/.github/workflows/gem-push.yml +0 -23
- data/.github/workflows/ruby.yml +0 -36
- data/.gitignore +0 -8
- data/.rubocop.yml +0 -37
- data/Gemfile +0 -7
- data/Rakefile +0 -8
- data/bashvar.gemspec +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1e949f40c11e89c95ef0a82f1ea3cbdb46fd27d1725af7cde5cd9d12516d6e5
|
4
|
+
data.tar.gz: 5915c4b53fa94124d9732573e4c04788d700a5ca97455eb627f8dd94d236c2f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e76591e05f77df4c16e96bc052c5025d48d76fa8613786196c096eb67296ddf3903808098790224ac9ff72818c9fa3390f6085f0f4a5ca76b538a93e8868f8e
|
7
|
+
data.tar.gz: ae58d5cee8b00d1536ec5d460414da8cb03280344f80f7003098c6818b17f74e1ae3624cdf71e9c0594a66697a2a160d17574460e736e5ff6bb1602dc25e5e57
|
data/bashvar.md
CHANGED
@@ -50,7 +50,9 @@ class BashVar
|
|
50
50
|
#
|
51
51
|
# @param input [String] Multi-line string containing the raw output of
|
52
52
|
# `compgen -v | while read -r var; do declare -p "$var"; done`.
|
53
|
-
# @
|
53
|
+
# @param symbolize_names [Boolean] When true, returns a Hash with symbolized keys.
|
54
|
+
# Defaults to false.
|
55
|
+
# @return [Hash{(String | Symbol) => (String, Integer, Array, Hash)}]
|
54
56
|
# Variable name mapped to decoded Ruby value.
|
55
57
|
#
|
56
58
|
# Type mapping rules:
|
@@ -59,7 +61,7 @@ class BashVar
|
|
59
61
|
# -i -> Integer (fallback String)
|
60
62
|
# else -> String
|
61
63
|
#
|
62
|
-
def self.parse(input)
|
64
|
+
def self.parse(input, symbolize_names: false)
|
63
65
|
...
|
64
66
|
end
|
65
67
|
end
|
@@ -68,9 +70,11 @@ end
|
|
68
70
|
### Error Handling
|
69
71
|
|
70
72
|
- Method **must never raise** on malformed lines; skip unparseable entries.
|
71
|
-
- Recoverable parse anomalies (e.g., unknown escape `\\z`)
|
73
|
+
- Recoverable parse anomalies (e.g., unknown escape `\\z`)
|
74
|
+
leave literal `z` w/o backslash.
|
72
75
|
- Return empty `{}` if `input.nil?` or blank.
|
73
76
|
|
77
|
+
|
74
78
|
---
|
75
79
|
|
76
80
|
## 5. Escape Decoding Rules
|
data/lib/bashvar/version.rb
CHANGED
data/lib/bashvar.rb
CHANGED
@@ -4,7 +4,7 @@ require_relative 'bashvar/version'
|
|
4
4
|
|
5
5
|
class BashVar
|
6
6
|
class << self
|
7
|
-
def parse(input)
|
7
|
+
def parse(input, symbolize_names: false)
|
8
8
|
return {} if input.nil? || input.strip.empty?
|
9
9
|
|
10
10
|
vars = {}
|
@@ -23,14 +23,14 @@ class BashVar
|
|
23
23
|
next if flags.include?('f') && !flags.match?(/-[^A-Za-z]*[ai]/) # crude but protects `declare -f`
|
24
24
|
|
25
25
|
value = if flags.include?('a') || flags.include?('A')
|
26
|
-
parse_array_like(raw, assoc: flags.include?('A'))
|
26
|
+
parse_array_like(raw, assoc: flags.include?('A'), symbolize_names: symbolize_names)
|
27
27
|
elsif flags.include?('i')
|
28
28
|
parse_integer(raw)
|
29
29
|
else
|
30
30
|
parse_scalar(raw)
|
31
31
|
end
|
32
|
-
|
33
|
-
vars[
|
32
|
+
key = symbolize_names ? name.to_sym : name
|
33
|
+
vars[key] = value
|
34
34
|
end
|
35
35
|
vars
|
36
36
|
end
|
@@ -65,7 +65,7 @@ class BashVar
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
-
def parse_array_like(raw, assoc: false)
|
68
|
+
def parse_array_like(raw, assoc: false, symbolize_names: false)
|
69
69
|
s = raw.strip
|
70
70
|
# expect quoted wrapper; tolerate missing quotes
|
71
71
|
# Corrected string comparisons for quotes
|
@@ -86,7 +86,8 @@ class BashVar
|
|
86
86
|
key_str = parse_scalar(k.strip.gsub(/^"|"$/, '').gsub(/^'|'$/, '')) # keys seldom quoted; defensive
|
87
87
|
val_str = parse_scalar(v)
|
88
88
|
if assoc
|
89
|
-
|
89
|
+
key = symbolize_names ? key_str.to_sym : key_str
|
90
|
+
result[key] = val_str
|
90
91
|
else
|
91
92
|
idx = key_str.to_i
|
92
93
|
result[idx] = val_str
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bashvar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daisuke Fujimura
|
@@ -88,16 +88,8 @@ executables: []
|
|
88
88
|
extensions: []
|
89
89
|
extra_rdoc_files: []
|
90
90
|
files:
|
91
|
-
- ".fasterer.yml"
|
92
|
-
- ".github/workflows/gem-push.yml"
|
93
|
-
- ".github/workflows/ruby.yml"
|
94
|
-
- ".gitignore"
|
95
|
-
- ".rubocop.yml"
|
96
|
-
- Gemfile
|
97
91
|
- LICENSE
|
98
92
|
- README.md
|
99
|
-
- Rakefile
|
100
|
-
- bashvar.gemspec
|
101
93
|
- bashvar.md
|
102
94
|
- lib/bashvar.rb
|
103
95
|
- lib/bashvar/version.rb
|
data/.fasterer.yml
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
name: Ruby Gem
|
2
|
-
|
3
|
-
on:
|
4
|
-
push:
|
5
|
-
tags:
|
6
|
-
- v*
|
7
|
-
|
8
|
-
jobs:
|
9
|
-
build:
|
10
|
-
name: Build + Publish
|
11
|
-
runs-on: ubuntu-latest
|
12
|
-
permissions:
|
13
|
-
contents: read
|
14
|
-
id-token: write
|
15
|
-
packages: write
|
16
|
-
|
17
|
-
steps:
|
18
|
-
- uses: actions/checkout@v4
|
19
|
-
- uses: ruby/setup-ruby@v1
|
20
|
-
with:
|
21
|
-
ruby-version: '3.4.5'
|
22
|
-
bundler-cache: true
|
23
|
-
- uses: rubygems/release-gem@v1
|
data/.github/workflows/ruby.yml
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
# This workflow uses actions that are not certified by GitHub.
|
2
|
-
# They are provided by a third-party and are governed by
|
3
|
-
# separate terms of service, privacy policy, and support
|
4
|
-
# documentation.
|
5
|
-
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
-
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
-
|
8
|
-
name: Ruby
|
9
|
-
|
10
|
-
on:
|
11
|
-
push:
|
12
|
-
branches: [ "master" ]
|
13
|
-
pull_request:
|
14
|
-
branches: [ "master" ]
|
15
|
-
|
16
|
-
permissions:
|
17
|
-
contents: read
|
18
|
-
|
19
|
-
jobs:
|
20
|
-
test:
|
21
|
-
runs-on: ubuntu-latest
|
22
|
-
steps:
|
23
|
-
- uses: actions/checkout@v4
|
24
|
-
- name: Set up Ruby
|
25
|
-
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
26
|
-
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
27
|
-
uses: ruby/setup-ruby@v1
|
28
|
-
with:
|
29
|
-
ruby-version: '3.4.5'
|
30
|
-
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
31
|
-
- name: Run rubocop
|
32
|
-
run: bundle exec rubocop --format simple
|
33
|
-
- name: Run fasterer
|
34
|
-
run: bundle exec fasterer
|
35
|
-
- name: Run tests
|
36
|
-
run: bundle exec rspec
|
data/.gitignore
DELETED
data/.rubocop.yml
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
require: rubocop-performance
|
2
|
-
|
3
|
-
AllCops:
|
4
|
-
NewCops: enable
|
5
|
-
SuggestExtensions: false
|
6
|
-
TargetRubyVersion: 3.2
|
7
|
-
Exclude:
|
8
|
-
- 'vendor/**/*'
|
9
|
-
|
10
|
-
Gemspec/DevelopmentDependencies:
|
11
|
-
EnforcedStyle: gemspec
|
12
|
-
|
13
|
-
Layout/LineLength:
|
14
|
-
Max: 160
|
15
|
-
Exclude:
|
16
|
-
- '*.gemspec'
|
17
|
-
|
18
|
-
Metrics/AbcSize:
|
19
|
-
Max: 45
|
20
|
-
Metrics/BlockLength:
|
21
|
-
Exclude:
|
22
|
-
- '*.gemspec'
|
23
|
-
- 'spec/**/*'
|
24
|
-
Metrics/CyclomaticComplexity:
|
25
|
-
Max: 10
|
26
|
-
Metrics/MethodLength:
|
27
|
-
Max: 35
|
28
|
-
Metrics/ParameterLists:
|
29
|
-
Max: 8
|
30
|
-
Metrics/PerceivedComplexity:
|
31
|
-
Max: 12
|
32
|
-
|
33
|
-
Naming/FileName:
|
34
|
-
Enabled: false
|
35
|
-
|
36
|
-
Style/Documentation:
|
37
|
-
Enabled: false
|
data/Gemfile
DELETED
data/Rakefile
DELETED
data/bashvar.gemspec
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'lib/bashvar/version'
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = 'bashvar'
|
7
|
-
spec.version = BashVar::VERSION
|
8
|
-
spec.authors = ['Daisuke Fujimura']
|
9
|
-
spec.email = ['booleanlabel@gmail.com']
|
10
|
-
|
11
|
-
spec.summary = 'Parse Bash declare -p output into Ruby data structures.'
|
12
|
-
spec.description = "A simple, dependency-free Ruby library to parse the output of Bash's `declare -p` command, converting shell variables into corresponding Ruby types like String, Integer, Array, and Hash."
|
13
|
-
spec.homepage = 'https://github.com/fd00/bashvar'
|
14
|
-
spec.license = 'MIT'
|
15
|
-
spec.required_ruby_version = '>= 3.2.0'
|
16
|
-
|
17
|
-
spec.metadata['homepage_uri'] = spec.homepage
|
18
|
-
spec.metadata['source_code_uri'] = spec.homepage
|
19
|
-
spec.metadata['rubygems_mfa_required'] = 'true'
|
20
|
-
|
21
|
-
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
22
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(spec|features)/}) }
|
23
|
-
end
|
24
|
-
spec.bindir = 'exe'
|
25
|
-
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
26
|
-
spec.require_paths = ['lib']
|
27
|
-
|
28
|
-
spec.add_development_dependency 'fasterer', '>= 0.11.0'
|
29
|
-
spec.add_development_dependency 'rake', '>= 13.3.0'
|
30
|
-
spec.add_development_dependency 'rspec', '>= 3.13.1'
|
31
|
-
spec.add_development_dependency 'rubocop', '>= 1.78.0'
|
32
|
-
spec.add_development_dependency 'rubocop-performance', '>= 1.25.0'
|
33
|
-
end
|