lib/ruby-rails-extensions.rb in ruby-rails-extensions-0.1.0 vs lib/ruby-rails-extensions.rb in ruby-rails-extensions-0.2.0.pre.rc.1
- old
+ new
@@ -1,42 +1,21 @@
# frozen_string_literal: true
-module RubyRailsExtensions
- # @return [CONFIGURATION]
- def self.configuration
- @configuration ||= CONFIGURATION.new
- end
+require_relative 'ruby-rails-extensions/errors'
- # @yield [Configuration]
- def self.configure
- yield(configuration)
-
- gem_list.each do |gem_base|
- next unless configuration.public_send("#{flag_name(gem_base)}?")
-
- require_relative("ruby-rails-extensions/extensions/#{gem_base}")
- end
- end
-
- # @return [Array<Symbol>]
- def configuration_flags
- CONFIGURATION.members
- end
-
- module_function :configuration_flags
-
- private
-
- # @return [Symbol] the flag name
- def flag_name(gem_base)
- :"include_#{gem_base}"
- end
-
- module_function :flag_name
-
+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
@@ -44,48 +23,107 @@
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
- # @return [Array<Symbol>] the list of gems
- def gem_list
- BOOLEAN_GEMS
+ attr_accessor :default_time_zone
+
+ # @return [Symbol] the flag name
+ def self.flag_name(gem_base)
+ :"include_#{gem_base}"
end
- module_function :gem_list
+ BOOLEAN_GEMS.each do |extension_name|
+ include_extension = flag_name(extension_name)
- CONFIGURATION = Struct.new(*gem_list.map { |gem| flag_name(gem) }) do
- members.each do |gem_member|
- define_method(:"#{gem_member}?") do
- public_send(gem_member) != false
- end
+ 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
+ # Sets all flags to true by default
+ def initialize
+ super
- members.each do |gem_member|
- public_send("#{gem_member}=", true)
- end
+ BOOLEAN_GEMS.each do |extension_name|
+ include_extension = flag_name(extension_name)
+
+ public_send("#{include_extension}=", true)
end
end
+
+ # @return [Array<Symbol>]
+ 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<Symbol>]
+ def configuration_flags
+ configuration.flags
+ end
+
+ module_function :configuration_flags
end