<commit_before>module Falcor
  module DefineDsl
    class << self
      def included(base)
        base.extend ClassMethods
      end
    end

    module ClassMethods
      def allow(attr)
        self.fields = (self.fields || []).push(attr)

        default_blk = Proc.new { return self.instance_variable_get("@#{attr}".to_sym) }
        self.send(:define_method, attr, default_blk)

        default_assignment_blk = Proc.new do |val|
          self.instance_variable_set("@#{attr}".to_sym, val)
        end

        self.send(:define_method, "#{attr}=", default_assignment_blk)
      end

      def field(attr, default)
        self.fields = (self.fields || []).push(attr)

        default_blk = Proc.new { return self.instance_variable_get("@#{attr}".to_sym) || default }
        self.send(:define_method, attr, default_blk)

        default_assignment_blk = Proc.new do |val|
          self.instance_variable_set("@#{attr}".to_sym, val)
        end

        self.send(:define_method, "#{attr}=", default_assignment_blk)
      end

      def association(attr, model=nil)
        self.associations = (self.associations || []).push(attr)

        unless model
          model = Factory attr
        end

        default_blk = Proc.new { return self.instance_variable_get("@#{attr}".to_sym) || model }
        self.send(:define_method, attr, default_blk)

        default_assignment_blk = Proc.new do |val|
          if val.class == Hash
            association = self.send(attr)
            val.each do |k,v|
              association.send(:"#{k}=", v)
            end
          else
            self.instance_variable_set("@#{attr}".to_sym, val)
          end
        end
        self.send(:define_method, "#{attr}=", default_assignment_blk)
      end

      def create_list(attr, count, model)
        self.lists = (self.lists || []).push(attr)

        models = []
        count.times do
          models << model
        end

        default_blk = Proc.new { return self.instance_variable_get("@#{attr}".to_sym) || models }
        self.send(:define_method, attr, default_blk)

        default_assignment_blk = Proc.new do |val|
          raise "Invalid association list" unless val.class == Array

          factory_name = ActiveSupport::Inflector.singularize(attr).to_sym

          overrides = val.map do |override|
            Factory(factory_name, override)
          end

          self.instance_variable_set("@#{attr}".to_sym, overrides)
        end

        self.send(:define_method, "#{attr}=", default_assignment_blk)
      end
    end
  end
end<commit_msg>- Remove return statement from blocks - Make all tests pass with JRuby<commit_after>module Falcor
  module DefineDsl
    class << self
      def included(base)
        base.extend ClassMethods
      end
    end

    module ClassMethods
      def allow(attr)
        self.fields = (self.fields || []).push(attr)

        default_blk = Proc.new { self.instance_variable_get("@#{attr}".to_sym) }
        self.send(:define_method, attr, default_blk)

        default_assignment_blk = Proc.new do |val|
          self.instance_variable_set("@#{attr}".to_sym, val)
        end

        self.send(:define_method, "#{attr}=", default_assignment_blk)
      end

      def field(attr, default)
        self.fields = (self.fields || []).push(attr)

        default_blk = Proc.new { self.instance_variable_get("@#{attr}".to_sym) || default }
        self.send(:define_method, attr, default_blk)

        default_assignment_blk = Proc.new do |val|
          self.instance_variable_set("@#{attr}".to_sym, val)
        end

        self.send(:define_method, "#{attr}=", default_assignment_blk)
      end

      def association(attr, model=nil)
        self.associations = (self.associations || []).push(attr)

        unless model
          model = Factory attr
        end

        default_blk = Proc.new { self.instance_variable_get("@#{attr}".to_sym) || model }
        self.send(:define_method, attr, default_blk)

        default_assignment_blk = Proc.new do |val|
          if val.class == Hash
            association = self.send(attr)
            val.each do |k,v|
              association.send(:"#{k}=", v)
            end
          else
            self.instance_variable_set("@#{attr}".to_sym, val)
          end
        end
        self.send(:define_method, "#{attr}=", default_assignment_blk)
      end

      def create_list(attr, count, model)
        self.lists = (self.lists || []).push(attr)

        models = []
        count.times do
          models << model
        end

        default_blk = Proc.new { self.instance_variable_get("@#{attr}".to_sym) || models }
        self.send(:define_method, attr, default_blk)

        default_assignment_blk = Proc.new do |val|
          raise "Invalid association list" unless val.class == Array

          factory_name = ActiveSupport::Inflector.singularize(attr).to_sym

          overrides = val.map do |override|
            Factory(factory_name, override)
          end

          self.instance_variable_set("@#{attr}".to_sym, overrides)
        end

        self.send(:define_method, "#{attr}=", default_assignment_blk)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.12062632901604485, 'fraction_numerical': 0.0, 'mean_word_length': 2.2892561983471076, 'pattern_counts': {'":': 0, '<': 11, '<?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': '888566', 'n_tokens_mistral': 1578, 'n_tokens_neox': 1552, 'n_words': 320}