Module: SvgConform::Profiles
- Defined in:
- lib/svg_conform/profiles.rb
Constant Summary collapse
- PROFILES_DIR =
File.("../../config/profiles", __dir__)
- @@cache =
{}
Class Method Summary collapse
- .available_profiles ⇒ Object
- .clear_cache! ⇒ Object
- .get(profile_id) ⇒ Object
- .list ⇒ Object
- .load(profile_name) ⇒ Object
- .load_profile(profile_name) ⇒ Object
Class Method Details
.available_profiles ⇒ Object
21 22 23 24 25 26 |
# File 'lib/svg_conform/profiles.rb', line 21 def self.available_profiles return @@cache.keys.map(&:to_sym) if @@cache.any? profile_files = Dir.glob(File.join(PROFILES_DIR, "*.yml")) profile_files.map { |file| File.basename(file, ".yml").to_sym } end |
.clear_cache! ⇒ Object
36 37 38 |
# File 'lib/svg_conform/profiles.rb', line 36 def self.clear_cache! @@cache.clear end |
.get(profile_id) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/svg_conform/profiles.rb', line 10 def self.get(profile_id) case profile_id when Symbol, String load_profile(profile_id.to_s) when Profile profile_id else raise ProfileError, "Invalid profile: #{profile_id}" end end |
.list ⇒ Object
32 33 34 |
# File 'lib/svg_conform/profiles.rb', line 32 def self.list available_profiles.map(&:to_s) end |
.load(profile_name) ⇒ Object
28 29 30 |
# File 'lib/svg_conform/profiles.rb', line 28 def self.load(profile_name) load_profile(profile_name.to_s) end |
.load_profile(profile_name) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/svg_conform/profiles.rb', line 40 def self.load_profile(profile_name) return @@cache[profile_name] if @@cache[profile_name] profile_file = File.join(PROFILES_DIR, "#{profile_name}.yml") unless File.exist?(profile_file) raise ProfileError, "Profile not found: #{profile_name} (expected: #{profile_file})" end begin profile = Profile.load_from_file(profile_file) @@cache[profile_name] = profile profile # rescue => e # raise e # raise ProfileError, "Failed to load profile #{profile_name}: #{e.message}" end end |