Class: BBortcodes::Registry
- Inherits:
-
Object
- Object
- BBortcodes::Registry
- Includes:
- MonitorMixin
- Defined in:
- lib/bbortcodes/registry.rb
Instance Method Summary collapse
-
#all ⇒ Hash
Get all registered shortcode classes.
-
#clear ⇒ Object
Clear all registered shortcodes.
-
#count ⇒ Integer
Get the count of registered shortcodes.
-
#find(tag_name) ⇒ Class?
Find a shortcode class by tag name.
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
-
#register(shortcode_class) ⇒ Object
Register a shortcode class.
-
#registered?(tag_name) ⇒ Boolean
Check if a shortcode is registered.
-
#tag_names ⇒ Array<String>
Get all registered tag names.
-
#unregister(tag_name) ⇒ Object
Unregister a shortcode.
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
9 10 11 12 |
# File 'lib/bbortcodes/registry.rb', line 9 def initialize super @shortcodes = {} end |
Instance Method Details
#all ⇒ Hash
Get all registered shortcode classes
58 59 60 61 62 |
# File 'lib/bbortcodes/registry.rb', line 58 def all synchronize do @shortcodes.dup end end |
#clear ⇒ Object
Clear all registered shortcodes
81 82 83 84 85 |
# File 'lib/bbortcodes/registry.rb', line 81 def clear synchronize do @shortcodes.clear end end |
#count ⇒ Integer
Get the count of registered shortcodes
89 90 91 92 93 |
# File 'lib/bbortcodes/registry.rb', line 89 def count synchronize do @shortcodes.size end end |
#find(tag_name) ⇒ Class?
Find a shortcode class by tag name
41 42 43 44 45 |
# File 'lib/bbortcodes/registry.rb', line 41 def find(tag_name) synchronize do @shortcodes[tag_name.to_s] end end |
#register(shortcode_class) ⇒ Object
Register a shortcode class
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/bbortcodes/registry.rb', line 16 def register(shortcode_class) synchronize do unless shortcode_class < Shortcode raise RegistryError, "#{shortcode_class} must inherit from BBortcodes::Shortcode" end tag_name = shortcode_class.tag_name if @shortcodes.key?(tag_name) if BBortcodes.config.allow_shortcode_overwrite @shortcodes.delete(tag_name) else raise RegistryError, "Shortcode '#{tag_name}' is already registered by #{@shortcodes[tag_name].name}. " \ "Set allow_shortcode_overwrite: true in config to override, or call unregister('#{tag_name}') first." end end @shortcodes[tag_name] = shortcode_class end end |
#registered?(tag_name) ⇒ Boolean
Check if a shortcode is registered
50 51 52 53 54 |
# File 'lib/bbortcodes/registry.rb', line 50 def registered?(tag_name) synchronize do @shortcodes.key?(tag_name.to_s) end end |
#tag_names ⇒ Array<String>
Get all registered tag names
66 67 68 69 70 |
# File 'lib/bbortcodes/registry.rb', line 66 def tag_names synchronize do @shortcodes.keys end end |
#unregister(tag_name) ⇒ Object
Unregister a shortcode
74 75 76 77 78 |
# File 'lib/bbortcodes/registry.rb', line 74 def unregister(tag_name) synchronize do @shortcodes.delete(tag_name.to_s) end end |