Class: ActiveHelper::Base
- Inherits:
-
Object
- Object
- ActiveHelper::Base
- Includes:
- GenericMethods
- Defined in:
- lib/active_helper/base.rb
Instance Attribute Summary collapse
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Class Method Summary collapse
-
.needs(*methods) ⇒ Object
Define a dependency to another ActiveHelper.
-
.provides(*methods) ⇒ Object
Add public methods to the helper’s interface.
-
.uses(*classes) ⇒ Object
Define a dependency to methods in target.
Instance Method Summary collapse
- #import(*classes) ⇒ Object (also: #use)
-
#initialize(parent = nil) ⇒ Base
constructor
A new instance of Base.
Methods included from GenericMethods
Constructor Details
#initialize(parent = nil) ⇒ Base
Returns a new instance of Base.
56 57 58 59 60 61 |
# File 'lib/active_helper/base.rb', line 56 def initialize(parent=nil) @parent = parent setup_delegator_strategy! # in GenericMethods. delegate_parent_readers! use_class_helpers! end |
Instance Attribute Details
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
54 55 56 |
# File 'lib/active_helper/base.rb', line 54 def parent @parent end |
Class Method Details
.needs(*methods) ⇒ Object
Define a dependency to another ActiveHelper. All provided methods by the needed helper will be imported into the helper that called needs.
Example:
class UrlHelper < ActiveHelper::Base
needs TagHelper
will import #tag into UrlHelper.
31 32 33 |
# File 'lib/active_helper/base.rb', line 31 def needs(*methods) parent_readers.push(*methods).uniq! end |
.provides(*methods) ⇒ Object
Add public methods to the helper’s interface. Only methods listed here will be imported into the target.
Example:
class UrlHelper < ActiveHelper::Base
provides :url_for, :link_to
19 20 21 |
# File 'lib/active_helper/base.rb', line 19 def provides(*methods) helper_methods.push(*methods) end |
.uses(*classes) ⇒ Object
Define a dependency to methods in target. Calls to that methods will be delegated simply back to target.
Note: This can also be used to call a helper method from a non-ActiveHelper, which was preliminary included in target.
Example:
class UrlHelper < ActiveHelper::Base
uses controller
will deletegate calls to #controller to target (i.e. the view instance that #use’s UrlHelper).
47 48 49 |
# File 'lib/active_helper/base.rb', line 47 def uses(*classes) class_helpers.push(*classes).uniq! end |
Instance Method Details
#import(*classes) ⇒ Object Also known as: use
63 64 65 |
# File 'lib/active_helper/base.rb', line 63 def import(*classes) use_for(classes, parent) # in GenericMethods. end |