Module: HasHelpers::ActiveRecord::Base
- Defined in:
- lib/has_helpers/active_record/base.rb
Class Method Summary collapse
-
.set_renderable_proc(to_renderable_proc = nil, &block) ⇒ Object
Set a proc which will process the current object when #to_renderable is invoked.
- .to_renderable_proc ⇒ Object
Instance Method Summary collapse
Class Method Details
.set_renderable_proc(to_renderable_proc = nil, &block) ⇒ Object
Set a proc which will process the current object when #to_renderable is invoked. If the proc does not handle the object (by returning nil) then the default logic will take effect.
Examples
HasHelpers::ActiveRecord::Base.set_renderable_proc do |object| # logic here end
HasHelpers::ActiveRecord::Base.set_renderable_proc = proc { |object| #logic here }
40 41 42 |
# File 'lib/has_helpers/active_record/base.rb', line 40 def self.set_renderable_proc(to_renderable_proc = nil, &block) @to_renderable_proc = to_renderable_proc || block end |
.to_renderable_proc ⇒ Object
44 45 46 |
# File 'lib/has_helpers/active_record/base.rb', line 44 def self.to_renderable_proc @to_renderable_proc end |
Instance Method Details
#to_renderable(*args) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/has_helpers/active_record/base.rb', line 20 def to_renderable(*args) if ::HasHelpers::ActiveRecord::Base.to_renderable_proc proc_result = ::HasHelpers::ActiveRecord::Base.to_renderable_proc.call(self) end proc_result || to_service(*args) rescue ServiceError name.to_s.to_text_node end |
#to_service(url: nil, **options) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/has_helpers/active_record/base.rb', line 11 def to_service(url: nil, **) begin url ||= ::HasHelpers::BasePresenter::Routing.routes.polymorphic_path(self) rescue raise ServiceError, $!. end name.to_s.to_service(url, **) end |