Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability for pre_window commands to parse yaml arrays (as well as strings) #482

Merged
merged 4 commits into from Mar 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,4 +1,7 @@
## Unreleased

- Add ability for pre_window commands to parse yaml arrays

### Misc
- Removed support for Ruby 1.9.3
- Move gem dependencies from Gemfile to tmuxinator.gemspec
Expand Down
25 changes: 11 additions & 14 deletions lib/tmuxinator/project.rb
Expand Up @@ -110,11 +110,7 @@ def name

def pre
pre_config = yaml["pre"]
if pre_config.is_a?(Array)
pre_config.join("; ")
else
pre_config
end
parsed_parameters(pre_config)
end

def attach?
Expand All @@ -129,23 +125,20 @@ def attach?

def pre_window
if rbenv?
"rbenv shell #{yaml['rbenv']}"
params = "rbenv shell #{yaml['rbenv']}"
elsif rvm?
"rvm use #{yaml['rvm']}"
params = "rvm use #{yaml['rvm']}"
elsif pre_tab?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed that there are several conditional branches in this method. While multiple commands don't make sense for rbenv or rvm, would you mind also adding a call to parsed_parameters here with yaml["pre_tab"]?

yaml["pre_tab"]
params = yaml["pre_tab"]
else
yaml["pre_window"]
params = yaml["pre_window"]
end
parsed_parameters(params)
end

def post
post_config = yaml["post"]
if post_config.is_a?(Array)
post_config.join("; ")
else
post_config
end
parsed_parameters(post_config)
end

def tmux
Expand Down Expand Up @@ -306,5 +299,9 @@ def synchronize_options
def window_options
yaml["windows"].map(&:values).flatten
end

def parsed_parameters(parameters)
parameters.is_a?(Array) ? parameters.join("; ") : parameters
end
end
end
23 changes: 21 additions & 2 deletions spec/lib/tmuxinator/project_spec.rb
Expand Up @@ -172,8 +172,27 @@
end

describe "#pre_window" do
it "gets the pre_window command" do
expect(project.pre_window).to eq "rbenv shell 2.0.0-p247"
subject(:pre_window) { project.pre_window }

context "pre_window in yaml is string" do
before { project.yaml["pre_window"] = "mysql.server start" }

it "returns the string" do
expect(pre_window).to eq("mysql.server start")
end
end

context "pre_window in yaml is Array" do
before do
project.yaml["pre_window"] = [
"mysql.server start",
"memcached -d"
]
end

it "joins array using ;" do
expect(pre_window).to eq("mysql.server start; memcached -d")
end
end

context "with deprecations" do
Expand Down