# frozen_string_literal: true require_relative 'ruby-rails-extensions/errors' module RubyRailsExtensions class Configuration BOOLEAN_GEMS = %i[ all_keys all_values any_key any_value assign_nil boolean_scope clean_string compact_map compact_blank_join current_day current_month current_week day_of_week display_military display_user find_bang find_dupes first_dupe google_format hash_only humanize_symbol in_utc input month_and_year month_year no_keys no_values only_some overlaps pipe presence_bang quarter_dates range_add range_multiply remove_reserved_keywords safe_parse select_present select_present_join set_to_sentence to_bool to_dec to_i to_local to_negative_i to_nonzero_i to_or_sentence to_positive_i to_sort_i to_x todays_date uniq_map usd_to_f usd_to_i weighted_sum yesno zero_range ].freeze attr_accessor :default_time_zone # @return [Symbol] the flag name def self.flag_name(gem_base) :"include_#{gem_base}" end BOOLEAN_GEMS.each do |extension_name| include_extension = flag_name(extension_name) attr_accessor include_extension define_method(:"#{extension_name}?") do public_send(include_extension) != false end end # Sets all flags to true by default def initialize super BOOLEAN_GEMS.each do |extension_name| include_extension = flag_name(extension_name) public_send("#{include_extension}=", true) end end # @return [Array] def flags BOOLEAN_GEMS.map { |f| flag_name(f) } end private # @return [Symbol] the flag name def flag_name(gem_base) self.class.flag_name(gem_base) end end # @return [Configuration] def self.configuration @configuration ||= Configuration.new end # @yield [Configuration] def self.configure yield(configuration) Configuration::BOOLEAN_GEMS.each do |extension| next unless configuration.public_send("#{extension}?") require_relative("ruby-rails-extensions/extensions/#{extension}") end end # @return [Array] def configuration_flags configuration.flags end module_function :configuration_flags end