<commit_before>module Ragios
  class Controller
    #see contracts: https://github.com/egonSchiele/contracts.ruby
    include Contracts
    #types
    Monitor = Hash
    Monitor_id = String

    def self.scheduler
      @scheduler ||= Ragios::Scheduler.new(self)
    end

    def self.model
      @model ||= Ragios::Database::Model.new(Ragios::CouchdbAdmin.get_database)
    end

    Contract Monitor_id => Bool
    def self.stop(monitor_id)
      try_monitor(monitor_id) do
        scheduler.unschedule(monitor_id)
        !!model.update(monitor_id, status_: "stopped")
      end
    end

    Contract Monitor_id => Bool
    def self.delete(monitor_id)
      try_monitor(monitor_id) do
        monitor = model.find(monitor_id)
        scheduler.unschedule(monitor_id) if is_active?(monitor)
        !!model.delete(monitor_id)
      end
    end

    Contract Monitor_id, Hash => Bool
    def self.update(monitor_id, options)
      try_monitor(monitor_id) do
        message = "Cannot edit system settings"
        unless options.keys.to_set.disjoint? [:type, :status_, :created_at_, :creation_timestamp_].to_set
          raise Ragios::CannotEditSystemSettings.new(error: message), message
        end
        model.update(monitor_id, options)
        monitor = model.find(monitor_id)
        if is_active?(monitor)
          scheduler.unschedule(monitor_id)
          updated_generic_monitor = update_previous_state(monitor)<commit_msg>use any? instead of disjoint? for Ruby 1.9.3 support<commit_after>module Ragios
  class Controller
    #see contracts: https://github.com/egonSchiele/contracts.ruby
    include Contracts
    #types
    Monitor = Hash
    Monitor_id = String

    def self.scheduler
      @scheduler ||= Ragios::Scheduler.new(self)
    end

    def self.model
      @model ||= Ragios::Database::Model.new(Ragios::CouchdbAdmin.get_database)
    end

    Contract Monitor_id => Bool
    def self.stop(monitor_id)
      try_monitor(monitor_id) do
        scheduler.unschedule(monitor_id)
        !!model.update(monitor_id, status_: "stopped")
      end
    end

    Contract Monitor_id => Bool
    def self.delete(monitor_id)
      try_monitor(monitor_id) do
        monitor = model.find(monitor_id)
        scheduler.unschedule(monitor_id) if is_active?(monitor)
        !!model.delete(monitor_id)
      end
    end

    Contract Monitor_id, Hash => Bool
    def self.update(monitor_id, options)
      try_monitor(monitor_id) do
        message = "Cannot edit system settings"
        if options.keys.any? { |key| [:type, :status_, :created_at_, :creation_timestamp_].include?(key) }
          raise Ragios::CannotEditSystemSettings.new(error: message), message
        end
        model.update(monitor_id, options)
        monitor = model.find(monitor_id)
        if is_active?(monitor)
          scheduler.unschedule(monitor_id)
          updated_generic_monitor = update_previous_state(monitor)
{'fraction_non_alphanumeric': 0.09334248455730954, 'fraction_numerical': 0.001029512697323267, 'mean_word_length': 2.998628257887517, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6578717', 'n_tokens_mistral': 900, 'n_tokens_neox': 871, 'n_words': 182}