Skip to content

Commit 7e568f5

Browse files
authored
Merge pull request #428 from DannyBen/refactor/x_arbitrary
Refactor arbitrary options from x- to x_
2 parents 5d646db + 6984f1a commit 7e568f5

File tree

7 files changed

+41
-35
lines changed

7 files changed

+41
-35
lines changed

lib/bashly/concerns/validation_helpers.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ def assert_hash(key, value, keys: nil)
4040

4141
return unless keys
4242

43-
invalid_keys = value.keys.map(&:to_sym) - keys
44-
invalid_keys.reject! { |key| key.start_with? 'x-' }
43+
invalid_keys = (value.keys.map(&:to_sym) - keys).reject { |k| k.start_with? 'x_' }
4544
assert invalid_keys.empty?, "#{key} contains invalid options: #{invalid_keys.join ', '}"
4645
end
4746

lib/bashly/script/base.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ def method_missing(method_name, *arguments, &block)
3535
end
3636

3737
def respond_to_missing?(method_name, include_private = false)
38-
self.class.option_keys.include?(method_name) || super
38+
self.class.option_keys.include?(method_name) ||
39+
method_name.to_s.start_with?('x_') || super
3940
end
4041
end
4142
end

schemas/bashly.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
"definitions": {
44
"custom-properties": {
55
"patternProperties": {
6-
"^x-.": {
6+
"^x_.": {
77
"title": "custom property",
88
"description": "A custom property of any type",
99
"examples": [
10-
"This command shows the status of all `images`, `containers` and `volumes`. Use with `--verbose` to see deleted containers."
10+
"Anything"
1111
]
1212
}
1313
}

spec/bashly/script/base_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
expect { subject.no_such_option }.to raise_error(NoMethodError)
2626
end
2727
end
28+
29+
context 'when the method starts with x_ and does not exist' do
30+
it 'returns nil' do
31+
expect(subject.x_no_such_option).to be_nil
32+
end
33+
end
2834
end
2935

3036
describe '#optional' do

spec/fixtures/script/x-arbitrary.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: docker
2+
x_string: hello
3+
x_hash: { key: value }
4+
x_array: [1, 2]
5+
x_int: 1
6+
x_float: 1.2
7+
x_boolean: yes
8+
x_nil: ~
9+
10+
environment_variables:
11+
- name: rush_config
12+
x_any: hello
13+
14+
commands:
15+
- name: status
16+
x_any: hello
17+
18+
args:
19+
- name: repo
20+
x_any: hello
21+
22+
flags:
23+
- long: --purge
24+
x_any: hello
25+
26+
- name: images
27+
commands:
28+
- name: ls
29+
x_any: hello

support/runfile/schema.runfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ helpers do
4343

4444
def check_arbitrary
4545
say "\ngub`Arbitrary`"
46-
file = 'spec/fixtures/script/x-arbitrary.yml'
46+
file = 'spec/fixtures/script/x_arbitrary.yml'
4747
schema_check file
4848
end
4949

0 commit comments

Comments
 (0)