<commit_before>require 'generators/curation_concerns/work/work_generator'

module Sufia
  class WorkGenerator < CurationConcerns::WorkGenerator
    source_root CurationConcerns::WorkGenerator.source_root

    # Allows us to pull templates from sufia as well as from curation_concerns
    def self.source_paths
      [File.expand_path('../templates/', __FILE__)]
    end

    desc """
  This generator makes the following changes to your application:
   1. Generates work model
   2. Injects sufia behavior into model
   3. Injects sufia behavior into form
         """

    def create_model
      say_status("info", "GENERATING WORK MODEL", :blue)
      super
    end

    def create_i18n
      template 'locale.en.yml.erb', "config/locales/#{file_name}.en.yml"
    end

    def register_work
      inject_into_file 'config/initializers/sufia.rb', after: "Sufia.config do |config|\n" do
        "  # Injected via `rails g sufia:work #{class_name}`\n" \
        "  config.register_curation_concern :#{file_name}\n"
      end
    end

    def inject_sufia_work_behavior
      underscored_name = name.underscore
      insert_into_file "app/models/#{underscored_name}.rb", after: 'include ::CurationConcerns::BasicMetadata' do
        "\n  include Sufia::WorkBehavior" \
        "\n  self.human_readable_type = '#{underscored_name.titleize}'"
      end
    end
<commit_msg>Change work generator to insert after last created work, if any<commit_after>require 'generators/curation_concerns/work/work_generator'

module Sufia
  class WorkGenerator < CurationConcerns::WorkGenerator
    source_root CurationConcerns::WorkGenerator.source_root

    # Allows us to pull templates from sufia as well as from curation_concerns
    def self.source_paths
      [File.expand_path('../templates/', __FILE__)]
    end

    desc """
  This generator makes the following changes to your application:
   1. Generates work model
   2. Injects sufia behavior into model
   3. Injects sufia behavior into form
         """

    def create_model
      say_status("info", "GENERATING WORK MODEL", :blue)
      super
    end

    def create_i18n
      template 'locale.en.yml.erb', "config/locales/#{file_name}.en.yml"
    end

    # Inserts after the last registering work, or at the top of the config block
    def register_work
      config = 'config/initializers/sufia.rb'
      lastmatch = nil
      File.open(config).each_line do |line|
        lastmatch = line if line =~ /^\s*config.register_curation_concern :.*\n$/
      end
      content = "  # Injected via `rails g sufia:work #{class_name}`\n" \
                "  config.register_curation_concern :#{file_name}\n"
      content = "  # Note: order of registration affects Zotero/Arkivo\n#{content}" unless lastmatch
      anchor = lastmatch || "Sufia.config do |config|\n"
      inject_into_file config, after: anchor do
        content
      end
    end

    def inject_sufia_work_behavior
      underscored_name = name.underscore
      insert_into_file "app/models/#{underscored_name}.rb", after: 'include ::CurationConcerns::BasicMetadata' do
        "\n  include Sufia::WorkBehavior" \
        "\n  self.human_readable_type = '#{underscored_name.titleize}'"
      end
    end

{'fraction_non_alphanumeric': 0.0923220391669257, 'fraction_numerical': 0.003108486167236556, 'mean_word_length': 3.0993630573248407, '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': '7309903', 'n_tokens_mistral': 1045, 'n_tokens_neox': 994, 'n_words': 260}