module Chic::Presents
Public Class Methods
included(parent)
click to toggle source
# File lib/chic/presents.rb, line 6 def included(parent) parent.extend ClassMethods end
Private Instance Methods
_presents_options_presenter_class(options)
click to toggle source
# File lib/chic/presents.rb, line 111 def _presents_options_presenter_class(options) options.is_a?(Class) ? options : options[:with] end
_presents_options_value(attribute, options)
click to toggle source
# File lib/chic/presents.rb, line 115 def _presents_options_value(attribute, options) return object&.public_send(attribute) unless options.is_a?(Hash) && options.key?(:value) case options[:value] when Symbol send(options[:value]) when Proc instance_exec(&options[:value]) else raise PresentsOptionsNotValid, "Options value for #{attribute} must be a symbol or a Proc" end end
nil_presenter(object)
click to toggle source
# File lib/chic/presents.rb, line 107 def nil_presenter(object) Presenters::Nil.new(object, context) end
present(object, with: nil)
click to toggle source
# File lib/chic/presents.rb, line 91 def present(object, with: nil) if object.is_a?(Enumerable) object.map { |o| present(o, with) } elsif with.present? with.new(object, context) elsif object.nil? nil_presenter(object) else Chic::Presentable.presenter_for(object)&.new(object, context) || nil_presenter(object) end end
present_with(object, with)
click to toggle source
# File lib/chic/presents.rb, line 103 def present_with(object, with) with.is_a?(Class) ? with.new(object, context) : nil_presenter(object) end