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.
- #displayable_attributes ⇒ Object
- #editable_attributes ⇒ Object
-
#initialize(context_class) ⇒ 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) ⇒ AttributeRegistry
10 11 12 13 |
# File 'lib/active_fedora/registered_attributes/attribute_registry.rb', line 10 def initialize(context_class) @context_class = context_class super(HashWithIndifferentAccess.new) 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
39 40 41 |
# File 'lib/active_fedora/registered_attributes/attribute_registry.rb', line 39 def attribute_defaults collect { |name, attribute| [name, attribute.default(context_class)] } end |
#displayable_attributes ⇒ Object
29 30 31 32 33 34 |
# File 'lib/active_fedora/registered_attributes/attribute_registry.rb', line 29 def displayable_attributes @displayable_attributes ||= each_with_object([]) {|(name, attribute),m| m << attribute if attribute.displayable? m } end |
#editable_attributes ⇒ Object
22 23 24 25 26 27 |
# File 'lib/active_fedora/registered_attributes/attribute_registry.rb', line 22 def editable_attributes @editable_attributes ||= each_with_object([]) {|(name, attribute), m| m << attribute if attribute.editable? m } end |
#input_options_for(attribute_name, override_options = {}) ⇒ Object
43 44 45 46 47 |
# File 'lib/active_fedora/registered_attributes/attribute_registry.rb', line 43 def (attribute_name, = {}) fetch(attribute_name).() rescue KeyError end |
#label_for(name) ⇒ Object
49 50 51 52 53 |
# File 'lib/active_fedora/registered_attributes/attribute_registry.rb', line 49 def label_for(name) fetch(name).label rescue KeyError name.to_s.titleize end |
#register(attribute_name, options) {|attribute| ... } ⇒ Object
15 16 17 18 19 20 |
# File 'lib/active_fedora/registered_attributes/attribute_registry.rb', line 15 def register(attribute_name, ) attribute = Attribute.new(context_class, attribute_name, ) self[attribute.name] = attribute yield(attribute) if block_given? attribute end |