Sha256: 7f94b02ea96691e2b680636fb8eb3dbae9878c30ed273f25c82a12d41c727608
Contents?: true
Size: 887 Bytes
Versions: 2
Compression:
Stored size: 887 Bytes
Contents
module ChosenTemplate module Chooser extend ActiveSupport::Concern included do self.template_choices.each do |template_choice| [:previewed, :published].each do |action_type| method_name = :"#{action_type}_#{template_choice.to_s.singularize}" define_method(method_name) do order_scope_name = :"by_template_#{action_type}_at" template_class = template_choice.to_s.classify.constantize foreign_key = "#{self.class.name.underscore}_id" template_scope = if template_class.column_names.include?(foreign_key) self.send(template_choice) else template_class.scoped end template_scope.send(order_scope_name).first end end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
chosen_template-0.1.0 | lib/chosen_template/chooser.rb |
chosen_template-0.0.1 | lib/chosen_template/chooser.rb |