Hi all,
I''m proposing a small extension to the application configuration,
whereby it will use and store the block in the method missing that
handles the configuration keys.
This pattern is already essentially used in config.generators which
has been made a special case for Rails, and really it shouldn''t be.
The block passed could be stored as a normal config value would be,
with the DSL resolved later during load_generators.
My use-case for this is the following:
class MyApp < Rails::Application
config.my_engine do |engine|
engine.page_types.some_method_missing_implementation do |page|
page.field ''title''
...
end
end
end
The Application is potentially a great way for plugin and gem authors
to expose really flexible and succinct configuration DSLs to
consumers. This simple extension would prevent lots of
MyEngine.configuration { stuff.and_more.stuff } everywhere, and
constant wheel re-inventing.
The patch is simple (not written tests yet, wanted some input first):
diff --git a/railties/lib/rails/railtie/configuration.rb b/railties/
lib/rails/railtie/configuration.rb
index 828ccec..bc38313 100644
--- a/railties/lib/rails/railtie/configuration.rb
+++ b/railties/lib/rails/railtie/configuration.rb
@@ -77,7 +77,7 @@ module Rails
def method_missing(name, *args, &blk)
if name.to_s =~ config_key_regexp
- return $2 == ''='' ? options[$1] = args.first :
options[$1]
+ return $2 == ''='' ? options[$1] = (block_given? ?
blk :
args.first) : options[$1]
end
super
end
Does anyone have any thoughts or opinions on this?
Thanks,
Paul Bowsher
Technical Director
Rawnet
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Core" group.
To post to this group, send email to rubyonrails-core@googlegroups.com.
To unsubscribe from this group, send email to
rubyonrails-core+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en.