Class: EditInPlace::Registrar
- Inherits:
-
Object
- Object
- EditInPlace::Registrar
- Defined in:
- lib/edit_in_place/registrar.rb
Overview
Direct Known Subclasses
Instance Method Summary collapse
-
#all ⇒ Hash<(Symbol, Object)>
Gets a hash of all registrations.
-
#dup ⇒ Registrar
Creates a deep copy of this Registrar that can be safely modified.
-
#find(name) ⇒ Object?
Attempts to find an object associated with the given symbol name.
-
#initialize ⇒ Registrar
constructor
Creates a new instance of Registrar.
-
#register(name, object) ⇒ void
Registers the given object with the given symbol name.
-
#register_all(objects) ⇒ void
Registers all the symbol names and objects in the given hash.
Constructor Details
#initialize ⇒ Registrar
Creates a new instance of EditInPlace::Registrar.
13 14 15 |
# File 'lib/edit_in_place/registrar.rb', line 13 def initialize @registrations = {} end |
Instance Method Details
#all ⇒ Hash<(Symbol, Object)>
Gets a hash of all registrations. Note that this hash is a deep clone of the actual, internal one and can be safely modified.
61 62 63 |
# File 'lib/edit_in_place/registrar.rb', line 61 def all registrations.deep_dup end |
#dup ⇒ Registrar
Creates a deep copy of this EditInPlace::Registrar that can be safely modified.
19 20 21 22 23 |
# File 'lib/edit_in_place/registrar.rb', line 19 def dup r = Registrar.new r.register_all(all) r end |
#find(name) ⇒ Object?
Attempts to find an object associated with the given symbol name.
54 55 56 |
# File 'lib/edit_in_place/registrar.rb', line 54 def find(name) registrations[name] end |
#register(name, object) ⇒ void
This method returns an undefined value.
Registers the given object with the given symbol name.
30 31 32 33 |
# File 'lib/edit_in_place/registrar.rb', line 30 def register(name, object) validate_registration!(name, object) registrations[name] = object end |
#register_all(objects) ⇒ void
This method returns an undefined value.
Registers all the symbol names and objects in the given hash. All elements of the hash are passed through #register.
40 41 42 43 44 45 46 47 48 |
# File 'lib/edit_in_place/registrar.rb', line 40 def register_all(objects) # The identical loops are necessary to prevent anyything from being registered if even one # fails the validation. # rubocop:disable Style/CombinableLoops objects.each { |n, t| validate_registration!(n, t) } objects.each { |n, t| register(n, t) } # rubocop:enable Style/CombinableLoops end |