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

Variable declaration order issue #85

Closed
zimbatm opened this issue Oct 26, 2011 · 4 comments
Closed

Variable declaration order issue #85

zimbatm opened this issue Oct 26, 2011 · 4 comments

Comments

@zimbatm
Copy link
Contributor

zimbatm commented Oct 26, 2011

Yet another follow-up of issue #82.

Since there is no rake mechanism to declare constants, ruby constants are often uses to describe things like a build path or defaults. Because those are not declarative, "rakelib/*.rake" file inclusion order then rapidly start to matter when you start to have cross-dependencies.

I propose to introduce a "var" task that defines the value of it's name after the declaration phase.

@kagminjeong
Copy link

The workaround/solution is to use blocks for definitions, at which point definitions are evaluated when they are used.

How would you propose improving on the current set :foo, { definition } syntax?

@zimbatm
Copy link
Contributor Author

zimbatm commented Oct 31, 2011

I'm not aware of rake supporting the set method but it's something like that that I had in mind.

@kagminjeong
Copy link

Sorry, that clearly was capistrano and not rake syntax. My mistake.

@sunaku
Copy link

sunaku commented Oct 31, 2011

Why not use an OpenStruct object to house all of your "constants" and read/write/override them as you wish?

# some_lib.rb
require 'ostruct'
MY_QUOTE_CONSTANTS = OpenStruct.new
task :foobar do
  puts "now do something with #{MY_QUOTE_CONSTANTS.something}"
end

# Rakefile
require './some_lib'
MY_QUOTE_CONSTANTS.something = "that foobar thing!"
task :catdog do
  MY_QUOTE_CONSTANTS.something = "that catdog thing!"
  Rake::Task[:foobar].invoke
end

And now to run the above code:

$ rake foobar
(in /tmp)
now do something with that foobar thing!
$ rake catdog
(in /tmp)
now do something with that catdog thing!

KISS, and more importantly, keep Ruby/Rake simple please!

@zimbatm zimbatm closed this as completed Nov 3, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants