Warbler: Dynamic War Naming

I’d like to be able to give my wars a dynamic name (which includes the
svn
branch, svn revision, date stamp, etc.).

warble.rb: https://gist.github.com/3183573
warble.rake: warble.rake · GitHub

This works, but the war naming routine runs once for every prerequisite
rake task (assets:clean, assets:precompile, etc.). It’s a relatively
expensive routine, so I’d like to get it to run only once.

Also, I’m new to Rake (and Ruby), so my code is probably pretty ugly,
and
I’ll gladly take suggestions.

Thanks,
Jamie

I think it’s just because the instance variable in which you’re trying
to cache the name lives in an object that is not long-lived. Perhaps
try moving the code into a module as class methods like this, so the
instance variable lives in the module object which is not going to be
refreshed.

module Warbler
  def self.create_war_name
    ...
  end
  def self.svn_war_name
    @war_name ||= create_war_name
  end
end

Warbler::Config.new do |config|
  config.jar_name = Warbler.svn_war_name
  ...
end

Regards,
/Nick