Module: ActiveFedora::Attributes::ClassMethods
- Defined in:
- lib/active_fedora/attributes.rb
Instance Method Summary collapse
-
#association_attributes ⇒ Object
Attributes that represent associations to other repository objects.
- #attribute_names ⇒ Object
-
#attributes_with_defaults ⇒ Object
From ActiveFedora::FedoraAttributes.
- #defined_attributes ⇒ Object
- #delegated_attributes ⇒ Object
- #delegated_attributes=(val) ⇒ Object
- #has_attributes(*fields, &block) ⇒ Object
-
#local_attributes ⇒ Object
Attributes that are asserted about this RdfSource (not on a datastream).
-
#multiple?(field) ⇒ Boolean
Reveal if the attribute is multivalued.
- #property(name, properties = {}, &block) ⇒ Object
-
#system_attributes ⇒ Object
Attributes that are required by ActiveFedora and Fedora.
-
#unique?(field) ⇒ Boolean
Reveal if the attribute has been declared unique.
Instance Method Details
#association_attributes ⇒ Object
Attributes that represent associations to other repository objects
135 136 137 |
# File 'lib/active_fedora/attributes.rb', line 135 def association_attributes outgoing_reflections.values.map { |reflection| reflection.foreign_key.to_s } end |
#attribute_names ⇒ Object
115 116 117 |
# File 'lib/active_fedora/attributes.rb', line 115 def attribute_names @attribute_names ||= delegated_attributes.keys + association_attributes - system_attributes end |
#attributes_with_defaults ⇒ Object
From ActiveFedora::FedoraAttributes
130 131 132 |
# File 'lib/active_fedora/attributes.rb', line 130 def attributes_with_defaults ['type', 'rdf_label'] end |
#defined_attributes ⇒ Object
139 140 141 142 |
# File 'lib/active_fedora/attributes.rb', line 139 def defined_attributes Deprecation.warn Attributes, "defined_attributes has been renamed to delegated_attributes. defined_attributes will be removed in ActiveFedora 9" delegated_attributes end |
#delegated_attributes ⇒ Object
144 145 146 147 148 149 |
# File 'lib/active_fedora/attributes.rb', line 144 def delegated_attributes @delegated_attributes ||= {}.with_indifferent_access return @delegated_attributes unless superclass.respond_to?(:delegated_attributes) && value = superclass.delegated_attributes @delegated_attributes = value.dup if @delegated_attributes.empty? @delegated_attributes end |
#delegated_attributes=(val) ⇒ Object
151 152 153 |
# File 'lib/active_fedora/attributes.rb', line 151 def delegated_attributes=(val) @delegated_attributes = val end |
#has_attributes(*fields, &block) ⇒ Object
155 156 157 158 159 160 161 162 |
# File 'lib/active_fedora/attributes.rb', line 155 def has_attributes(*fields, &block) = fields.pop delegate_target = .delete(:datastream) raise ArgumentError, "You must provide a datastream to has_attributes" if delegate_target.blank? Deprecation.warn(Attributes, "has_attributes is deprecated and will be removed in ActiveFedora 10.0. Instead use:\n property #{fields.first.inspect}, delegate_to: '#{delegate_target}', ...") define_delegated_accessor(fields, delegate_target, , &block) end |
#local_attributes ⇒ Object
Attributes that are asserted about this RdfSource (not on a datastream)
120 121 122 |
# File 'lib/active_fedora/attributes.rb', line 120 def local_attributes association_attributes + properties.keys - system_attributes end |
#multiple?(field) ⇒ Boolean
Reveal if the attribute is multivalued
174 175 176 177 |
# File 'lib/active_fedora/attributes.rb', line 174 def multiple?(field) raise UnknownAttributeError, "#{self} does not have an attribute `#{field}'" unless delegated_attributes.key?(field) delegated_attributes[field].multiple end |
#property(name, properties = {}, &block) ⇒ Object
179 180 181 182 183 184 185 186 187 |
# File 'lib/active_fedora/attributes.rb', line 179 def property(name, properties = {}, &block) if properties.key?(:predicate) define_active_triple_accessor(name, properties, &block) elsif properties.key?(:delegate_to) define_delegated_accessor([name], properties.delete(:delegate_to), properties.reverse_merge(multiple: true), &block) else raise "You must provide `:delegate_to' or `:predicate' options to property" end end |
#system_attributes ⇒ Object
Attributes that are required by ActiveFedora and Fedora
125 126 127 |
# File 'lib/active_fedora/attributes.rb', line 125 def system_attributes ['has_model', 'create_date', 'modified_date'] end |
#unique?(field) ⇒ Boolean
Reveal if the attribute has been declared unique
167 168 169 |
# File 'lib/active_fedora/attributes.rb', line 167 def unique?(field) !multiple?(field) end |