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) ⇒ 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_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



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_attributesObject



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_attributesObject



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

Yields:

  • (attribute)


15
16
17
18
19
20
# File 'lib/active_fedora/registered_attributes/attribute_registry.rb', line 15

def register(attribute_name, options)
  attribute = Attribute.new(context_class, attribute_name, options)
  self[attribute.name] = attribute
  yield(attribute) if block_given?
  attribute
end