<commit_before>require File.expand_path(File.join(File.dirname(__FILE__), '..', 'nc_api'))
require 'json'
require 'pry'

Puppet::Type.type(:puppet_environment).provide(:puppet_environment, :parent => Puppet::Provider::Nc_api) do

  # API will fail if disallowed-keys are passed
  def self.friendly_name
    {
      :name => 'name',
    }
  end

  def self.instances
    env = JSON.parse(rest('GET', 'environments'))
    env.collect do |env|
      env_hash = {}
      friendly_name.each do |property,friendly|
        env_hash[friendly.to_sym] = env[property.to_s]
      end
      env_hash[:ensure] = :present
      new(env_hash)
    end
  end

  def self.prefetch(resources)
    env = instances
    resources.keys.each do |env|
      resources[env].provider = 'puppet_environment'
    end
  end

  def exists?
    @property_hash[:ensure] == :present
  end

  mk_resource_methods

  def create
    binding.pry
    # Only passing parameters that are given
    send_data = @resource.original_parameters
    # namevar may not be in this hash
    send_data[:name] = resource[:name] unless send_data[:name]

    resp = Puppet::Provider::Nc_api.rest('PUT', "environments/#{send_data[:name]}")

    send_data.each_key do |k|
      @property_hash[k] = @resource[k]
    end

    exists? ? (return true) : (return false)<commit_msg>Removed pry refs<commit_after>require File.expand_path(File.join(File.dirname(__FILE__), '..', 'nc_api'))
require 'json'

Puppet::Type.type(:puppet_environment).provide(:puppet_environment, :parent => Puppet::Provider::Nc_api) do

  # API will fail if disallowed-keys are passed
  def self.friendly_name
    {
      :name => 'name',
    }
  end

  def self.instances
    env = JSON.parse(rest('GET', 'environments'))
    env.collect do |env|
      env_hash = {}
      friendly_name.each do |property,friendly|
        env_hash[friendly.to_sym] = env[property.to_s]
      end
      env_hash[:ensure] = :present
      new(env_hash)
    end
  end

  def self.prefetch(resources)
    env = instances
    resources.keys.each do |env|
      resources[env].provider = 'puppet_environment'
    end
  end

  def exists?
    @property_hash[:ensure] == :present
  end

  mk_resource_methods

  def create
    # Only passing parameters that are given
    send_data = @resource.original_parameters
    # namevar may not be in this hash
    send_data[:name] = resource[:name] unless send_data[:name]

    resp = Puppet::Provider::Nc_api.rest('PUT', "environments/#{send_data[:name]}")

    send_data.each_key do |k|
      @property_hash[k] = @resource[k]
    end

    exists? ? (return true) : (return false)
{'fraction_non_alphanumeric': 0.124282982791587, 'fraction_numerical': 0.0, 'mean_word_length': 3.3819095477386933, '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': '3954183', 'n_tokens_mistral': 884, 'n_tokens_neox': 862, 'n_words': 190}