Class: ActiveHelper::Base

Inherits:
Object
  • Object
show all
Includes:
GenericMethods
Defined in:
lib/active_helper/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from GenericMethods

#use_for

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

#parentObject (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