FoodCritic023: Prefer conditional attributes
FoodCritic (www.foodcritic.io) is a lint tool for your Chef (learn.chef.io) cookbooks. FC023 indicates that you should prefer Chef guards over Ruby conditions. This challenge expects you to be able to fix this issue in a sample cookbook, given the FoodCritic output: ================================================================ FC023: Prefer conditional attributes: cookbooks/foo/recipes/default.rb:25 ================================================================ See http://www.foodcritic.io/#FC023 for more details about the changes being made.
Start file
# Cookbook Name:: foo # Recipe:: default # # Copyright 2015, Foo Inc. # # All rights reserved - Do Not Redistribute # directory "/opt/foo" do end remote_file "/tmp/foo.rpm" do source "http://foo.inc/packages/foo.rpm" action :create end rpm_package "/tmp/foo.rpm" do action :install end service "foo" do action :start end if node["foo"] == "bar" execute "bar my foo" do command "foo < bar" end end
End file
# Cookbook Name:: foo # Recipe:: default # # Copyright 2015, Foo Inc. # # All rights reserved - Do Not Redistribute # directory "/opt/foo" do end remote_file "/tmp/foo.rpm" do source "http://foo.inc/packages/foo.rpm" action :create end rpm_package "/tmp/foo.rpm" do action :install end service "foo" do action :start end execute "bar my foo" do command "foo < bar" only_if { node["foo"] == "bar" } end
View Diff
25,28c25,27 < if node["foo"] == "bar" < execute "bar my foo" do < command "foo < bar" < end --- > execute "bar my foo" do > command "foo < bar" > only_if { node["foo"] == "bar" }
Solutions
The best way to learn is to practice. Below, you will find some of the solutions other golfers have entered. To unlock higher ranked solutions, submit your own entry which does as well or better than the solutions you can currently see - climb the ladder!
Check out these helpful resources to improve your Vim skills... Game on.
#53 Jakob Schöttl / @jschoettl - Score: 53 - 12/20/15 @ 00:24
/if<CR>dw"aDddjoonly_if { <Esc>pu"apA }<Esc>jjddb0<C-V>j<Esc><Esc><C-V>kkkld:wq<CR>
0 comments