<commit_before>require 'cheffish/version'
require 'chef/dsl/recipe'
require 'chef/event_dispatch/base'
require 'chef/event_dispatch/dispatcher'
require 'chef/node'
require 'chef/run_context'
require 'chef/runner'
require 'forwardable'
require 'chef/providers'
require 'chef/resources'

module Cheffish
  class BasicChefClient
    include Chef::DSL::Recipe

    def initialize(node = nil, events = nil, **chef_config)
      if !node
        node = Chef::Node.new
        node.name 'basic_chef_client'
        node.automatic[:platform] = 'basic_chef_client'
        node.automatic[:platform_version] = Cheffish::VERSION
      end

      # Decide on the config we want for this chef client
      @chef_config = chef_config

      with_chef_config do
        @cookbook_name = 'basic_chef_client'
        @event_catcher = BasicChefClientEvents.new
        dispatcher = Chef::EventDispatch::Dispatcher.new(@event_catcher)
        case events
        when nil
        when Array
          events.each { |e| dispatcher.register(e) } if events
        else
          dispatcher.register(events)
        end
        @run_context = Chef::RunContext.new(node, {}, dispatcher)
        @updated = []
        @cookbook_name = 'basic_chef_client'
      end
    end

    extend Forwardable

    # Stuff recipes need
    attr_reader :chef_config
    attr_reader :run_context
    attr_accessor :cookbook_name
    attr_accessor :recipe_name

    def add_resource(resource)
      with_chef_config do
        resource.run_context = run_context
        run_context.resource_collection.insert(resource)
      end
    end

    def load_block(&block)
      with_chef_config do
        @recipe_name = 'block'
        instance_eval(&block)
      end
    end

    def converge
      with_chef_config do
        Chef::Runner.new(run_context).converge
      end
    end

    def updates
      @event_catcher.updates
    end

    def updated?
      @event_catcher.updates.size > 0
    end

    # Builds a resource sans context, which can be later used in a new client's
    # add_resource() method.
    def self.build_resource(type, name, created_at=nil, &resource_attrs_block)
      created_at ||= caller[0]
      result = BasicChefClient.new.tap do |client|<commit_msg>Revert "fix completely object model insanity"<commit_after>require 'cheffish/version'
require 'chef/dsl/recipe'
require 'chef/event_dispatch/base'
require 'chef/event_dispatch/dispatcher'
require 'chef/node'
require 'chef/run_context'
require 'chef/runner'
require 'forwardable'
require 'chef/providers'
require 'chef/resources'

module Cheffish
  class BasicChefClient
    include Chef::DSL::Recipe

    def initialize(node = nil, events = nil, **chef_config)
      if !node
        node = Chef::Node.new
        node.name 'basic_chef_client'
        node.automatic[:platform] = 'basic_chef_client'
        node.automatic[:platform_version] = Cheffish::VERSION
      end

      # Decide on the config we want for this chef client
      @chef_config = chef_config

      with_chef_config do
        @cookbook_name = 'basic_chef_client'
        @event_catcher = BasicChefClientEvents.new
        dispatcher = Chef::EventDispatch::Dispatcher.new(@event_catcher)
        case events
        when nil
        when Array
          events.each { |e| dispatcher.register(e) } if events
        else
          dispatcher.register(events)
        end
        @run_context = Chef::RunContext.new(node, {}, dispatcher)
        @updated = []
        @cookbook_name = 'basic_chef_client'
      end
    end

    extend Forwardable

    # Stuff recipes need
    attr_reader :chef_config
    attr_reader :run_context
    attr_accessor :cookbook_name
    attr_accessor :recipe_name
    def_delegators :@run_context, :resource_collection, :immediate_notifications, :delayed_notifications

    def add_resource(resource)
      with_chef_config do
        resource.run_context = run_context
        run_context.resource_collection.insert(resource)
      end
    end

    def load_block(&block)
      with_chef_config do
        @recipe_name = 'block'
        instance_eval(&block)
      end
    end

    def converge
      with_chef_config do
        Chef::Runner.new(self).converge
      end
    end

    def updates
      @event_catcher.updates
    end

    def updated?
      @event_catcher.updates.size > 0
    end

    # Builds a resource sans context, which can be later used in a new client's
    # add_resource() method.
    def self.build_resource(type, name, created_at=nil, &resource_attrs_block)
      created_at ||= caller[0]
      result = BasicChefClient.new.tap do |client|
{'fraction_non_alphanumeric': 0.0798611111111111, 'fraction_numerical': 0.0008680555555555555, 'mean_word_length': 2.824896265560166, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7037929', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1409, 'n_words': 327}