Module: Poniard::Controller::ClassMethods
- Defined in:
- lib/poniard/controller.rb
Overview
Class methods that are automatically added when ‘Controller` is included.
Instance Method Summary collapse
-
#provided_by(klass = nil, opts = {}) ⇒ Object
For every non-inherited public instance method on the given class, generates a method of the same name that calls it via the injector.
-
#sources ⇒ Object
An array of sources to be used for all injected methods on the host class.
Instance Method Details
#provided_by(klass = nil, opts = {}) ⇒ Object
For every non-inherited public instance method on the given class, generates a method of the same name that calls it via the injector.
If a ‘layout` method is present on the class, it is given special treatment and set up so that it will be called using the Rails `layout` DSL method.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/poniard/controller.rb', line 28 def provided_by(klass = nil, opts = {}) if klass methods = klass.public_instance_methods(false) layout_method = methods.delete(:layout) methods.each do |m| class_eval <<-RUBY def #{m} inject :#{m} end RUBY end if layout_method layout :layout_for_controller class_eval <<-RUBY def layout_for_controller inject :layout end RUBY end @provided_by = klass @sources = opts.fetch(:sources, []).reverse else @provided_by end end |
#sources ⇒ Object
An array of sources to be used for all injected methods on the host class. This is typically specified using the ‘sources` option to `provided_by`, however you can override it for more complicated dynamic behaviour.
63 64 65 |
# File 'lib/poniard/controller.rb', line 63 def sources @sources end |