<commit_before>require 'puppet/provider/mongodb'

Puppet::Type.type(:mongodb_database).provide :mongodb, :parent => Puppet::Provider::Mongodb do

  desc 'Manages MongoDB database.'

  defaultfor :kernel => 'Linux'

  def create
    mongo_command('db.dummyData.insert({"created_by_puppet": 1})', @resource[:router], @resource[:name])
  end

  def destroy
    mongo_command('db.dropDatabase()', @resource[:router], @resource[:name])
  end

  def exists?
    block_until_command
    unless db_ismaster(@resource[:router])
      raise Puppet::Error, "Cannot add database `#{@resource[:name]}` on non-primary `#{@resource[:router]}`"
    end

    mongo_command_json('db.getMongo().getDBNames()', @resource[:router]).include?(@resource[:name])
  end

  def shard
    issharded = sh_issharded(@resource[:name], @resource[:router])
    issharded ? :true : :false
  end

  def shard=(value)
    if :true == value
      sh_enable(@resource[:name], @resource[:router])
    else
      raise Puppet::Error, "Cannot disable sharding for database `#{@resource[:name]}`"
    end
  end

  private

  def sh_enable(dbname, master)
    self.mongo_command_json("sh.enableSharding('#{dbname}')", master)
  end<commit_msg>Raise error if database should be removed<commit_after>require 'puppet/provider/mongodb'

Puppet::Type.type(:mongodb_database).provide :mongodb, :parent => Puppet::Provider::Mongodb do

  desc 'Manages MongoDB database.'

  defaultfor :kernel => 'Linux'

  def create
    mongo_command('db.dummyData.insert({"created_by_puppet": 1})', @resource[:router], @resource[:name])
  end

  def destroy
    raise Puppet::Error, 'Not implemented'
  end

  def exists?
    block_until_command
    unless db_ismaster(@resource[:router])
      raise Puppet::Error, "Cannot add database `#{@resource[:name]}` on non-primary `#{@resource[:router]}`"
    end

    mongo_command_json('db.getMongo().getDBNames()', @resource[:router]).include?(@resource[:name])
  end

  def shard
    issharded = sh_issharded(@resource[:name], @resource[:router])
    issharded ? :true : :false
  end

  def shard=(value)
    if :true == value
      sh_enable(@resource[:name], @resource[:router])
    else
      raise Puppet::Error, "Cannot disable sharding for database `#{@resource[:name]}`"
    end
  end

  private

  def sh_enable(dbname, master)
    self.mongo_command_json("sh.enableSharding('#{dbname}')", master)
  end
{'fraction_non_alphanumeric': 0.15288220551378445, 'fraction_numerical': 0.000835421888053467, 'mean_word_length': 4.743405275779376, 'pattern_counts': {'":': 2, '<': 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': '5830856', 'n_tokens_mistral': 810, 'n_tokens_neox': 779, 'n_words': 168}