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
122 123 124 |
# File 'lib/active_fedora/attributes.rb', line 122 def association_attributes outgoing_reflections.values.map { |reflection| reflection.foreign_key.to_s } end |
#attribute_names ⇒ Object
102 103 104 |
# File 'lib/active_fedora/attributes.rb', line 102 def attribute_names @attribute_names ||= delegated_attributes.keys + association_attributes - system_attributes end |
#attributes_with_defaults ⇒ Object
From ActiveFedora::FedoraAttributes
117 118 119 |
# File 'lib/active_fedora/attributes.rb', line 117 def attributes_with_defaults ['type', 'rdf_label'] end |
#defined_attributes ⇒ Object
126 127 128 129 |
# File 'lib/active_fedora/attributes.rb', line 126 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
131 132 133 134 135 136 |
# File 'lib/active_fedora/attributes.rb', line 131 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
138 139 140 |
# File 'lib/active_fedora/attributes.rb', line 138 def delegated_attributes=(val) @delegated_attributes = val end |
#has_attributes(*fields, &block) ⇒ Object
142 143 144 145 146 147 148 149 |
# File 'lib/active_fedora/attributes.rb', line 142 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. Consider using the Form pattern to save all related models or directly delegate the properties and save the target separately" define_delegated_accessor(fields, delegate_target, , &block) end |
#local_attributes ⇒ Object
Attributes that are asserted about this RdfSource (not on a datastream)
107 108 109 |
# File 'lib/active_fedora/attributes.rb', line 107 def local_attributes association_attributes + properties.keys - system_attributes end |
#multiple?(field) ⇒ Boolean
Reveal if the attribute is multivalued
161 162 163 164 |
# File 'lib/active_fedora/attributes.rb', line 161 def multiple?(field) raise UnknownAttributeError.new(nil, field, self) unless delegated_attributes.key?(field) delegated_attributes[field].multiple end |
#property(name, properties = {}, &block) ⇒ Object
166 167 168 169 170 171 172 173 174 175 |
# File 'lib/active_fedora/attributes.rb', line 166 def property(name, properties = {}, &block) if properties.key?(:predicate) define_active_triple_accessor(name, properties, &block) elsif properties.key?(:delegate_to) Deprecation.warn Attributes, "delegated properties are deprecated and will be removed in ActiveFedora 10.0. Consider using the Form pattern to save all related models or directly delegate the properties and save the target separately" 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
112 113 114 |
# File 'lib/active_fedora/attributes.rb', line 112 def system_attributes ['has_model', 'create_date', 'modified_date'] end |
#unique?(field) ⇒ Boolean
Reveal if the attribute has been declared unique
154 155 156 |
# File 'lib/active_fedora/attributes.rb', line 154 def unique?(field) !multiple?(field) end |