Class: Locomotive::BasePresenter
- Inherits:
-
Object
- Object
- Locomotive::BasePresenter
- Extended by:
- ActionView::Helpers::SanitizeHelper::ClassMethods
- Includes:
- ActionView::Helpers::NumberHelper, ActionView::Helpers::SanitizeHelper, ActionView::Helpers::TextHelper, Presentable
- Defined in:
- app/presenters/locomotive/base_presenter.rb
Direct Known Subclasses
AccountPresenter, ContentAssetPresenter, ContentEntryPresenter, ContentFieldPresenter, ContentTypePresenter, EditableElementPresenter, MembershipPresenter, PagePresenter, SitePresenter, SnippetPresenter, ThemeAssetPresenter, TranslationPresenter
Instance Attribute Summary collapse
-
#ability ⇒ Object
readonly
utility accessors ##.
-
#depth ⇒ Object
readonly
utility accessors ##.
Class Method Summary collapse
-
.getters_to_hash ⇒ Hash
Return the set of getters with their options.
-
.setters_to_hash(options = {}) ⇒ Hash
Return the set of setters with their options.
Instance Method Summary collapse
-
#ability? ⇒ Boolean
Check if there is an ability object used for permissions.
-
#after_initialize ⇒ Object
Set the ability object to check if we can or not get a property.
-
#id ⇒ String
Get the id of the source only if it has been persisted or if it’s an embedded document.
-
#site ⇒ Object
Shortcut to the site taken from the source.
Methods included from Presentable
#as_json, #attributes=, #getters, #initialize, #property_options, #setters
Instance Attribute Details
#ability ⇒ Object (readonly)
utility accessors ##
15 16 17 |
# File 'app/presenters/locomotive/base_presenter.rb', line 15 def ability @ability end |
#depth ⇒ Object (readonly)
utility accessors ##
15 16 17 |
# File 'app/presenters/locomotive/base_presenter.rb', line 15 def depth @depth end |
Class Method Details
.getters_to_hash ⇒ Hash
Return the set of getters with their options.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/presenters/locomotive/base_presenter.rb', line 82 def self.getters_to_hash {}.tap do |hash| self.getters.each do |name| next if %w(created_at updated_at).include?(name) = self.[name] || {} hash[name] = [:type] || 'String' end %w(created_at updated_at).each do |name| = self.[name] || {} hash[name] = [:type] || 'String' end end end |
.setters_to_hash(options = {}) ⇒ Hash
Return the set of setters with their options.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/presenters/locomotive/base_presenter.rb', line 60 def self.setters_to_hash( = {}) = { without_ids: true }.merge() {}.tap do |hash| self.setters.each do |name| next if %w(id _id).include?(name.to_s) && [:without_ids] = self.[name] || {} hash[name] = { type: [:type] || 'String', required: [:required].nil? ? true : [:required], alias_of: self.alias_of(name) } end end end |
Instance Method Details
#ability? ⇒ Boolean
Check if there is an ability object used for permissions.
42 43 44 |
# File 'app/presenters/locomotive/base_presenter.rb', line 42 def ability? self.ability.present? end |
#after_initialize ⇒ Object
Set the ability object to check if we can or not get a property.
20 21 22 23 24 25 26 27 |
# File 'app/presenters/locomotive/base_presenter.rb', line 20 def after_initialize @depth = self.[:depth] || 0 @ability = self.[:ability] if @options[:current_account] && @options[:current_site] @ability = Locomotive::Ability.new @options[:current_account], @options[:current_site] end end |
#id ⇒ String
Get the id of the source only if it has been persisted or if it’s an embedded document.
11 |
# File 'app/presenters/locomotive/base_presenter.rb', line 11 property :id, alias: :_id |
#site ⇒ Object
Shortcut to the site taken from the source.
50 51 52 |
# File 'app/presenters/locomotive/base_presenter.rb', line 50 def site self.source.try(:site) end |