<commit_before>module Effective
  class Region < ActiveRecord::Base
    self.table_name = EffectiveRegions.regions_table_name.to_s

    belongs_to :regionable, :polymorphic => true

    structure do
      title             :string, :validates => [:presence]
      content           :text
      snippets          :text

      timestamps
    end

    serialize :snippets, HashWithIndifferentAccess

    scope :global, -> { where("#{EffectiveRegions.regions_table_name}.regionable_type IS NULL").where("#{EffectiveRegions.regions_table_name}.regionable_id IS NULL") }

    def snippets
      self[:snippets] || HashWithIndifferentAccess.new()
    end

    # Hash of the Snippets objectified
    #
    # Returns a Hash of {'snippet_1' => CurrentUserInfo.new(snippets[:key]['options'])}
    def snippet_objects
      @snippet_objects ||= snippets.map do |key, snippet|  # Key here is 'snippet_1'
        if snippet['class_name']
          klass = "Effective::Snippets::#{snippet['class_name'].classify}".safe_constantize
          klass.new(snippet.merge!(:region => self, :id => key)) if klass
        end
      end.compact
    end

    def global?
      regionable_id == nil && regionable_type == nil
    end

  end
end




<commit_msg>Touch the regional object on save<commit_after>module Effective
  class Region < ActiveRecord::Base
    self.table_name = EffectiveRegions.regions_table_name.to_s

    belongs_to :regionable, :polymorphic => true, :touch => true

    structure do
      title             :string, :validates => [:presence]
      content           :text
      snippets          :text

      timestamps
    end

    serialize :snippets, HashWithIndifferentAccess

    scope :global, -> { where("#{EffectiveRegions.regions_table_name}.regionable_type IS NULL").where("#{EffectiveRegions.regions_table_name}.regionable_id IS NULL") }

    def snippets
      self[:snippets] || HashWithIndifferentAccess.new()
    end

    # Hash of the Snippets objectified
    #
    # Returns a Hash of {'snippet_1' => CurrentUserInfo.new(snippets[:key]['options'])}
    def snippet_objects
      @snippet_objects ||= snippets.map do |key, snippet|  # Key here is 'snippet_1'
        if snippet['class_name']
          klass = "Effective::Snippets::#{snippet['class_name'].classify}".safe_constantize
          klass.new(snippet.merge!(:region => self, :id => key)) if klass
        end
      end.compact
    end

    def global?
      regionable_id == nil && regionable_type == nil
    end

  end
end





{'fraction_non_alphanumeric': 0.10711430855315747, 'fraction_numerical': 0.0015987210231814548, 'mean_word_length': 2.9541864139020535, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 16, 'https://': 0, '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': '4867068', 'n_tokens_mistral': 793, 'n_tokens_neox': 739, 'n_words': 171}