Class: ActiveFedora::RegisteredAttributes::AttributeRegistry
- Inherits:
-
HashWithIndifferentAccess
- Object
- HashWithIndifferentAccess
- ActiveFedora::RegisteredAttributes::AttributeRegistry
- Defined in:
- lib/active_fedora/registered_attributes/attribute_registry.rb
Instance Attribute Summary collapse
-
#context_class ⇒ Object
Returns the value of attribute context_class.
Instance Method Summary collapse
-
#attribute_defaults ⇒ Hash{String => Object}
Calculates the attribute defaults from the attribute definitions.
- #copy_to(target) ⇒ Object
- #displayable_attributes ⇒ Object
- #editable_attributes ⇒ Object
-
#initialize(context_class, initial_container = HashWithIndifferentAccess.new) ⇒ AttributeRegistry
constructor
A new instance of AttributeRegistry.
- #input_options_for(attribute_name, override_options = {}) ⇒ Object
- #label_for(name) ⇒ Object
- #register(attribute_name, options) {|attribute| ... } ⇒ Object
Constructor Details
#initialize(context_class, initial_container = HashWithIndifferentAccess.new) ⇒ AttributeRegistry
Returns a new instance of AttributeRegistry.
10 11 12 13 |
# File 'lib/active_fedora/registered_attributes/attribute_registry.rb', line 10 def initialize(context_class, initial_container = HashWithIndifferentAccess.new) @context_class = context_class super(initial_container) end |
Instance Attribute Details
#context_class ⇒ Object
Returns the value of attribute context_class.
9 10 11 |
# File 'lib/active_fedora/registered_attributes/attribute_registry.rb', line 9 def context_class @context_class end |
Instance Method Details
#attribute_defaults ⇒ Hash{String => Object}
Calculates the attribute defaults from the attribute definitions
41 42 43 |
# File 'lib/active_fedora/registered_attributes/attribute_registry.rb', line 41 def attribute_defaults collect { |name, attribute| [name, attribute.default(context_class)] } end |
#copy_to(target) ⇒ Object
15 16 17 |
# File 'lib/active_fedora/registered_attributes/attribute_registry.rb', line 15 def copy_to(target) self.class.new(target, __getobj__.dup) end |
#displayable_attributes ⇒ Object
32 33 34 35 36 |
# File 'lib/active_fedora/registered_attributes/attribute_registry.rb', line 32 def displayable_attributes @displayable_attributes ||= select_matching_attributes { |attribute| attribute.displayable? } end |
#editable_attributes ⇒ Object
26 27 28 29 30 |
# File 'lib/active_fedora/registered_attributes/attribute_registry.rb', line 26 def editable_attributes @editable_attributes ||= select_matching_attributes { |attribute| attribute.editable? } end |
#input_options_for(attribute_name, override_options = {}) ⇒ Object
45 46 47 48 49 |
# File 'lib/active_fedora/registered_attributes/attribute_registry.rb', line 45 def (attribute_name, = {}) fetch(attribute_name).() rescue KeyError end |
#label_for(name) ⇒ Object
51 52 53 54 55 |
# File 'lib/active_fedora/registered_attributes/attribute_registry.rb', line 51 def label_for(name) fetch(name).label rescue KeyError name.to_s.titleize end |
#register(attribute_name, options) {|attribute| ... } ⇒ Object
19 20 21 22 23 24 |
# File 'lib/active_fedora/registered_attributes/attribute_registry.rb', line 19 def register(attribute_name, ) attribute = Attribute.new(context_class, attribute_name, ) self[attribute.name] = attribute yield(attribute) if block_given? attribute end |