-
-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #565 from DannyBen/refactor/variables
Refactor `command.variables` to a new `Variable` object
- Loading branch information
Showing
9 changed files
with
95 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module Bashly | ||
module Script | ||
module Introspection | ||
module Variables | ||
# Returns an array of Variable objects | ||
def variables | ||
return [] unless options['variables'] | ||
|
||
options['variables'].map do |options| | ||
Variable.new options | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Bashly | ||
module Script | ||
class Variable < Base | ||
class << self | ||
def option_keys | ||
@option_keys ||= %i[name value] | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,5 @@ | ||
= view_marker | ||
|
||
variables.each do |var| | ||
case var['value'] | ||
when Array | ||
if var['value'].empty? | ||
> declare -a {{ var['name'] }}=() | ||
else | ||
> declare -a {{ var['name'] }}=( | ||
var['value'].each do |v| | ||
> "{{ v }}" | ||
end | ||
> ) | ||
end | ||
when Hash | ||
if var['value'].empty? | ||
> declare -A {{ var['name'] }}=() | ||
else | ||
> declare -A {{ var['name'] }}=( | ||
var['value'].each do |k, v| | ||
> ["{{ k }}"]="{{ v }}" | ||
end | ||
> ) | ||
end | ||
when String, NilClass | ||
> {{ var['name'] }}="{{ var['value'] }}" | ||
else | ||
> {{ var['name'] }}={{ var['value'] }} | ||
end | ||
= var.render(:definition) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
= view_marker | ||
|
||
case value | ||
when Array | ||
if value.empty? | ||
> declare -a {{ name }}=() | ||
else | ||
> declare -a {{ name }}=( | ||
value.each do |v| | ||
> "{{ v }}" | ||
end | ||
> ) | ||
end | ||
when Hash | ||
if value.empty? | ||
> declare -A {{ name }}=() | ||
else | ||
> declare -A {{ name }}=( | ||
value.each do |k, v| | ||
> ["{{ k }}"]="{{ v }}" | ||
end | ||
> ) | ||
end | ||
when String, NilClass | ||
> {{ name }}="{{ value }}" | ||
else | ||
> {{ name }}={{ value }} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
describe Script::Introspection::Variables do | ||
subject do | ||
result = Script::Command.new fixtures[fixture] | ||
result.parents = result.options['parents'] | ||
result | ||
end | ||
|
||
let(:fixtures) { load_fixture 'script/commands' } | ||
let(:fixture) { :variables } | ||
|
||
describe '#variables' do | ||
it 'returns an array of Variable objects' do | ||
expect(subject.variables).to be_an Array | ||
expect(subject.variables).to all(be_a Script::Variable) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters