lib/usps_flags.rb in usps_flags-0.5.1 vs lib/usps_flags.rb in usps_flags-0.5.2
- old
+ new
@@ -3,77 +3,25 @@
# Main module for the namespace.
#
# @author Julian Fiander
# @since 0.1.5
class USPSFlags
- MODULES ||= {
- 'usps_flags' => %w[rational config helpers core generate errors],
- 'usps_flags/helpers' => %w[builders spec_arrows],
- 'usps_flags/core' => %w[
- icons ensign field footer headers pennant tridents trident_specs trident_spec us wheel
- ],
- 'usps_flags/generate' => %w[flag]
- }.freeze
-
require 'fileutils'
require 'zip'
require 'mini_magick'
+ require 'yaml'
+ MODULES ||= ::YAML.safe_load(File.read('lib/modules.yml')).freeze
+
MODULES.each do |parent, bases|
bases.each do |base|
res = require("#{parent}/#{base}")
puts "#{parent}/#{base}: #{res}" if ENV['VERBOSE_REQUIRE'] == 'true'
end
end
- # Configuration accessor.
- def self.configuration
- @configuration ||= USPSFlags::Config.new
- end
-
- # Configuration constructor.
- def self.configure
- yield(configuration) if block_given?
- ensure_directories
- @configuration
- end
-
- # Ensures the directory structure exists.
- #
- # @private
- def self.ensure_directories
- get_dir_configs
- prepare_dir_configs
- prepare_flags_dir
- ::FileUtils.mkdir_p(USPSFlags.configuration.log_path)
- end
-
- # Gets all configuration variables that specify a dir.
- #
- # @private
- def self.get_dir_configs
- @dirs = USPSFlags.configuration.instance_variables.map(&:to_s)
- .map { |v| v.match(/.*?_dir/) }.compact.map(&:to_s)
- end
-
- # Ensures that directories exist (and are cleared, if configured).
- #
- # @private
- def self.prepare_dir_configs
- @dirs.each do |dir|
- dir_path = @configuration.instance_variable_get(dir)
- ::FileUtils.rm_rf(dir_path) if @configuration.clear
- ::FileUtils.mkdir_p(dir_path)
- end
- end
-
- # Ensures that the flags_dir subdirectories exist.
- #
- # @private
- def self.prepare_flags_dir
- ::FileUtils.mkdir_p("#{@configuration.flags_dir}/PNG/insignia")
- ::FileUtils.mkdir_p("#{@configuration.flags_dir}/SVG/insignia")
- ::FileUtils.mkdir_p("#{@configuration.flags_dir}/ZIP")
+ class << self
+ include USPSFlags::Configuration
end
# Constructor for individual flags.
#
# @example Generate insignia at default scale for Lt/C