Class: BasePresenter
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- BasePresenter
- 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
Direct Known Subclasses
CatalogItemPresenter, CatalogPresenter, Crm::BasePresenter, Crm::Report::ActivityPerformanceResultPresenter, Crm::Report::ChannelRevenueResultsPresenter, Crm::Report::CustomerPerformanceResultsPresenter, DeliveryPresenter, Edi::MiraklSeller::BaseMiraklPresenter, ExportedCatalogItemPacketPresenter, FaqPresenter, Feed::ItemPresenter, OrderPresenter, PostPresenter, Search::ActivityPresenter, Search::BudgetPresenter, Search::CertificationPresenter, Search::ContactPresenter, Search::CouponPresenter, Search::CreditApplicationPresenter, Search::CreditMemoPresenter, Search::CustomerPresenter, Search::DeliveryPresenter, Search::EmployeeReviewPresenter, Search::ExchangeRatePresenter, Search::InvoicePresenter, Search::InvoiceSummaryPresenter, Search::ItAssetPresenter, Search::ItemLedgerEntryPresenter, Search::ItemPresenter, Search::LedgerEntryPresenter, Search::LocatorRecordPresenter, Search::OpportunityPresenter, Search::OpportunitySummaryPresenter, Search::OrderPresenter, Search::OutgoingPaymentPresenter, Search::ProductCatalogPresenter, Search::PurchaseOrderPresenter, Search::QuotePresenter, Search::ReceiptPresenter, Search::RmaPresenter, Search::SalesCommissionPresenter, Search::ServiceJobPresenter, Search::SupplierItemPresenter, Search::SupportCasePresenter, Search::VoucherPresenter, SearchPresenter, ShowcasePresenter, VideoBasePresenter, Www::BasePresenter
Instance Attribute Summary collapse
-
#current_account ⇒ Object
readonly
Returns the value of attribute current_account.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#url_helper ⇒ Object
readonly
Returns the value of attribute url_helper.
Delegated Instance Attributes collapse
-
#can? ⇒ Object
Alias for H#can?.
-
#capture ⇒ Object
Alias for H#capture.
-
#concat ⇒ Object
Alias for H#concat.
-
#content_tag ⇒ Object
Alias for H#content_tag.
-
#fa_icon ⇒ Object
Alias for H#fa_icon.
-
#link_to ⇒ Object
Alias for H#link_to.
-
#number_to_currency ⇒ Object
Alias for H#number_to_currency.
-
#simple_format ⇒ Object
Alias for H#simple_format.
Class Method Summary collapse
Instance Method Summary collapse
- #h ⇒ Object
-
#initialize(model, view = nil, options = nil) ⇒ BasePresenter
constructor
A new instance of BasePresenter.
-
#present(attribute_name) ⇒ Object
Helper method which will first see if model responds to this method otherwise will simply return nil.
- #r ⇒ Object
- #safe_present(attribute_name) ⇒ Object
- #u ⇒ Object
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, = nil) ||= {} @model = model @view = view @view ||= ApplicationController.helpers @url_helper ||= @view || Rails.application.routes.url_helpers @options = @current_account = [:current_account] super(@model) end |
Instance Attribute Details
#current_account ⇒ Object (readonly)
Returns the value of attribute current_account.
4 5 6 |
# File 'app/presenters/base_presenter.rb', line 4 def current_account @current_account end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'app/presenters/base_presenter.rb', line 4 def @options end |
#url_helper ⇒ Object (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?
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 |
#capture ⇒ Object
Alias for H#capture
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 |
#concat ⇒ Object
Alias for H#concat
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_tag ⇒ Object
Alias for H#content_tag
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_icon ⇒ Object
Alias for H#fa_icon
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 |
#h ⇒ Object
29 30 31 |
# File 'app/presenters/base_presenter.rb', line 29 def h @view end |
#link_to ⇒ Object
Alias for H#link_to
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_currency ⇒ Object
Alias for H#number_to_currency
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 |
#r ⇒ Object
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_format ⇒ Object
Alias for H#simple_format
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 |
#u ⇒ Object
33 34 35 |
# File 'app/presenters/base_presenter.rb', line 33 def u @url_helper end |