phallstrom / slackistrano

Slack integration for Capistrano deployments.
MIT License
373 stars 74 forks source link

add lazily loaded example to Readme #52

Closed btsuhako closed 8 years ago

btsuhako commented 8 years ago

Example of when a variable may have different value from stage to stage. Lambdas FTW!

phallstrom commented 8 years ago

@btsuhako I've had a crazy long day and my brain isn't working quite right. Can you explain what you mean and why this is useful? I'm not getting where you're pulling 'branch' from.

btsuhako commented 8 years ago

No worries. I was using a branch variable in my PR, but it may not be the best example. Say we have the following:

project/config/deploy/stage1.rb

set :branch, 'my-branch'

project/config/deploy/stage2.rb

set :branch, 'another-branch'

project/config/deploy.rb

# Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
set :slack_revision, `git rev-parse origin/#{fetch(:branch)}`,strip! }

No matter what stage I deployed, Capistrano was posting master for the :slack_revision in Slack. Turns out that deploy.rb is evaluated, sets all the values, and stageX.rb is ran afterwards without redoing values in deploy.rb. The solution I found was http://capistranorb.com/documentation/faq/how-can-i-access-stage-configuration-variables/, which uses Ruby lambdas to lazy load symbol values in deploy.rb. I thought it would be useful to include an example in your Readme.

btsuhako commented 8 years ago

Btw, thanks for the awesome gem! It's helped us add a lot of visibility and increased communication around our deployments

phallstrom commented 8 years ago

@btsuhako Ah! That makes total sense. Would you mind tweaking your commit a bit to add some of that language/explanation? Perhaps just as part of the note would be sufficient. Definitely a good addition.

Thanks! Glad you like the gem!

btsuhako commented 8 years ago

Let me know if that makes sense. It's ready to merge!

phallstrom commented 8 years ago

thx!