Class: MetaPresenter::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/meta_presenter/builder.rb

Overview

Builds a presenter class for a controller and method

Defined Under Namespace

Classes: FileExistsButPresenterNotDefinedError, InvalidControllerError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller, action_name) ⇒ Builder

Creates a new Builder

Parameters:

  • controller (ActionController::Base, ActionMailer::Base)

    Controller that this presenter will delegate methods to

  • action_name (String)

    Name of the controller’s action to hook the presenter up to



16
17
18
19
# File 'lib/meta_presenter/builder.rb', line 16

def initialize(controller, action_name)
  @controller = controller
  @action_name = action_name
end

Instance Attribute Details

#action_nameString (readonly)

Returns Name of the controller’s action to hook the presenter up to.

Returns:

  • (String)

    Name of the controller’s action to hook the presenter up to



10
11
12
# File 'lib/meta_presenter/builder.rb', line 10

def action_name
  @action_name
end

#controllerActionController::Base, ActionMailer::Base (readonly)

Returns Controller that this presenter will delegate methods to.

Returns:

  • (ActionController::Base, ActionMailer::Base)

    Controller that this presenter will delegate methods to



7
8
9
# File 'lib/meta_presenter/builder.rb', line 7

def controller
  @controller
end

Instance Method Details

#presenter_base_dirObject



53
54
55
# File 'lib/meta_presenter/builder.rb', line 53

def presenter_base_dir
  File.join(Rails.root, 'app', 'presenters')
end

#presenter_classClass

Returns Class constant for the built MetaPresenter::Base presenter.

Returns:

  • (Class)

    Class constant for the built MetaPresenter::Base presenter



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/meta_presenter/builder.rb', line 40

def presenter_class
  # Try to find the presenter class (Not guaranteed,
  # for example if the presenter class wasn't defined
  # or if the file wasn't found)
  klass = nil
  ancestors.each do |klass_name|
    klass = presenter_class_for(klass_name)
    break unless klass.nil?
  end

  klass
end