Class: ActiveFedora::RegisteredAttributes::AttributeRegistry

Inherits:
HashWithIndifferentAccess
  • Object
show all
Defined in:
lib/active_fedora/registered_attributes/attribute_registry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_classObject

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_defaultsHash{String => Object}

Calculates the attribute defaults from the attribute definitions

Returns:

  • (Hash{String => Object})

    the attribute defaults



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_attributesObject



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_attributesObject



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 input_options_for(attribute_name, override_options = {})
  fetch(attribute_name).options_for_input(override_options)
rescue KeyError
  override_options
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

Yields:

  • (attribute)


19
20
21
22
23
24
# 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