Created
October 24, 2012 19:23
-
-
Save gkop/3948243 to your computer and use it in GitHub Desktop.
Best practice for methods used only during pre-initialization?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This simple solution permanently adds a method on Object that | |
# will never be used outside this file. | |
def compile_asset?(path) | |
# ... lots of complicated logic ... | |
# returns boolean | |
end | |
Foo::Application.configure do | |
... | |
config.assets.precompile = [ method(:compile_asset?).to_proc ] | |
end | |
# One way to keep things clean | |
class <<Foo::Application | |
def compile_asset?(path) | |
# ... lots of complicated logic ... | |
# returns boolean | |
end | |
end | |
Foo::Application.configure do | |
... | |
config.assets.precompile = [ method(:compile_asset?).to_proc ] | |
end | |
class <<Foo::Application | |
remove_method :compile_asset? | |
end | |
# What's a more elegant way? |
@rahearn suppose if you will the precompile method calls two other methods that each encapsulate a bit of file-matching logic.
I'm probably wrap them all in a module that sticks around but then doesn't leak out into Object.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does
compile_asset?
ever use anything other than thepath
parameter? If not, then you could just move it inline: