class ActiveFedora::RegisteredAttributes::AttributeRegistry

Attributes

context_class[RW]

Public Class Methods

new(context_class, initial_container = HashWithIndifferentAccess.new) click to toggle source
Calls superclass method
# 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

Public Instance Methods

attribute_defaults() click to toggle source

Calculates the attribute defaults from the attribute definitions

@return [Hash{String => Object}] the attribute defaults

# 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) click to toggle source
# File lib/active_fedora/registered_attributes/attribute_registry.rb, line 15
def copy_to(target)
  self.class.new(target, __getobj__.dup)
end
displayable_attributes() click to toggle source
# 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() click to toggle source
# 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 = {}) click to toggle source
# File lib/active_fedora/registered_attributes/attribute_registry.rb, line 45
def input_options_for(attribute_name, override_options = {})
  fetch(attribute_name).options_for_input(override_options)
rescue KeyError
  override_options
end
label_for(name) click to toggle source
# 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| ... } click to toggle source
# File lib/active_fedora/registered_attributes/attribute_registry.rb, line 19
def register(attribute_name, options)
  attribute = Attribute.new(context_class, attribute_name, options)
  self[attribute.name] = attribute
  yield(attribute) if block_given?
  attribute
end

Private Instance Methods

select_matching_attributes() { |attribute| ... } click to toggle source
# File lib/active_fedora/registered_attributes/attribute_registry.rb, line 58
def select_matching_attributes
  each_with_object([]) do |(name, attribute),m|
    m << attribute if yield(attribute)
    m
  end
end