<commit_before>require 'json'
require 'fileutils'

module BowerRails
  class Dsl

    DEFAULT_DEPENDENCY_GROUP = :dependencies

    def self.evalute(root_path, filename)
      new(root_path).tap do |dsl|
        dsl.send(eval_file_method, File.join(root_path, filename))
      end
    end

    def self.eval_file_method
      BowerRails.use_gem_deps_for_bowerfile ? :eval_file_with_deps : :eval_file
    end

    attr_reader :dependencies, :root_path

    def initialize(root_path)
      @dependency_groups = []
      @root_path = root_path
      @bower_dependencies_list = []
      @dependencies = {}
      @resolutions = {}
      @assets_path ||= "assets"
      @main_files = {}
      @current_group = nil
    end

    def asset(name, *args, &block)
      @asset_name = name
      group = @current_group || default_group
      options = Hash === args.last ? args.pop.dup : {}

      version = args.last || "latest"
      version = options[:ref] if options[:ref]

      options[:git] = "https://github.com/#{options[:github]}.git" if options[:github]

      if options[:git]
        version = if version == 'latest'
                    options[:git]
                  else
                    options[:git] + "#" + version
                  end
      end

      if options[:main_files]
        main_files(options[:main_files])
      end

      instance_eval(&block) if block_given?

      normalized_group_path = normalize_location_path(group.first, group_assets_path(group))
      @dependencies[normalized_group_path] ||= {}
      @dependencies[normalized_group_path][current_dependency_group_normalized] ||= {}
      @dependencies[normalized_group_path][current_dependency_group_normalized][name] = version
    end

    def dependency_group(name, options = {}, &block)

      assert_dependency_group_name name
      add_dependency_group name

      yield if block_given?

      remove_dependency_group!
    end

    def directories
      @dependencies.keys
    end

    def eval_file(file)
      instance_eval(File.open(file, 'rb') { |f| f.read }, file.to_s)
    end

    def eval_file_with_deps(file)
      Gem::Specification.map do |dep|
        bowerfile_in_dep = File.join(dep.gem_dir, 'Bowerfile')
        eval_file(bowerfile_in_dep) if bowerfile_in_dep != file && File.exist?(bowerfile_in_dep)
      end
      eval_file(file)
    end

    def final_assets_path
      groups.map do |group|
        [group.first.to_s, group_assets_path(group)]
      end.uniq
    end

    def generate_dotbowerrc
      contents = JSON.parse(File.read(File.join(root_path, '.bowerrc'))) rescue {}
      contents["directory"] = "bower_components"
      JSON.pretty_generate(contents)
    end

    def group_assets_path group
      group.last[:assets_path]
    end

    def group(name, options = {}, &block)
      options[:assets_path] ||= @assets_path

      assert_asset_path options[:assets_path]
      assert_group_name name

      @current_group = add_group name, options
      yield if block_given?
    end

    def resolution(name, version)
      @resolutions[name] = version
    end

    def resolutions_with_root
      { :resolutions => @resolutions }
    end

    def write_bower_json
      @dependencies.each do |dir, data|

        FileUtils.mkdir_p dir unless File.directory? dir
        File.open(File.join(dir, "bower.json"), "w") do |f|
          data.merge!(resolutions_with_root)
          f.write(dependencies_to_json(data))
        end
      end
    end<commit_msg>Add ignore_dependencies in .bowerrc<commit_after>require 'json'
require 'fileutils'

module BowerRails
  class Dsl

    DEFAULT_DEPENDENCY_GROUP = :dependencies

    def self.evalute(root_path, filename)
      new(root_path).tap do |dsl|
        dsl.send(eval_file_method, File.join(root_path, filename))
      end
    end

    def self.eval_file_method
      BowerRails.use_gem_deps_for_bowerfile ? :eval_file_with_deps : :eval_file
    end

    attr_reader :dependencies, :root_path

    def initialize(root_path)
      @dependency_groups = []
      @root_path = root_path
      @bower_dependencies_list = []
      @dependencies = {}
      @resolutions = {}
      @ignored_dependencies = []
      @assets_path ||= "assets"
      @main_files = {}
      @current_group = nil
    end

    def asset(name, *args, &block)
      @asset_name = name
      group = @current_group || default_group
      options = Hash === args.last ? args.pop.dup : {}

      version = args.last || "latest"
      version = options[:ref] if options[:ref]

      options[:git] = "https://github.com/#{options[:github]}.git" if options[:github]

      if options[:git]
        version = if version == 'latest'
                    options[:git]
                  else
                    options[:git] + "#" + version
                  end
      end

      if options[:main_files]
        main_files(options[:main_files])
      end

      instance_eval(&block) if block_given?

      normalized_group_path = normalize_location_path(group.first, group_assets_path(group))
      @dependencies[normalized_group_path] ||= {}
      @dependencies[normalized_group_path][current_dependency_group_normalized] ||= {}
      @dependencies[normalized_group_path][current_dependency_group_normalized][name] = version
    end

    def dependency_group(name, options = {}, &block)

      assert_dependency_group_name name
      add_dependency_group name

      yield if block_given?

      remove_dependency_group!
    end

    def directories
      @dependencies.keys
    end

    def eval_file(file)
      instance_eval(File.open(file, 'rb') { |f| f.read }, file.to_s)
    end

    def eval_file_with_deps(file)
      Gem::Specification.map do |dep|
        bowerfile_in_dep = File.join(dep.gem_dir, 'Bowerfile')
        eval_file(bowerfile_in_dep) if bowerfile_in_dep != file && File.exist?(bowerfile_in_dep)
      end
      eval_file(file)
    end

    def final_assets_path
      groups.map do |group|
        [group.first.to_s, group_assets_path(group)]
      end.uniq
    end

    def generate_dotbowerrc
      contents = JSON.parse(File.read(File.join(root_path, '.bowerrc'))) rescue {}
      contents["directory"] = "bower_components"
      contents["ignoredDependencies"] = @ignored_dependencies
      JSON.pretty_generate(contents)
    end

    def group_assets_path group
      group.last[:assets_path]
    end

    def group(name, options = {}, &block)
      options[:assets_path] ||= @assets_path

      assert_asset_path options[:assets_path]
      assert_group_name name

      @current_group = add_group name, options
      yield if block_given?
    end

    def resolution(name, version)
      @resolutions[name] = version
    end

    def resolutions_with_root
      { :resolutions => @resolutions }
    end

    def ignored_dependency(name)
      @ignored_dependencies.push(name)
    end

    def write_bower_json
      @dependencies.each do |dir, data|

        FileUtils.mkdir_p dir unless File.directory? dir
        File.open(File.join(dir, "bower.json"), "w") do |f|
          data.merge!(resolutions_with_root)
          f.write(dependencies_to_json(data))
        end
      end
    end
{'fraction_non_alphanumeric': 0.10095211425371045, 'fraction_numerical': 0.0, 'mean_word_length': 2.7300261096605745, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '199668', 'n_tokens_mistral': 2309, 'n_tokens_neox': 2191, 'n_words': 429}