Class: Omnizip::Profile::ProfileRegistry
- Inherits:
-
Object
- Object
- Omnizip::Profile::ProfileRegistry
- Defined in:
- lib/omnizip/profile/profile_registry.rb
Overview
Thread-safe registry for compression profiles
This class manages both built-in and custom compression profiles, providing a central location for profile registration, lookup, and management.
Instance Method Summary collapse
-
#all ⇒ Array<CompressionProfile>
Get all registered profiles.
-
#clear ⇒ void
Clear all registered profiles.
-
#count ⇒ Integer
Get the number of registered profiles.
-
#each {|profile| ... } ⇒ void
Iterate over all profiles.
-
#get(name) ⇒ CompressionProfile?
Get a profile by name.
-
#initialize ⇒ ProfileRegistry
constructor
Initialize a new profile registry.
-
#inspect ⇒ String
String representation.
-
#names ⇒ Array<Symbol>
Get all registered profile names.
-
#register(profile) ⇒ CompressionProfile
Register a profile.
-
#register!(profile) ⇒ CompressionProfile
Register a profile, replacing if it exists.
-
#registered?(name) ⇒ Boolean
Check if a profile is registered.
-
#suitable_for(mime_type) ⇒ Array<CompressionProfile>
Find profiles suitable for a MIME type.
-
#to_h ⇒ Hash{Symbol => Hash}
Get profile information as hash.
-
#unregister(name) ⇒ CompressionProfile?
Unregister a profile by name.
Constructor Details
#initialize ⇒ ProfileRegistry
Initialize a new profile registry
12 13 14 15 |
# File 'lib/omnizip/profile/profile_registry.rb', line 12 def initialize @profiles = {} @mutex = Mutex.new end |
Instance Method Details
#all ⇒ Array<CompressionProfile>
Get all registered profiles
99 100 101 102 103 |
# File 'lib/omnizip/profile/profile_registry.rb', line 99 def all @mutex.synchronize do @profiles.values end end |
#clear ⇒ void
This method returns an undefined value.
Clear all registered profiles
116 117 118 119 120 |
# File 'lib/omnizip/profile/profile_registry.rb', line 116 def clear @mutex.synchronize do @profiles.clear end end |
#count ⇒ Integer
Get the number of registered profiles
125 126 127 128 129 |
# File 'lib/omnizip/profile/profile_registry.rb', line 125 def count @mutex.synchronize do @profiles.size end end |
#each {|profile| ... } ⇒ void
This method returns an undefined value.
Iterate over all profiles
rubocop:disable Naming/BlockForwarding, Style/ArgumentsForwarding -- Ruby 3.0 compatibility
137 138 139 |
# File 'lib/omnizip/profile/profile_registry.rb', line 137 def each(&block) all.each(&block) end |
#get(name) ⇒ CompressionProfile?
Get a profile by name
71 72 73 74 75 |
# File 'lib/omnizip/profile/profile_registry.rb', line 71 def get(name) @mutex.synchronize do @profiles[name] end end |
#inspect ⇒ String
String representation
154 155 156 157 158 |
# File 'lib/omnizip/profile/profile_registry.rb', line 154 def inspect @mutex.synchronize do "#<#{self.class.name} profiles=#{@profiles.keys.join(', ')}>" end end |
#names ⇒ Array<Symbol>
Get all registered profile names
90 91 92 93 94 |
# File 'lib/omnizip/profile/profile_registry.rb', line 90 def names @mutex.synchronize do @profiles.keys end end |
#register(profile) ⇒ CompressionProfile
Register a profile
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/omnizip/profile/profile_registry.rb', line 22 def register(profile) unless profile.is_a?(CompressionProfile) raise ArgumentError, "Profile must be a CompressionProfile instance" end @mutex.synchronize do if @profiles.key?(profile.name) raise ArgumentError, "Profile '#{profile.name}' is already registered" end @profiles[profile.name] = profile end profile end |
#register!(profile) ⇒ CompressionProfile
Register a profile, replacing if it exists
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/omnizip/profile/profile_registry.rb', line 44 def register!(profile) unless profile.is_a?(CompressionProfile) raise ArgumentError, "Profile must be a CompressionProfile instance" end @mutex.synchronize do @profiles[profile.name] = profile end profile end |
#registered?(name) ⇒ Boolean
Check if a profile is registered
81 82 83 84 85 |
# File 'lib/omnizip/profile/profile_registry.rb', line 81 def registered?(name) @mutex.synchronize do @profiles.key?(name) end end |
#suitable_for(mime_type) ⇒ Array<CompressionProfile>
Find profiles suitable for a MIME type
109 110 111 |
# File 'lib/omnizip/profile/profile_registry.rb', line 109 def suitable_for(mime_type) all.select { |profile| profile.suitable_for?(mime_type) } end |
#to_h ⇒ Hash{Symbol => Hash}
Get profile information as hash
145 146 147 148 149 |
# File 'lib/omnizip/profile/profile_registry.rb', line 145 def to_h @mutex.synchronize do @profiles.transform_values(&:to_h) end end |
#unregister(name) ⇒ CompressionProfile?
Unregister a profile by name
61 62 63 64 65 |
# File 'lib/omnizip/profile/profile_registry.rb', line 61 def unregister(name) @mutex.synchronize do @profiles.delete(name) end end |