Sha256: e4f4a98db810cf79f037b1599e4a602b7f2c08e8fd38048a6d8f8372eb79afa2
Contents?: true
Size: 1.15 KB
Versions: 118
Compression:
Stored size: 1.15 KB
Contents
module Scrivito class RestrictionSet Restriction = Struct.new(:attribute, :callable) do def call(obj) if skip?(obj) false else value = obj[attribute] callable.call(value) end end private def skip?(obj) !obj.has_attribute?(attribute) || obj.type_of_attribute(attribute) == 'widgetlist' end end def add(options, &block) options = options.with_indifferent_access attribute = options.fetch(:using) do raise ScrivitoError, 'No "using" option given when adding a publish restriction' end unless block_given? raise ScrivitoError, 'No block provided when adding a publish restriction' end restrictions << Restriction.new(attribute, block) end def restriction_messages_for(obj) restriction_messages = restrictions.inject([]) do |messages, restriction| message = restriction.call(obj) if message messages << message.to_s end messages end restriction_messages.uniq end private def restrictions @restrictions ||= [] end end end
Version data entries
118 entries across 118 versions & 1 rubygems