Sha256: c10687f7793a632d1b7cbd849cf5ebc38d72b33cda430250acfb2be0b1b008a1
Contents?: true
Size: 1.3 KB
Versions: 2
Compression:
Stored size: 1.3 KB
Contents
require 'active_support/concern' module TheModerator module ModerationModel extend ActiveSupport::Concern included do belongs_to :moderatable, polymorphic: true serialize :data serialize :data_display end module ClassMethods end def accept self.class.transaction do destroy moderatable.update(data) end end def accept! accept || raise(TheModerator::ModerationNotAccepted) end def discard destroy end def preview preview = moderatable.clone preview.attributes = data preview.freeze end def parsed_data data end def parsed_data_display data_display end def include?(attribute) include_attribute?(attribute, data[:attributes]) end def moderated_fields_for(assoc) (data[:attributes][assoc].try(:keys) || []) - [:id] end private def include_attribute?(attribute, attr_data) return false if attr_data.nil? if attribute.is_a?(Hash) include_assoc?(attribute, attr_data) else attr_data.keys.include?(attribute) end end def include_assoc?(attribute, assoc_data) include_attribute?(attribute.first.last, assoc_data[attribute.first.first]) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
the_moderator-0.1.5 | lib/the_moderator/moderation_model.rb |
the_moderator-0.1.4 | lib/the_moderator/moderation_model.rb |