Sha256: d9c29874b3ddc48c6c953f2542a0e8c36c2706197f5e95f18d366079d166dae0
Contents?: true
Size: 1.66 KB
Versions: 13
Compression:
Stored size: 1.66 KB
Contents
module Toy module EmbeddedLists extend ActiveSupport::Concern module ClassMethods def embedded_lists @embedded_lists ||= {} end def embedded_list?(key) embedded_lists.keys.include?(key.to_sym) end def parent_reference_module @parent_reference_module ||= begin mod = Module.new include mod mod end end def parent_references @parent_references ||= [] end def parent_reference?(key) parent_references.include?(key.to_sym) end def parent_reference(*names) names.flatten.each do |name| parent_references << name parent_reference_module.module_eval <<-CODE def #{name} parent_reference end def #{name}? parent_reference.present? end CODE end end # @examples # list :moves # assumes Move # list :moves, :dependent => true # assumes Move # list :recent_moves, Move # uses Move # list :recent_moves, Move, :dependent => true # uses Move # # embedded_list :moves do # def recent # target.select { |t| t.recent? } # end # end # # module RecentExtension # def recent # target.select { |t| t.recent? } # end # end # embedded_list :moves, :extensions => [RecentExtension] def embedded_list(name, *args, &block) EmbeddedList.new(self, name, *args, &block) end end end end
Version data entries
13 entries across 13 versions & 1 rubygems