<commit_before>module Humpyard
  ####
  # Humpyard::Element is a model of an element to display on a Humpyard::Page.
  class Element < ::ActiveRecord::Base
    attr_accessible :page, :page_id, :content_data, :content_data_id, :content_data_type, :page_yield_name, :container, :container_id, :display_until, :display_from

    set_table_name "#{Humpyard::config.table_name_prefix}elements"

    belongs_to :page, :class_name => 'Humpyard::Page'
    belongs_to :container, :class_name => 'Humpyard::Element'
    belongs_to :content_data, :polymorphic => true, :dependent => :destroy
    has_many :elements, :class_name => 'Humpyard::Element', :foreign_key => :container_id, :order => :position
    
    delegate :'is_humpyard_container_element?', :'is_humpyard_element?', :to => :content_data

    validates_with Humpyard::ActiveModel::PublishRangeValidator, {:attributes => [:display_from, :display_until]}
    
    # Return the logical modification time for the element.
    #
    def last_modified
      rails_root_mtime = Time.zone.at(::File.new("#{Rails.root}").mtime)
      timestamps = [rails_root_mtime, self.updated_at]
      timestamps.sort.last
    end
    
  end
end<commit_msg>beginnings of shared elements<commit_after>module Humpyard
  ####
  # Humpyard::Element is a model of an element to display on a Humpyard::Page.
  class Element < ::ActiveRecord::Base
    attr_accessible :page, :page_id, :content_data, :content_data_id, :content_data_type, :page_yield_name, :container, :container_id, :display_until, :display_from

    set_table_name "#{Humpyard::config.table_name_prefix}elements"

    belongs_to :page, :class_name => 'Humpyard::Page'
    belongs_to :container, :class_name => 'Humpyard::Element'
    belongs_to :content_data, :polymorphic => true, :dependent => :destroy
    has_many :elements, :class_name => 'Humpyard::Element', :foreign_key => :container_id, :order => :position
    
    delegate :'is_humpyard_container_element?', :'is_humpyard_element?', :to => :content_data

    validates_with Humpyard::ActiveModel::PublishRangeValidator, {:attributes => [:display_from, :display_until]}
    
    # Elements can be shared on other pages. this adds #unshared?, #shared_on_siblings?, shared_on_children? getters
    # plus #to_unshared, #to_shared_on_siblings, #to_shared_on_children "setters"
    # 
    SHARED_STATES = { 
      :unshared => 0,
      :shared_on_siblings   => 1,
      :shared_on_children  => 2
    }.each_pair do |key, value|
      define_method "#{key}?" do
        state == value
      end
      define_method "to_#{key}" do
        update_attribute :state, value unless state == value # no point in troubling the database if the state is already == value
      end
    end


    # Return the logical modification time for the element.
    #
    def last_modified
      rails_root_mtime = Time.zone.at(::File.new("#{Rails.root}").mtime)
      timestamps = [rails_root_mtime, self.updated_at]
      timestamps.sort.last
    end
    

    
  end
end
{'fraction_non_alphanumeric': 0.11737245748582861, 'fraction_numerical': 0.0010003334444814939, 'mean_word_length': 4.272407732864675, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 24, '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': '4202724', 'n_tokens_mistral': 997, 'n_tokens_neox': 972, 'n_words': 222}