<commit_before># libs
require_relative 'resource_deprecations'
require_relative 'resource_defaults'
require_relative 'commands'

module PlatformSpecificBuilders

  def generates_archive_commands_for(application,options)
    condition = options[:when_the]
    builder = options[:with_builder_klass]
    archive_command_generators.push [ condition, builder ]
  end

  def archive_command_generators
    @archive_command_generators ||= []
  end

end

module Opscode
  module Ark
    module ProviderHelpers
      extend PlatformSpecificBuilders

      generates_archive_commands_for :seven_zip,
        when_the: -> { node['platform_family'] == 'windows' },
        with_builder_klass: SevenZipCommandBuilder

      generates_archive_commands_for :unzip,
        when_the: -> { new_resource.extension =~ /zip|war|jar/ },
        with_builder_klass: UnzipCommandBuilder

      generates_archive_commands_for :tar,
        when_the: -> { true },
        with_builder_klass: TarCommandBuilder

      def deprecations
        ::Ark::ResourceDeprecations.on(new_resource)
      end

      def show_deprecations
        deprecations.each { |message| Chef::Log.warn("DEPRECATED: #{message}") }
      end

      def defaults
        @resource_defaults ||= ::Ark::ResourceDefaults.new(new_resource)
      end

      def set_paths
        new_resource.extension = defaults.extension
        new_resource.prefix_bin = defaults.prefix_bin
        new_resource.prefix_root = defaults.prefix_root
        new_resource.home_dir = defaults.home_dir
        new_resource.version = defaults.version

        # TODO: what happens when the path is already set -- with the current logic we overwrite it\
        # if you are in windows we overwrite it
        # otherwise we overwrite it with the root/name-version
        new_resource.path = defaults.path
        new_resource.release_file = defaults.release_file
      end

      def set_put_paths
        new_resource.extension = defaults.extension

        # TODO: Should this be added - as the prefix_root could be used in the path_with_version
        # new_resource.prefix_root = default.prefix_root
        new_resource.path = defaults.path_without_version
        new_resource.release_file = defaults.release_file_without_version
      end

      def set_dump_paths
        new_resource.extension = defaults.extension
        new_resource.release_file = defaults.release_file_without_version
      end

      def unpack_command
        archive_application.unpack
      end

      def dump_command
        archive_application.dump
      end

      def cherry_pick_command
        archive_application.cherry_pick
      end

      def unzip_command
        UnzipCommandBuilder.new(new_resource).unpack
      end

      def owner_command
        if node['platform_family'] == 'windows'
          WindowsOwner.new(new_resource).command
        else
          GeneralOwner.new(new_resource).command
        end
      end

      private

      def archive_application
        @archive_application ||= builder_klass.new(new_resource)
      end

      def builder_klass
        new_resource.extension ||= defaults.extension
        Opscode::Ark::ProviderHelpers.archive_command_generators.find { |condition, klass| instance_exec(&condition) }.last
      end

    end
  end
end<commit_msg>Refactored Owner command generation to be the same archive command gen<commit_after># libs
require_relative 'resource_deprecations'
require_relative 'resource_defaults'
require_relative 'commands'

module PlatformSpecificBuilders

  def generates_archive_commands_for(application,options)
    condition = options[:when_the]
    builder = options[:with_klass]
    archive_command_generators.push [ condition, builder ]
  end

  def archive_command_generators
    @archive_command_generators ||= []
  end

  def generates_owner_commands_for(application,options)
    condition = options[:when_the]
    builder = options[:with_klass]
    owner_command_generators.push [ condition, builder ]
  end

  def owner_command_generators
    @owner_command_generators ||= []
  end

end

module Opscode
  module Ark
    module ProviderHelpers
      extend PlatformSpecificBuilders

      generates_archive_commands_for :seven_zip,
        when_the: -> { node['platform_family'] == 'windows' },
        with_klass: SevenZipCommandBuilder

      generates_archive_commands_for :unzip,
        when_the: -> { new_resource.extension =~ /zip|war|jar/ },
        with_klass: UnzipCommandBuilder

      generates_archive_commands_for :tar,
        when_the: -> { true },
        with_klass: TarCommandBuilder


      generates_owner_commands_for :windows,
        when_the: -> { node['platform_family'] == 'windows' },
        with_klass: WindowsOwner

      generates_owner_commands_for :all_other_platforms,
        when_the: -> { true },
        with_klass: GeneralOwner

      def deprecations
        ::Ark::ResourceDeprecations.on(new_resource)
      end

      def show_deprecations
        deprecations.each { |message| Chef::Log.warn("DEPRECATED: #{message}") }
      end

      def defaults
        @resource_defaults ||= ::Ark::ResourceDefaults.new(new_resource)
      end

      def set_paths
        new_resource.extension = defaults.extension
        new_resource.prefix_bin = defaults.prefix_bin
        new_resource.prefix_root = defaults.prefix_root
        new_resource.home_dir = defaults.home_dir
        new_resource.version = defaults.version

        # TODO: what happens when the path is already set -- with the current logic we overwrite it\
        # if you are in windows we overwrite it
        # otherwise we overwrite it with the root/name-version
        new_resource.path = defaults.path
        new_resource.release_file = defaults.release_file
      end

      def set_put_paths
        new_resource.extension = defaults.extension

        # TODO: Should this be added - as the prefix_root could be used in the path_with_version
        # new_resource.prefix_root = default.prefix_root
        new_resource.path = defaults.path_without_version
        new_resource.release_file = defaults.release_file_without_version
      end

      def set_dump_paths
        new_resource.extension = defaults.extension
        new_resource.release_file = defaults.release_file_without_version
      end

      def unpack_command
        archive_application.unpack
      end

      def dump_command
        archive_application.dump
      end

      def cherry_pick_command
        archive_application.cherry_pick
      end

      def unzip_command
        UnzipCommandBuilder.new(new_resource).unpack
      end

      def owner_command
        owner_builder_klass.new(new_resource).command
      end

      private

      def archive_application
        @archive_application ||= archive_builder_klass.new(new_resource)
      end

      def archive_builder_klass
        new_resource.extension ||= defaults.extension
        Opscode::Ark::ProviderHelpers.archive_command_generators.find { |condition, klass| instance_exec(&condition) }.last
      end

      def owner_builder_klass
        Opscode::Ark::ProviderHelpers.owner_command_generators.find { |condition, klass| instance_exec(&condition) }.last
      end

    end
  end
end
{'fraction_non_alphanumeric': 0.06461411017534172, 'fraction_numerical': 0.0, 'mean_word_length': 2.9911845730027546, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '6571701', 'n_tokens_mistral': 2007, 'n_tokens_neox': 1963, 'n_words': 426}