<commit_before>module Hussar
  class Addon
    FIELDS = {
      :software_name  => :string,
      :watch_port     => :bool,
      :scheduler_actions => :cron,
      :install        => :shell,
      :start          => :shell,
      :validate       => :shell
    }

    attr_accessor :name

    def initialize(name, &block)
      @name = name
      @fields = {}
      @default_options = IndifferentHash.new
      block.call(self)
    end

    def default_options
      @default_options
    end

    FIELDS.each do |field, type|
      case type
      when :string, :bool
        class_eval <<-EOS, __FILE__, __LINE__
          def #{field}(value)
            @fields[:#{field}] = value
          end
        EOS
      when :shell
        class_eval <<-EOS, __FILE__, __LINE__
          def #{field}(&block)
            @fields[:#{field}] = Shell.new(&block)
          end
        EOS
      when :cron
        class_eval <<-EOS, __FILE__, __LINE__
          def #{field}(&block)
            @fields[:#{field}] = Cron.new(&block)
          end
        EOS
      end
    end

    def default_fields
      {
        :install => default_install
      }
    end

    def default_install
      soft = @fields[:software_name].downcase
      Shell.new do
        sh "sofin get #{soft}", false
        expect "All done"
      end
    end

    def generate(options = {})
      options = @default_options.merge(options)

      default_fields.merge(@fields).inject({}) do |hash, (field, gen_or_value)|
        value = if gen_or_value.respond_to?(:generate)
          gen_or_value.generate(options)
        else
          gen_or_value<commit_msg>fix: Use __LINE__ + 1 when defining methods with class_eval<commit_after>module Hussar
  class Addon
    FIELDS = {
      :software_name  => :string,
      :watch_port     => :bool,
      :scheduler_actions => :cron,
      :install        => :shell,
      :start          => :shell,
      :validate       => :shell
    }

    attr_accessor :name

    def initialize(name, &block)
      @name = name
      @fields = {}
      @default_options = IndifferentHash.new
      block.call(self)
    end

    def default_options
      @default_options
    end

    FIELDS.each do |field, type|
      case type
      when :string, :bool
        class_eval <<-EOS, __FILE__, __LINE__ + 1
          def #{field}(value)
            @fields[:#{field}] = value
          end
        EOS
      when :shell
        class_eval <<-EOS, __FILE__, __LINE__ + 1
          def #{field}(&block)
            @fields[:#{field}] = Shell.new(&block)
          end
        EOS
      when :cron
        class_eval <<-EOS, __FILE__, __LINE__ + 1
          def #{field}(&block)
            @fields[:#{field}] = Cron.new(&block)
          end
        EOS
      end
    end

    def default_fields
      {
        :install => default_install
      }
    end

    def default_install
      soft = @fields[:software_name].downcase
      Shell.new do
        sh "sofin get #{soft}", false
        expect "All done"
      end
    end

    def generate(options = {})
      options = @default_options.merge(options)

      default_fields.merge(@fields).inject({}) do |hash, (field, gen_or_value)|
        value = if gen_or_value.respond_to?(:generate)
          gen_or_value.generate(options)
        else
          gen_or_value
{'fraction_non_alphanumeric': 0.11007237635705669, 'fraction_numerical': 0.0012062726176115801, 'mean_word_length': 1.7873949579831934, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, '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': '4076846', 'n_tokens_mistral': 1029, 'n_tokens_neox': 1008, 'n_words': 238}