<commit_before>module StashEngine
  class Resource < ActiveRecord::Base
    # ------------------------------------------------------------
    # Relations

    has_many :file_uploads, class_name: 'StashEngine::FileUpload', dependent: :destroy
    has_one :stash_version, class_name: 'StashEngine::Version'
    belongs_to :identifier, class_name: 'StashEngine::Identifier', foreign_key: 'identifier_id'
    has_one :resource_usage, class_name: 'StashEngine::ResourceUsage'
    has_one :embargo, class_name: 'StashEngine::Embargo'
    belongs_to :user, class_name: 'StashEngine::User'
    has_one :current_state,
            class_name: 'StashEngine::ResourceState',
            primary_key: 'current_resource_state_id',
            foreign_key: 'id'

    amoeba do
      include_association :file_uploads
      customize(lambda do |_, new_resource|
        new_resource.file_uploads.each do |file|
          raise "Expected #{new_resource.id}, was #{file.resource_id}" unless file.resource_id == new_resource.id
          if file.file_state == 'created'
            file.file_state = 'copied'
            file.save
          end
        end
      end)
    end

    # ------------------------------------------------------------
    # Patch points

    def primary_title
      raise NoMethodError, 'Metadata engine should patch Resource to implement :primary_title'
    end

    # ------------------------------------------------------------
    # Callbacks

    def init_state_and_version<commit_msg>Include embargo in amoeba duplication<commit_after>module StashEngine
  class Resource < ActiveRecord::Base
    # ------------------------------------------------------------
    # Relations

    has_many :file_uploads, class_name: 'StashEngine::FileUpload', dependent: :destroy
    has_one :stash_version, class_name: 'StashEngine::Version'
    belongs_to :identifier, class_name: 'StashEngine::Identifier', foreign_key: 'identifier_id'
    has_one :resource_usage, class_name: 'StashEngine::ResourceUsage'
    has_one :embargo, class_name: 'StashEngine::Embargo'
    belongs_to :user, class_name: 'StashEngine::User'
    has_one :current_state,
            class_name: 'StashEngine::ResourceState',
            primary_key: 'current_resource_state_id',
            foreign_key: 'id'

    amoeba do
      include_association :embargo
      include_association :file_uploads
      customize(lambda do |_, new_resource|
        new_resource.file_uploads.each do |file|
          raise "Expected #{new_resource.id}, was #{file.resource_id}" unless file.resource_id == new_resource.id
          if file.file_state == 'created'
            file.file_state = 'copied'
            file.save
          end
        end
      end)
    end

    # ------------------------------------------------------------
    # Patch points

    def primary_title
      raise NoMethodError, 'Metadata engine should patch Resource to implement :primary_title'
    end

    # ------------------------------------------------------------
    # Callbacks

    def init_state_and_version
{'fraction_non_alphanumeric': 0.19332679097154074, 'fraction_numerical': 0.0, 'mean_word_length': 2.018756169792695, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '651674', 'n_tokens_mistral': 822, 'n_tokens_neox': 797, 'n_words': 181}