From 30bcc3340120c1bfaea6cdba4b81d6208a0eb03b Mon Sep 17 00:00:00 2001 From: Rogerio de Paula Assis Date: Wed, 9 Nov 2016 12:33:17 +1100 Subject: [PATCH 1/6] Add ability for pre_window commands to parse yaml arrays --- CHANGELOG.md | 3 +++ lib/tmuxinator/project.rb | 3 ++- spec/lib/tmuxinator/project_spec.rb | 23 +++++++++++++++++++++-- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b913ac..8ba54ad 100644 --- a/CHANGELOG.md +++ b/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 diff --git a/lib/tmuxinator/project.rb b/lib/tmuxinator/project.rb index 7dbfece..135073f 100644 --- a/lib/tmuxinator/project.rb +++ b/lib/tmuxinator/project.rb @@ -135,7 +135,8 @@ module Tmuxinator elsif pre_tab? yaml["pre_tab"] else - yaml["pre_window"] + pre_window = yaml["pre_window"] + pre_window.is_a?(Array) ? pre_window.join("; ") : pre_window end end diff --git a/spec/lib/tmuxinator/project_spec.rb b/spec/lib/tmuxinator/project_spec.rb index 5e65224..bb31102 100644 --- a/spec/lib/tmuxinator/project_spec.rb +++ b/spec/lib/tmuxinator/project_spec.rb @@ -172,8 +172,27 @@ describe Tmuxinator::Project do 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 From 36e9883f2a00399fa7a322dd2fec8816c32db034 Mon Sep 17 00:00:00 2001 From: Oskar Cieslik Date: Wed, 28 Dec 2016 03:04:01 +0100 Subject: [PATCH 2/6] Inform user about 's' alias of start command --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5bf5d83..b357d5e 100644 --- a/README.md +++ b/README.md @@ -257,7 +257,7 @@ root: ~/<%= @settings["workspace"] %> ## Starting a session -This will fire up tmux with all the tabs and panes you configured. +This will fire up tmux with all the tabs and panes you configured, `start` is aliased to `s`. ``` tmuxinator start [project] -n [name] From f19e251bb736fc2f6cc6ce3f4e90fec2f181b05e Mon Sep 17 00:00:00 2001 From: Rogerio de Paula Assis Date: Mon, 30 Jan 2017 13:31:33 +1100 Subject: [PATCH 3/6] Refactored as per code review feedback --- lib/tmuxinator/project.rb | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/tmuxinator/project.rb b/lib/tmuxinator/project.rb index 135073f..4cce885 100644 --- a/lib/tmuxinator/project.rb +++ b/lib/tmuxinator/project.rb @@ -110,11 +110,7 @@ module Tmuxinator 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? @@ -136,17 +132,13 @@ module Tmuxinator yaml["pre_tab"] else pre_window = yaml["pre_window"] - pre_window.is_a?(Array) ? pre_window.join("; ") : pre_window + parsed_parameters(pre_window) end 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 @@ -307,5 +299,9 @@ module Tmuxinator def window_options yaml["windows"].map(&:values).flatten end + + def parsed_parameters(parameters) + parameters.is_a?(Array) ? parameters.join("; ") : parameters + end end end From f12946dcbba3caa8a34ca637f6d5ffc16124c525 Mon Sep 17 00:00:00 2001 From: Rogerio de Paula Assis Date: Tue, 31 Jan 2017 09:34:18 +1100 Subject: [PATCH 4/6] A bit more refactoring as per feedback --- lib/tmuxinator/project.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/tmuxinator/project.rb b/lib/tmuxinator/project.rb index 4cce885..5a05f1c 100644 --- a/lib/tmuxinator/project.rb +++ b/lib/tmuxinator/project.rb @@ -123,17 +123,17 @@ module Tmuxinator attach end - def pre_window + 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? - yaml["pre_tab"] + params = yaml["pre_tab"] else - pre_window = yaml["pre_window"] - parsed_parameters(pre_window) + params = yaml["pre_window"] end + parsed_parameters(params) end def post From cfade6b58a18b8250addb5e29ad49cc3f007cc10 Mon Sep 17 00:00:00 2001 From: Rogerio de Paula Assis Date: Tue, 31 Jan 2017 10:45:14 +1100 Subject: [PATCH 5/6] Removed trailing whitespace causing CI to fail --- lib/tmuxinator/project.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tmuxinator/project.rb b/lib/tmuxinator/project.rb index 5a05f1c..71bd776 100644 --- a/lib/tmuxinator/project.rb +++ b/lib/tmuxinator/project.rb @@ -123,7 +123,7 @@ module Tmuxinator attach end - def pre_window + def pre_window if rbenv? params = "rbenv shell #{yaml['rbenv']}" elsif rvm? @@ -131,7 +131,7 @@ module Tmuxinator elsif pre_tab? params = yaml["pre_tab"] else - params = yaml["pre_window"] + params = yaml["pre_window"] end parsed_parameters(params) end From 2e297d11111eef736f31be9f53e7fff111f5940b Mon Sep 17 00:00:00 2001 From: Adam Strickland Date: Fri, 19 May 2017 11:05:15 -0500 Subject: [PATCH 6/6] updates rubocop to 0.46.0 used by CodeClimate - removes old cops - updates source to accommodate new cops --- .rubocop.yml | 88 +++++++---------------------- bin/tmuxinator | 2 +- lib/tmuxinator/cli.rb | 2 +- lib/tmuxinator/config.rb | 3 +- lib/tmuxinator/project.rb | 32 +++++------ lib/tmuxinator/version.rb | 2 +- spec/lib/tmuxinator/cli_spec.rb | 2 +- spec/lib/tmuxinator/project_spec.rb | 3 +- spec/lib/tmuxinator/window_spec.rb | 12 ++-- tmuxinator.gemspec | 2 +- 10 files changed, 52 insertions(+), 96 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index eebf8cf..54b69ae 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -10,9 +10,10 @@ AllCops: Exclude: - "vendor/**/*" - "db/schema.rb" - RunRailsCops: false - DisplayCopNames: false + DisplayCopNames: true StyleGuideCopsOnly: false +Rails: + Enabled: false Style/AccessModifierIndentation: Description: Check indentation of private/protected visibility modifiers. StyleGuide: https://github.com/bbatsov/ruby-style-guide#indent-public-private-protected @@ -425,14 +426,10 @@ Style/TrailingBlankLines: SupportedStyles: - final_newline - final_blank_line -Style/TrailingComma: - Description: Checks for trailing comma in parameter lists and literals. - StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas +Style/TrailingCommaInLiteral: Enabled: false - EnforcedStyleForMultiline: no_comma - SupportedStyles: - - comma - - no_comma +Style/TrailingCommaInArguments: + Enabled: true Style/TrivialAccessors: Description: Prefer attr_* methods to trivial readers/writers. StyleGuide: https://github.com/bbatsov/ruby-style-guide#attr_family @@ -526,6 +523,18 @@ Metrics/PerceivedComplexity: reader. Enabled: false Max: 7 +Metrics/BlockLength: + Exclude: + - lib/tmuxinator/cli.rb + - spec/factories/**/*.rb + - spec/matchers/**/*.rb + - spec/**/*_spec.rb +Lint/PercentStringArray: + Exclude: + - lib/tmuxinator/cli.rb +Style/MutableConstant: + Exclude: + - lib/tmuxinator/project.rb Lint/AssignmentInCondition: Description: Don't use assignment in conditions. StyleGuide: https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition @@ -545,48 +554,6 @@ Lint/DefEndAlignment: SupportedStyles: - start_of_line - def -Rails/ActionFilter: - Description: Enforces consistent use of action filter methods. - Enabled: false - EnforcedStyle: action - SupportedStyles: - - action - - filter - Include: - - app/controllers/**/*.rb -Rails/DefaultScope: - Description: Checks if the argument passed to default_scope is a block. - Enabled: true - Include: - - app/models/**/*.rb -Rails/HasAndBelongsToMany: - Description: Prefer has_many :through to has_and_belongs_to_many. - Enabled: true - Include: - - app/models/**/*.rb -Rails/Output: - Description: Checks for calls to puts, print, etc. - Enabled: true - Include: - - app/**/*.rb - - config/**/*.rb - - db/**/*.rb - - lib/**/*.rb -Rails/ReadWriteAttribute: - Description: Checks for read_attribute(:attr) and write_attribute(:attr, val). - Enabled: true - Include: - - app/models/**/*.rb -Rails/ScopeArgs: - Description: Checks the arguments of ActiveRecord scopes. - Enabled: true - Include: - - app/models/**/*.rb -Rails/Validation: - Description: Use validates :attribute, hash of validations. - Enabled: true - Include: - - app/models/**/*.rb Style/InlineComment: Description: Avoid inline comments. Enabled: false @@ -679,10 +646,6 @@ Style/DefWithParentheses: Description: Use def with parentheses when there are arguments. StyleGuide: https://github.com/bbatsov/ruby-style-guide#method-parens Enabled: true -Style/DeprecatedHashMethods: - Description: Checks for use of deprecated Hash methods. - StyleGuide: https://github.com/bbatsov/ruby-style-guide#hash-key - Enabled: false Style/Documentation: Description: Document classes and non-namespace modules. Enabled: false @@ -834,7 +797,7 @@ Style/SelfAssignment: used. StyleGuide: https://github.com/bbatsov/ruby-style-guide#self-assignment Enabled: false -Style/SingleSpaceBeforeFirstArg: +Style/SpaceBeforeFirstArg: Description: Checks that exactly one space is used between a method name and the first argument for method calls without parentheses. Enabled: true @@ -846,8 +809,7 @@ Style/SpaceAfterComma: Description: Use spaces after commas. StyleGuide: https://github.com/bbatsov/ruby-style-guide#spaces-operators Enabled: true -Style/SpaceAfterControlKeyword: - Description: Use spaces after if/elsif/unless/while/until/case/when. +Style/SpaceAroundKeyword: Enabled: true Style/SpaceAfterMethodName: Description: Do not put a space between a method name and the opening parenthesis @@ -875,9 +837,6 @@ Style/SpaceAroundOperators: Description: Use spaces around operators. StyleGuide: https://github.com/bbatsov/ruby-style-guide#spaces-operators Enabled: true -Style/SpaceBeforeModifierKeyword: - Description: Put a space before the modifier keyword. - Enabled: true Style/SpaceInsideBrackets: Description: No spaces after [ or before ]. StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-spaces-braces @@ -1013,10 +972,6 @@ Lint/ShadowingOuterLocalVariable: Description: Do not use the same name as outer local variable for block arguments or block local variables. Enabled: true -Lint/SpaceBeforeFirstArg: - Description: Put a space between a method name and the first argument in a method - call without parentheses. - Enabled: true Lint/StringConversionInInterpolation: Description: Checks for Object#to_s usage in string interpolation. StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-to-s @@ -1054,6 +1009,3 @@ Lint/UselessSetterCall: Lint/Void: Description: Possible use of operator/literal/variable in void context. Enabled: false -Rails/Delegate: - Description: Prefer delegate method for delegations. - Enabled: false diff --git a/bin/tmuxinator b/bin/tmuxinator index d83b5ae..1455681 100755 --- a/bin/tmuxinator +++ b/bin/tmuxinator @@ -6,7 +6,7 @@ require "tmuxinator" name = ARGV[0] || nil -if ARGV.length == 0 && Tmuxinator::Config.local? +if ARGV.empty? && Tmuxinator::Config.local? Tmuxinator::Cli.new.local elsif name && !Tmuxinator::Cli::COMMANDS.keys.include?(name.to_sym) && Tmuxinator::Config.exists?(name) diff --git a/lib/tmuxinator/cli.rb b/lib/tmuxinator/cli.rb index 56e3325..3a3698a 100644 --- a/lib/tmuxinator/cli.rb +++ b/lib/tmuxinator/cli.rb @@ -30,7 +30,7 @@ module Tmuxinator version: "Display installed tmuxinator version", doctor: "Look for problems in your configuration", list: "Lists all tmuxinator projects" - } + }.freeze package_name "tmuxinator" \ unless Gem::Version.create(Thor::VERSION) < Gem::Version.create("0.18") diff --git a/lib/tmuxinator/config.rb b/lib/tmuxinator/config.rb index e71e7e8..94556d1 100644 --- a/lib/tmuxinator/config.rb +++ b/lib/tmuxinator/config.rb @@ -1,7 +1,8 @@ module Tmuxinator class Config LOCAL_DEFAULT = "./.tmuxinator.yml".freeze - NO_LOCAL_FILE_MSG = "Project file at ./.tmuxinator.yml doesn't exist." + NO_LOCAL_FILE_MSG = + "Project file at ./.tmuxinator.yml doesn't exist.".freeze class << self def root diff --git a/lib/tmuxinator/project.rb b/lib/tmuxinator/project.rb index 3648ab8..2bc8c42 100644 --- a/lib/tmuxinator/project.rb +++ b/lib/tmuxinator/project.rb @@ -62,9 +62,9 @@ module Tmuxinator def validate! raise "Your project file should include some windows." \ - unless self.windows? + unless windows? raise "Your project file didn't specify a 'project_name'" \ - unless self.name? + unless name? self end @@ -114,25 +114,25 @@ module Tmuxinator end def attach? - if yaml["attach"].nil? - yaml_attach = true - else - yaml_attach = yaml["attach"] - end + yaml_attach = if yaml["attach"].nil? + true + else + yaml["attach"] + end attach = force_attach || !force_detach && yaml_attach attach end def pre_window - if rbenv? - params = "rbenv shell #{yaml['rbenv']}" - elsif rvm? - params = "rvm use #{yaml['rvm']}" - elsif pre_tab? - params = yaml["pre_tab"] - else - params = yaml["pre_window"] - end + params = if rbenv? + "rbenv shell #{yaml['rbenv']}" + elsif rvm? + "rvm use #{yaml['rvm']}" + elsif pre_tab? + yaml["pre_tab"] + else + yaml["pre_window"] + end parsed_parameters(params) end diff --git a/lib/tmuxinator/version.rb b/lib/tmuxinator/version.rb index d503c30..5daff9d 100644 --- a/lib/tmuxinator/version.rb +++ b/lib/tmuxinator/version.rb @@ -1,3 +1,3 @@ module Tmuxinator - VERSION = "0.9.0" + VERSION = "0.9.0".freeze end diff --git a/spec/lib/tmuxinator/cli_spec.rb b/spec/lib/tmuxinator/cli_spec.rb index 9fc5e9b..f57f633 100644 --- a/spec/lib/tmuxinator/cli_spec.rb +++ b/spec/lib/tmuxinator/cli_spec.rb @@ -73,7 +73,7 @@ describe Tmuxinator::Cli do end it "accepts a flag for alternate name" do - ARGV.replace(["start", "foo" "--name=bar"]) + ARGV.replace(["start", "foo", "--name=bar"]) expect(Kernel).to receive(:exec) capture_io { cli.start } diff --git a/spec/lib/tmuxinator/project_spec.rb b/spec/lib/tmuxinator/project_spec.rb index 658bb34..837675a 100644 --- a/spec/lib/tmuxinator/project_spec.rb +++ b/spec/lib/tmuxinator/project_spec.rb @@ -166,7 +166,8 @@ describe Tmuxinator::Project do rendered = project_with_literals_as_window_name expect(rendered.windows.map(&:name)).to match_array( %w(222 222333 111222333444555666777 222.3 4e5 4E5 - true false nil // /sample/)) + true false nil // /sample/) + ) end end end diff --git a/spec/lib/tmuxinator/window_spec.rb b/spec/lib/tmuxinator/window_spec.rb index 1b405f1..5fa7503 100644 --- a/spec/lib/tmuxinator/window_spec.rb +++ b/spec/lib/tmuxinator/window_spec.rb @@ -99,11 +99,13 @@ describe Tmuxinator::Window do project: project, tab: window ) - expect(window.panes).to match([ - a_pane.with(index: 0).and_commands("vim"), - a_pane.with(index: 1).and_commands("ls"), - a_pane.with(index: 2).and_commands("top") - ]) + expect(window.panes).to match( + [ + a_pane.with(index: 0).and_commands("vim"), + a_pane.with(index: 1).and_commands("ls"), + a_pane.with(index: 2).and_commands("top") + ] + ) end end diff --git a/tmuxinator.gemspec b/tmuxinator.gemspec index a055ac5..13183b0 100644 --- a/tmuxinator.gemspec +++ b/tmuxinator.gemspec @@ -50,6 +50,6 @@ Gem::Specification.new do |s| s.add_development_dependency "pry", "~> 0.10" s.add_development_dependency "factory_girl", "~> 4.5" s.add_development_dependency "activesupport", "< 5.0.0" # Please see issue #432 - s.add_development_dependency "rubocop", "~> 0.35.1" + s.add_development_dependency "rubocop", "~> 0.46.0" end