fedux_org-stdlib 0.6.40 → 0.6.43
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/Gemfile.lock +1 -1
- data/lib/fedux_org_stdlib/core_ext/hash/options.rb +24 -1
- data/lib/fedux_org_stdlib/core_ext/shellwords/clean.rb +11 -0
- data/lib/fedux_org_stdlib/file_template.rb +8 -0
- data/lib/fedux_org_stdlib/version.rb +1 -1
- data/spec/app_config_spec.rb +5 -3
- data/spec/core_ext/hash/options_spec.rb +24 -0
- data/spec/core_ext/shellwords/clean_spec.rb +23 -0
- data/spec/template_file_spec.rb +20 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d70df22862cf89bde4bef5464ceaab686e727549
|
4
|
+
data.tar.gz: 4f615986ce1f3a5a04307bf2b2a1af55bc282141
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2adf3d393744ebdfafc5ba57ee182d9f4831a495de6d2a1b017aea791aac1358958e83ae43f55af660f25c9fdc0b9472ca03d6a4da3ccda6b1c43dd6e2da2a57
|
7
|
+
data.tar.gz: f8a609875743f1eb60222405ff879d83fed7c92b6edf7161ac9bf0f6ecbe25e230f609e514f1c71fbf701f11bf9647966d3d86465997d4a4c82dba7238104c33
|
data/Gemfile.lock
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
require 'shellwords'
|
3
|
+
require 'fedux_org_stdlib/core_ext/shellwords/clean'
|
4
|
+
|
2
5
|
class Hash
|
3
6
|
# Convert hash to command line options
|
4
7
|
#
|
@@ -28,15 +31,35 @@ class Hash
|
|
28
31
|
#
|
29
32
|
# hash.to_options
|
30
33
|
# # => [ '--opt1', 'string']
|
34
|
+
#
|
35
|
+
# @example Clean keys
|
36
|
+
#
|
37
|
+
# hash = {
|
38
|
+
# '$opt1' => 'string'
|
39
|
+
# }
|
40
|
+
#
|
41
|
+
# hash.to_options
|
42
|
+
# # => [ '--opt1', 'string']
|
43
|
+
#
|
44
|
+
# @example Escape values
|
45
|
+
#
|
46
|
+
# hash = {
|
47
|
+
# 'opt1' => '$string'
|
48
|
+
# }
|
49
|
+
#
|
50
|
+
# hash.to_options
|
51
|
+
# # => [ '--opt1', '\$string']
|
31
52
|
def to_options
|
32
53
|
each_with_object([]) do |(key, value), a|
|
54
|
+
key = Shellwords.clean(key)
|
55
|
+
|
33
56
|
if value.is_a? TrueClass
|
34
57
|
a << "--#{key}"
|
35
58
|
elsif value.is_a? FalseClass
|
36
59
|
a << "--no-#{key}"
|
37
60
|
else
|
38
61
|
a << "--#{key}"
|
39
|
-
a << value
|
62
|
+
a << Shellwords.escape(value)
|
40
63
|
end
|
41
64
|
end
|
42
65
|
end
|
@@ -210,8 +210,16 @@ module FeduxOrgStdlib
|
|
210
210
|
ext.any? { |e| e == extname }
|
211
211
|
end
|
212
212
|
|
213
|
+
def proposed_file_name
|
214
|
+
template_name
|
215
|
+
end
|
216
|
+
|
213
217
|
public
|
214
218
|
|
219
|
+
def proposed_file
|
220
|
+
File.join working_directory, proposed_file_name
|
221
|
+
end
|
222
|
+
|
215
223
|
def proposed_extname
|
216
224
|
ext = File.extname(basename)
|
217
225
|
|
data/spec/app_config_spec.rb
CHANGED
@@ -44,9 +44,11 @@ RSpec.describe AppConfig do
|
|
44
44
|
config = config_klass.new
|
45
45
|
expect(config.opt1).to be_nil
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
silence :stderr do
|
48
|
+
expect {
|
49
|
+
config.opt1 = 'blub'
|
50
|
+
}.to raise_error NoMethodError
|
51
|
+
end
|
50
52
|
end
|
51
53
|
end
|
52
54
|
|
@@ -48,4 +48,28 @@ RSpec.describe '#to_options' do
|
|
48
48
|
|
49
49
|
expect(hash.to_options).to eq %w{ --opt1 string }
|
50
50
|
end
|
51
|
+
|
52
|
+
it 'handles umlauts as well' do
|
53
|
+
hash = {
|
54
|
+
"öäopt1" => 'string'
|
55
|
+
}
|
56
|
+
|
57
|
+
expect(hash.to_options).to eq %w{ --opt1 string }
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'handles special characters as well' do
|
61
|
+
hash = {
|
62
|
+
"$o p\tt1" => 'string'
|
63
|
+
}
|
64
|
+
|
65
|
+
expect(hash.to_options).to eq %w{ --opt1 string }
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'handles special characters in value as well' do
|
69
|
+
hash = {
|
70
|
+
opt1: 'string$string string'
|
71
|
+
}
|
72
|
+
|
73
|
+
expect(hash.to_options).to eq ['--opt1', 'string\$string\ string']
|
74
|
+
end
|
51
75
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'fedux_org_stdlib/core_ext/shellwords/clean'
|
4
|
+
|
5
|
+
RSpec.describe '.shellclean' do
|
6
|
+
it 'returns a normal string as normal string' do
|
7
|
+
result = Shellwords.clean('asdf')
|
8
|
+
|
9
|
+
expect(result).to eq 'asdf'
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'removes whitespace' do
|
13
|
+
result = Shellwords.clean("asdf asdf\tasdf")
|
14
|
+
|
15
|
+
expect(result).to eq 'asdfasdfasdf'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'removes $' do
|
19
|
+
result = Shellwords.clean("asdf$asdf")
|
20
|
+
|
21
|
+
expect(result).to eq 'asdfasdf'
|
22
|
+
end
|
23
|
+
end
|
data/spec/template_file_spec.rb
CHANGED
@@ -3,6 +3,26 @@ require 'spec_helper'
|
|
3
3
|
require 'fedux_org_stdlib/file_template'
|
4
4
|
|
5
5
|
RSpec.describe FileTemplate do
|
6
|
+
|
7
|
+
context '#proposed_file' do
|
8
|
+
it 'generates a propose file path based on template basename' do
|
9
|
+
with_environment 'HOME' => working_directory do
|
10
|
+
template_klass = Class.new(FileTemplate) do
|
11
|
+
def class_name
|
12
|
+
'TestTemplate'
|
13
|
+
end
|
14
|
+
|
15
|
+
def module_name
|
16
|
+
'MyApplication'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
template = template_klass.new(working_directory: working_directory)
|
21
|
+
expect(template.proposed_file).to eq File.join(working_directory, 'test')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
6
26
|
context '#preferred_template_file' do
|
7
27
|
it 'has a default template file which is the preferred place to store the template' do
|
8
28
|
with_environment 'HOME' => working_directory do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fedux_org-stdlib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.43
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Meyer
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- lib/fedux_org_stdlib/command/which.rb
|
59
59
|
- lib/fedux_org_stdlib/core_ext/array.rb
|
60
60
|
- lib/fedux_org_stdlib/core_ext/hash/options.rb
|
61
|
+
- lib/fedux_org_stdlib/core_ext/shellwords/clean.rb
|
61
62
|
- lib/fedux_org_stdlib/core_ext/string.rb
|
62
63
|
- lib/fedux_org_stdlib/environment.rb
|
63
64
|
- lib/fedux_org_stdlib/file_template.rb
|
@@ -139,6 +140,7 @@ files:
|
|
139
140
|
- spec/command/run_command_spec.rb
|
140
141
|
- spec/command/which_spec.rb
|
141
142
|
- spec/core_ext/hash/options_spec.rb
|
143
|
+
- spec/core_ext/shellwords/clean_spec.rb
|
142
144
|
- spec/environment_spec.rb
|
143
145
|
- spec/examples/models/class_based/forbidden_keyword.rb
|
144
146
|
- spec/examples/models/class_based/ignore/ignored.rb
|
@@ -208,6 +210,7 @@ test_files:
|
|
208
210
|
- spec/command/run_command_spec.rb
|
209
211
|
- spec/command/which_spec.rb
|
210
212
|
- spec/core_ext/hash/options_spec.rb
|
213
|
+
- spec/core_ext/shellwords/clean_spec.rb
|
211
214
|
- spec/environment_spec.rb
|
212
215
|
- spec/examples/models/class_based/forbidden_keyword.rb
|
213
216
|
- spec/examples/models/class_based/ignore/ignored.rb
|