search for: lookupcontext

Displaying 4 results from an estimated 4 matches for "lookupcontext".

2012 Sep 09
2
mattr_accessor inside a class
Rails extends Ruby with mattr_accessor (Module accessor). As Ruby''s attr_accessor generates getter/setter methods for instances, mattr_accessor provide getter/setter methods at the module level. In below example, you see that mattr_accessor declared in the class context of LookupContext. It''s declared in class, not module. However, modules are defined in LookupContext, for example, the module ViewPaths, which makes use of the accessor. So is it safe to say that if a module accessor is declared in class, then it can only be available to modules of that class? class Look...
2012 Sep 11
1
define_method vs module_eval
...D end Here we invoke send() on the module Accessors, passing the :define_method symbol, which represents the define_method private method available from Class class. We create an instance method called default_locale, whose value is the block passed from register_detail class method of ActionView::LookupContext. Note that we later use "include Accessors" within LookupContext class to make that available as an instance method of LookupContext. We then create more instance methods using module_eval, with here-documents to specify our delimiter (METHOD) and the dynamic constants (__FILE__, __LINE__...
2010 Jul 04
2
Rendering a different format in the implementation of a renderer
...rrect behavior, of course, but there are legitimate reasons for wanting to override it. For instance, implementing one renderer in terms of another. In my particular case, I''m trying to get HTML rendered in order to convert it to PDF. As I can see no other clean way, I wish ActionView::LookupContext had a method #with_format(format) { ... } for overriding the format for the duration of the block. Such a renderer could then look like this ActionController.add_renderer(:xyz) do |template, options| lookup_context.with_format(:html) do html = render(template, options) convert_...
2012 Sep 14
1
calling method on base intended to simulate initialize on instances?
...mplate_handler(extension, klass) @@default_template_handlers = klass end def register_template_handler(extension, handler) @@template_handlers[extension.to_sym] = handler @@template_extensions = nil end class Template extend Template::Handlers class LookupContext register_detail(:handlers){ Template::Handlers.extensions } Basically, when ruby loads the Template class (I will assume that it must be loaded prior to Handlers module or LookupContext class), it immediately executes a class method, which is called extend, and passes the module Handlers as th...