Class: Trestle::Registry
- Inherits:
-
Object
- Object
- Trestle::Registry
- Includes:
- Enumerable
- Defined in:
- lib/trestle/registry.rb
Instance Attribute Summary collapse
-
#admins ⇒ Object
readonly
The admins hash is left exposed for backwards compatibility.
Instance Method Summary collapse
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
- #lookup_admin(admin) ⇒ Object (also: #lookup)
- #lookup_model(model) ⇒ Object
- #register(admin, register_model: true) ⇒ Object
- #reset! ⇒ Object
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
8 9 10 |
# File 'lib/trestle/registry.rb', line 8 def initialize reset! end |
Instance Attribute Details
#admins ⇒ Object (readonly)
The admins hash is left exposed for backwards compatibility
6 7 8 |
# File 'lib/trestle/registry.rb', line 6 def admins @admins end |
Instance Method Details
#each(&block) ⇒ Object
12 13 14 |
# File 'lib/trestle/registry.rb', line 12 def each(&block) @admins.values.sort_by(&:admin_name).each(&block) end |
#empty? ⇒ Boolean
21 22 23 |
# File 'lib/trestle/registry.rb', line 21 def empty? none? end |
#lookup_admin(admin) ⇒ Object Also known as: lookup
35 36 37 38 39 40 |
# File 'lib/trestle/registry.rb', line 35 def lookup_admin(admin) # Given object is already an admin class return admin if admin.is_a?(Class) && admin < Trestle::Admin @admins[admin.to_s] end |
#lookup_model(model) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/trestle/registry.rb', line 43 def lookup_model(model) # Lookup each class in the model's ancestor chain while model admin = @models[model.name] return admin if admin model = model.superclass end # No admin found nil end |
#register(admin, register_model: true) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/trestle/registry.rb', line 25 def register(admin, register_model: true) @admins[admin.admin_name] = admin if register_model && register_admin_for_model_loookup?(admin) @models[admin.model.name] ||= admin end admin end |
#reset! ⇒ Object
16 17 18 19 |
# File 'lib/trestle/registry.rb', line 16 def reset! @admins = {} @models = {} end |