<commit_before>require 'ostruct'
require 'delegate'
require 'usable/version'
require 'usable/mod_extender'
require 'usable/config'

module Usable

  def usable_config
    @usable_config ||= Config.new
  end
  attr_writer :usable_config

  # @description Configures the +available_methods+ of a module using the given options or block and then includes it on
  #   the target class. Checks if there is a module named UsableSpec within the given mods namespace and uses the instance of
  #   methods of that as the +available_methods+
  #
  # @example
  #
  #   class Example
  #     extend Usable
  #     usable VersionKit, only: :save_version
  #   end
  #
  # @note Hides methods
  # @note We include the primary mod when there is a UsableSpec set because any instance method defined on the mod are not
  #   configurable and should therefore takes precedence over those defined in the UsableSpec
  # @return [ModExtender] containing the original and modified module
  def usable(mod, options = {})
    options.each { |k, v| usable_config.public_send "#{k}=", v }
    yield usable_config if block_given?
    mod_ext = ModExtender.new mod, usable_config
    usable! mod_ext
    usable! mod if mod_ext.has_spec?
    mod_ext
  end

  # @description Directly include a module whose methods you want made available in +usable_config.available_methods+
  #   Gives the module a name when including so that it shows up properly in the list of ancestors
  def usable!(mod)
    mod_name = mod.name ? mod.name.split('::').last : "UsableMod#{Time.now.strftime('%s')}"
    const_name = "#{mod_name}Used"
    mod = mod.call if mod.respond_to? :call
    remove_const const_name if const_defined? const_name
    const_set const_name, mod
    usable_config.modules << mod
    send :include, mod<commit_msg>scope const lookup to exclude parent classes<commit_after>require 'ostruct'
require 'delegate'
require 'usable/version'
require 'usable/mod_extender'
require 'usable/config'

module Usable

  def usable_config
    @usable_config ||= Config.new
  end
  attr_writer :usable_config

  # @description Configures the +available_methods+ of a module using the given options or block and then includes it on
  #   the target class. Checks if there is a module named UsableSpec within the given mods namespace and uses the instance of
  #   methods of that as the +available_methods+
  #
  # @example
  #
  #   class Example
  #     extend Usable
  #     usable VersionKit, only: :save_version
  #   end
  #
  # @note Hides methods
  # @note We include the primary mod when there is a UsableSpec set because any instance method defined on the mod are not
  #   configurable and should therefore takes precedence over those defined in the UsableSpec
  # @return [ModExtender] containing the original and modified module
  def usable(mod, options = {})
    options.each { |k, v| usable_config.public_send "#{k}=", v }
    yield usable_config if block_given?
    mod_ext = ModExtender.new mod, usable_config
    usable! mod_ext
    usable! mod if mod_ext.has_spec?
    mod_ext
  end

  # @description Directly include a module whose methods you want made available in +usable_config.available_methods+
  #   Gives the module a name when including so that it shows up properly in the list of ancestors
  def usable!(mod)
    mod_name = mod.name ? mod.name.split('::').last : "UsableMod#{Time.now.strftime('%s')}"
    const_name = "#{mod_name}Used"
    mod = mod.call if mod.respond_to? :call
    remove_const const_name if const_defined? const_name, false
    const_set const_name, mod
    usable_config.modules << mod
    send :include, mod
{'fraction_non_alphanumeric': 0.07320441988950276, 'fraction_numerical': 0.0, 'mean_word_length': 3.7896825396825395, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '3772837', 'n_tokens_mistral': 1091, 'n_tokens_neox': 1054, 'n_words': 408}