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.



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

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.



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

def 
  @current_account
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#url_helperObject (readonly)

Returns the value of attribute url_helper.



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

def url_helper
  @url_helper
end

Class Method Details

.presents(name) ⇒ Object



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

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:



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

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:



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

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:



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

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:



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

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:



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

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

#hObject



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

def h
  @view
end

Alias for H#link_to

Returns:

  • (Object)

    H#link_to

See Also:



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

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:



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

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



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

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



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

def r
  @model
end

#safe_present(attribute_name) ⇒ Object



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

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:



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

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

#uObject



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

def u
  @url_helper
end