<commit_before>#
# Abstract class for events. All implementation specific events are derived from
# this
#
class AssetEvent < ActiveRecord::Base
      
  # Include the unique key mixin
  include UniqueKey
  # Include the numeric sanitizers mixin
  include NumericSanitizers
  # Include the fiscal year mixin
  include FiscalYear

  #------------------------------------------------------------------------------
  # Overrides
  #------------------------------------------------------------------------------
  
  #require rails to use the asset key as the restful parameter. All URLS will be of the form
  # /asset_event/{object_key}/...
  def to_param
    object_key
  end
      
  # Callbacks
  after_initialize :set_defaults

  # Always generate a unique asset key before saving to the database
  before_validation(:on => :create) do
    generate_unique_key(:object_key)
  end
      
  # Associations
  
  # Every event belongs to an asset
  belongs_to  :asset
  # Every event is of a type
  belongs_to  :asset_event_type
  
  validates :object_key,          :presence => true, :uniqueness => true
  validates :asset_id,            :presence => true
  validates :asset_event_type_id, :presence => true
  validates :event_date,          :presence => true
    
  # default scope
  default_scope { order("event_date") }
  # named scopes

  # List of hash parameters allowed by the controller
  FORM_PARAMS = [
    :object_key,
    :asset_id,
    :asset_event_type_id, 
    :asset_type_id, 
    :event_date, 
    :comments
  ]
  
  #------------------------------------------------------------------------------
  #
  # Class Methods
  #
  #------------------------------------------------------------------------------
    
  def self.allowable_params
    FORM_PARAMS
  end
  
  # Returns a typed version of itself. Every asset has a type and this will
  # return a specific asset type based on the AssetType attribute
  def self.as_typed_event(asset_event)
    if asset_event
      class_name = asset_event.asset_event_type.class_name
      klass = Object.const_get class_name
      o = klass.find(asset_event.id)
      return o
    end
  end

  #------------------------------------------------------------------------------
  #
  # Instance Methods<commit_msg>Extending out TransamObjectKey to AssetEvent<commit_after>#
# Abstract class for events. All implementation specific events are derived from
# this
#
class AssetEvent < ActiveRecord::Base
      
  # Include the object key mixin
  include TransamObjectKey
  # Include the numeric sanitizers mixin
  include NumericSanitizers
  # Include the fiscal year mixin
  include FiscalYear

  #------------------------------------------------------------------------------
  # Overrides
  #------------------------------------------------------------------------------
  
      
  # Callbacks
  after_initialize :set_defaults

  # Associations
  
  # Every event belongs to an asset
  belongs_to  :asset
  # Every event is of a type
  belongs_to  :asset_event_type
  
  validates :asset_id,            :presence => true
  validates :asset_event_type_id, :presence => true
  validates :event_date,          :presence => true
    
  # default scope
  default_scope { order("event_date") }
  # named scopes

  # List of hash parameters allowed by the controller
  FORM_PARAMS = [
    :asset_id,
    :asset_event_type_id, 
    :asset_type_id, 
    :event_date, 
    :comments
  ]
  
  #------------------------------------------------------------------------------
  #
  # Class Methods
  #
  #------------------------------------------------------------------------------
    
  def self.allowable_params
    FORM_PARAMS
  end
  
  # Returns a typed version of itself. Every asset has a type and this will
  # return a specific asset type based on the AssetType attribute
  def self.as_typed_event(asset_event)
    if asset_event
      class_name = asset_event.asset_event_type.class_name
      klass = Object.const_get class_name
      o = klass.find(asset_event.id)
      return o
    end
  end

  #------------------------------------------------------------------------------
  #
  # Instance Methods
{'fraction_non_alphanumeric': 0.23645557428365038, 'fraction_numerical': 0.0, 'mean_word_length': 1.5069402534701268, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 12, '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': '4790707', 'n_tokens_mistral': 1100, 'n_tokens_neox': 1070, 'n_words': 323}