Class: BasePresenter

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
app/presenters/base_presenter.rb

Overview

Base presenter class with the basic pattern implementation
initialize with a model instance the rails view context

Instance Attribute Summary collapse

Delegated Instance Attributes collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, view = nil, options = nil) ⇒ BasePresenter

Returns a new instance of BasePresenter.



9
10
11
12
13
14
15
16
17
18
# File 'app/presenters/base_presenter.rb', line 9

def initialize(model, view = nil, options = nil)
  options ||= {}
  @model = model
  @view = view
  @view ||= ApplicationController.helpers
  @url_helper ||= @view || Rails.application.routes.url_helpers
  @options = options
  @current_account = options[:current_account]
  super(@model)
end

Instance Attribute Details

#current_accountObject (readonly)

Returns the value of attribute current_account.



5
6
7
# File 'app/presenters/base_presenter.rb', line 5

def 
  @current_account
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'app/presenters/base_presenter.rb', line 5

def options
  @options
end

#url_helperObject (readonly)

Returns the value of attribute url_helper.



5
6
7
# File 'app/presenters/base_presenter.rb', line 5

def url_helper
  @url_helper
end

Class Method Details

.presents(name) ⇒ Object



20
21
22
23
24
# File 'app/presenters/base_presenter.rb', line 20

def self.presents(name)
  define_method(name) do
    @model
  end
end

Instance Method Details

#can?Object

Alias for H#can?

Returns:

  • (Object)

    H#can?

See Also:



7
# File 'app/presenters/base_presenter.rb', line 7

delegate :can?, :fa_icon, :link_to, :content_tag, :concat, :capture, :number_to_currency, :simple_format, to: :h

#captureObject

Alias for H#capture

Returns:

  • (Object)

    H#capture

See Also:



7
# File 'app/presenters/base_presenter.rb', line 7

delegate :can?, :fa_icon, :link_to, :content_tag, :concat, :capture, :number_to_currency, :simple_format, to: :h

#concatObject

Alias for H#concat

Returns:

  • (Object)

    H#concat

See Also:



7
# File 'app/presenters/base_presenter.rb', line 7

delegate :can?, :fa_icon, :link_to, :content_tag, :concat, :capture, :number_to_currency, :simple_format, to: :h

#content_tagObject

Alias for H#content_tag

Returns:

  • (Object)

    H#content_tag

See Also:



7
# File 'app/presenters/base_presenter.rb', line 7

delegate :can?, :fa_icon, :link_to, :content_tag, :concat, :capture, :number_to_currency, :simple_format, to: :h

#fa_iconObject

Alias for H#fa_icon

Returns:

  • (Object)

    H#fa_icon

See Also:



7
# File 'app/presenters/base_presenter.rb', line 7

delegate :can?, :fa_icon, :link_to, :content_tag, :concat, :capture, :number_to_currency, :simple_format, to: :h

#hObject



30
31
32
# File 'app/presenters/base_presenter.rb', line 30

def h
  @view
end

Alias for H#link_to

Returns:

  • (Object)

    H#link_to

See Also:



7
# File 'app/presenters/base_presenter.rb', line 7

delegate :can?, :fa_icon, :link_to, :content_tag, :concat, :capture, :number_to_currency, :simple_format, to: :h

#number_to_currencyObject

Alias for H#number_to_currency

Returns:

  • (Object)

    H#number_to_currency

See Also:



7
# File 'app/presenters/base_presenter.rb', line 7

delegate :can?, :fa_icon, :link_to, :content_tag, :concat, :capture, :number_to_currency, :simple_format, to: :h

#present(attribute_name) ⇒ Object

Helper method which will first see if model responds to this method
otherwise will simply return nil



40
41
42
43
44
45
# File 'app/presenters/base_presenter.rb', line 40

def present(attribute_name)
  attribute_key = attribute_name.to_sym
  return unless respond_to?(attribute_key) || r.respond_to?(attribute_key)

  send(attribute_key)
end

#rObject



26
27
28
# File 'app/presenters/base_presenter.rb', line 26

def r
  @model
end

#safe_present(attribute_name) ⇒ Object



47
48
49
50
51
# File 'app/presenters/base_presenter.rb', line 47

def safe_present(attribute_name)
  present(attribute_name)
rescue StandardError
  nil
end

#simple_formatObject

Alias for H#simple_format

Returns:

  • (Object)

    H#simple_format

See Also:



7
# File 'app/presenters/base_presenter.rb', line 7

delegate :can?, :fa_icon, :link_to, :content_tag, :concat, :capture, :number_to_currency, :simple_format, to: :h

#uObject



34
35
36
# File 'app/presenters/base_presenter.rb', line 34

def u
  @url_helper
end