states.rb
上传用户:netsea168
上传日期:2022-07-22
资源大小:4652k
文件大小:4k
源码类别:

Ajax

开发平台:

Others

  1. module Feedback::States
  2.   class Base < Stateful::State
  3.     # Give the default 'model' a more meaningful name
  4.     alias_method :content, :model
  5.     def before_save;           true; end
  6.     def after_save;            true; end
  7.     def after_initialize;      true; end
  8.     def post_trigger;          true; end
  9.     def send_notifications;    true; end
  10.     def report_classification; true; end
  11.     def withdraw;                    end
  12.     def confirm_classification;      end
  13.     def mark_as_spam
  14.       content.state = :just_marked_as_spam
  15.     end
  16.     def mark_as_ham
  17.       content.state = :just_marked_as_ham
  18.     end
  19.   end
  20.   class Unclassified < Base
  21.     def after_initialize
  22.       returning(true) { enter_hook }
  23.     end
  24.     def enter_hook
  25.       super
  26.       content[:published] = false
  27.       content[:status_confirmed] = false
  28.     end
  29.     def published?
  30.       classify_content
  31.       content.published?
  32.     end
  33.     def just_published?
  34.       classify_content
  35.       content.just_published?
  36.     end
  37.     def spam?
  38.       classify_content;
  39.       content.spam?
  40.     end
  41.     def classify_content
  42.       content.state = case content.classify
  43.                       when :ham;  :just_presumed_ham
  44.                       when :spam; :presumed_spam
  45.                       else        :presumed_spam
  46.                       end
  47.     end
  48.     def before_save
  49.       classify_content
  50.     end
  51.     def to_s
  52.       _("Unclassified")
  53.     end
  54.   end
  55.   class JustPresumedHam < Base
  56.     def enter_hook
  57.       super
  58.       content.just_changed_published_status = true
  59.       content.state = :presumed_ham unless content.user_id
  60.       content.state = :just_marked_as_ham if content.user_id
  61.     end
  62.     def to_s
  63.       _("Just Presumed Ham")
  64.     end
  65.   end
  66.   class PresumedHam < Base
  67.     def enter_hook
  68.       super
  69.       content[:published] = true
  70.       content[:status_confirmed] = false
  71.     end
  72.     def published?; true; end
  73.     def just_published?
  74.       content.just_changed_published_status?
  75.     end
  76.     def withdraw
  77.       mark_as_spam
  78.     end
  79.     def confirm_classification
  80.       mark_as_ham
  81.     end
  82.     def mark_as_ham
  83.       content.state = :ham
  84.     end
  85.     def to_s
  86.       _("Ham?")
  87.     end
  88.     def send_notifications
  89.       content.really_send_notifications if content.just_changed_published_status
  90.       return true
  91.     end
  92.   end
  93.   class JustMarkedAsHam < Base
  94.     def enter_hook
  95.       super
  96.       content.just_changed_published_status = true
  97.       content.state = :ham
  98.     end
  99.     def to_s
  100.       _("Just Marked As Ham")
  101.     end
  102.   end
  103.   class Ham < Base
  104.     def enter_hook
  105.       super
  106.       content[:published] = true
  107.       content[:status_confirmed] = true
  108.     end
  109.     def published?;        true; end
  110.     def status_confirmed?; true; end
  111.     def mark_as_ham;             end
  112.     def just_published?
  113.       content.just_changed_published_status?
  114.     end
  115.     def withdraw
  116.       mark_as_spam
  117.     end
  118.     def report_classification
  119.       content.report_as_ham if content.just_changed_published_status?
  120.       true
  121.     end
  122.     def send_notifications
  123.       content.really_send_notifications if content.just_changed_published_status?
  124.       true
  125.     end
  126.     def to_s
  127.       _("Ham")
  128.     end
  129.   end
  130.   class PresumedSpam < Base
  131.     def enter_hook
  132.       super
  133.       content[:published] = false
  134.       content[:status_confirmed?] = false
  135.     end
  136.     def spam?; true; end
  137.     def mark_as_ham
  138.       content.state = :just_marked_as_ham
  139.     end
  140.     def mark_as_spam
  141.       content.state = :spam
  142.     end
  143.     def withdraw
  144.       mark_as_spam
  145.     end
  146.     def confirm_classification
  147.       mark_as_spam
  148.     end
  149.     def to_s
  150.       _("Spam?")
  151.     end
  152.   end
  153.   class JustMarkedAsSpam < Base
  154.     def enter_hook
  155.       super
  156.       content.just_changed_published_status = true
  157.       content.state = :spam
  158.     end
  159.     def to_s
  160.       _("Just Marked As Spam")
  161.     end
  162.   end
  163.   class Spam < Base
  164.     def enter_hook
  165.       super
  166.       content[:published] = false
  167.       content[:status_confirmed] = true
  168.     end
  169.     def spam?;             true; end
  170.     def status_confirmed?; true; end
  171.     def mark_as_spam;            end
  172.     def report_classification
  173.       content.report_as_spam if content.just_changed_published_status?
  174.       true
  175.     end
  176.     def to_s
  177.       _("Spam")
  178.     end
  179.   end
  180. end