Sha256: 310cf041215c5ff0776ef09c2a78f96e113ced8a4584f2432ecd6d362a4fd906
Contents?: true
Size: 614 Bytes
Versions: 2
Compression:
Stored size: 614 Bytes
Contents
# frozen_string_literal: true module Decoro module Helpers def decorate(model, decorator_class = nil) array = nil klass = decorator_class if model.is_a? Array array = model model = model.first klass ||= "#{model.class}Decorator".constantize elsif model.is_a? ActiveRecord::Relation klass ||= "#{model.name.pluralize}Decorator".constantize else klass ||= "#{model.class}Decorator".constantize end decorator = array ? array.map { |m| klass.new(m) } : klass.new(model) yield(decorator) if block_given? end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
decoro-0.1.3 | lib/decoro/helpers.rb |
decoro-0.1.2 | lib/decoro/helpers.rb |