<commit_before>class RailsDbViews::DbViewsCreator
  attr_reader :views

  def initialize
    @views = {}
  end

  def register_files files
    files.each do |file|
      view_name = File.basename(file, File.extname(file))

      content = File.read(file)
      content_lines = content.split("\n")

      # Reject the commented lines from the file
      sql_content = content_lines.reject{ |x| x.strip =~ /^--/ || x.strip =~ /^#/ }.join("\n")

      file_obj = { path: file, sql_content: sql_content, status: :none, requires: [] }

      # Detect directives in commentary
      directives = content_lines.select{ |x| x.strip =~ /^--/ || x.strip =~ /^#/ }.map(&:strip).map{ |x| 
        x =~ /^--/ ? x[2..-1] : x[1..-1]
      }.select{|x| x =~ /^!/ }

      directives.each do |directive|
        if directive =~ /^!require / #Currently only the require directive exists.
          file_obj[:requires] += directive.split(" ")[1..-1]
        end
      end

      if @views[view_name]
        puts "WARNING: #{view_name} already defined in `#{@views[view_name][:path]}`. Will be ignored and we use `#{file_obj[:path]}`..."
      end

      @views[view_name] = file_obj
    end
  end

  def drop_views
    reset_views_status!
    @views.each{ |name, view|
      drop_view name, view
    }
  end

  def create_views<commit_msg>Change hash syntax for 1.8.7<commit_after>class RailsDbViews::DbViewsCreator
  attr_reader :views

  def initialize
    @views = {}
  end

  def register_files files
    files.each do |file|
      view_name = File.basename(file, File.extname(file))

      content = File.read(file)
      content_lines = content.split("\n")

      # Reject the commented lines from the file
      sql_content = content_lines.reject{ |x| x.strip =~ /^--/ || x.strip =~ /^#/ }.join("\n")

      file_obj = { :path => file, :sql_content => sql_content, :status => :none, :requires => [] }

      # Detect directives in commentary
      directives = content_lines.select{ |x| x.strip =~ /^--/ || x.strip =~ /^#/ }.map(&:strip).map{ |x| 
        x =~ /^--/ ? x[2..-1] : x[1..-1]
      }.select{|x| x =~ /^!/ }

      directives.each do |directive|
        if directive =~ /^!require / #Currently only the require directive exists.
          file_obj[:requires] += directive.split(" ")[1..-1]
        end
      end

      if @views[view_name]
        puts "WARNING: #{view_name} already defined in `#{@views[view_name][:path]}`. Will be ignored and we use `#{file_obj[:path]}`..."
      end

      @views[view_name] = file_obj
    end
  end

  def drop_views
    reset_views_status!
    @views.each{ |name, view|
      drop_view name, view
    }
  end

  def create_views
{'fraction_non_alphanumeric': 0.16110902959910078, 'fraction_numerical': 0.005620082427875608, 'mean_word_length': 2.463035019455253, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '3001224', 'n_tokens_mistral': 945, 'n_tokens_neox': 896, 'n_words': 219}