Class: Synthra::Mixin::Registry
- Inherits:
-
Object
- Object
- Synthra::Mixin::Registry
- Defined in:
- lib/synthra/mixin.rb
Overview
Registry for storing mixins
Class Method Summary collapse
- .all ⇒ Object
- .clear ⇒ Object
- .exists?(name) ⇒ Boolean
- .get(name) ⇒ Object
- .instance ⇒ Object
- .register(name, fields:, behaviors: []) ⇒ Object
Instance Method Summary collapse
-
#all ⇒ Object
Get all mixins.
-
#clear ⇒ Object
Clear all mixins.
-
#exists?(name) ⇒ Boolean
Check if mixin exists.
-
#get(name) ⇒ Hash?
Get a mixin by name.
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
-
#register(name, fields:, behaviors: []) ⇒ Object
Register a mixin.
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
49 50 51 52 |
# File 'lib/synthra/mixin.rb', line 49 def initialize @mixins = {} @mutex = Mutex.new end |
Class Method Details
.all ⇒ Object
44 45 46 |
# File 'lib/synthra/mixin.rb', line 44 def all instance.all end |
.clear ⇒ Object
40 41 42 |
# File 'lib/synthra/mixin.rb', line 40 def clear instance.clear end |
.exists?(name) ⇒ Boolean
36 37 38 |
# File 'lib/synthra/mixin.rb', line 36 def exists?(name) instance.exists?(name) end |
.get(name) ⇒ Object
32 33 34 |
# File 'lib/synthra/mixin.rb', line 32 def get(name) instance.get(name) end |
.instance ⇒ Object
24 25 26 |
# File 'lib/synthra/mixin.rb', line 24 def instance @instance ||= new end |
.register(name, fields:, behaviors: []) ⇒ Object
28 29 30 |
# File 'lib/synthra/mixin.rb', line 28 def register(name, fields:, behaviors: []) instance.register(name, fields: fields, behaviors: behaviors) end |
Instance Method Details
#all ⇒ Object
Get all mixins
94 95 96 |
# File 'lib/synthra/mixin.rb', line 94 def all @mutex.synchronize { @mixins.dup } end |
#clear ⇒ Object
Clear all mixins
89 90 91 |
# File 'lib/synthra/mixin.rb', line 89 def clear @mutex.synchronize { @mixins.clear } end |
#exists?(name) ⇒ Boolean
Check if mixin exists
84 85 86 |
# File 'lib/synthra/mixin.rb', line 84 def exists?(name) @mutex.synchronize { @mixins.key?(name.to_s) } end |
#get(name) ⇒ Hash?
Get a mixin by name
75 76 77 |
# File 'lib/synthra/mixin.rb', line 75 def get(name) @mutex.synchronize { @mixins[name.to_s] } end |
#register(name, fields:, behaviors: []) ⇒ Object
Register a mixin
60 61 62 63 64 65 66 67 68 |
# File 'lib/synthra/mixin.rb', line 60 def register(name, fields:, behaviors: []) @mutex.synchronize do @mixins[name.to_s] = { name: name.to_s, fields: fields, behaviors: behaviors } end end |