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
- #defined_attributes ⇒ Object
- #delegated_attributes ⇒ Object
- #delegated_attributes=(val) ⇒ Object
- #has_attributes(*fields) ⇒ 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
127 128 129 |
# File 'lib/active_fedora/attributes.rb', line 127 def association_attributes outgoing_reflections.values.map { |reflection| reflection.foreign_key.to_s } end |
#attribute_names ⇒ Object
112 113 114 |
# File 'lib/active_fedora/attributes.rb', line 112 def attribute_names @attribute_names ||= delegated_attributes.keys + association_attributes - system_attributes end |
#defined_attributes ⇒ Object
131 132 133 134 |
# File 'lib/active_fedora/attributes.rb', line 131 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
136 137 138 139 140 141 |
# File 'lib/active_fedora/attributes.rb', line 136 def delegated_attributes @delegated_attributes ||= {}.with_indifferent_access return @delegated_attributes unless superclass.respond_to?(:delegated_attributes) and value = superclass.delegated_attributes @delegated_attributes = value.dup if @delegated_attributes.empty? @delegated_attributes end |
#delegated_attributes=(val) ⇒ Object
143 144 145 |
# File 'lib/active_fedora/attributes.rb', line 143 def delegated_attributes= val @delegated_attributes = val end |
#has_attributes(*fields) ⇒ Object
147 148 149 150 151 152 153 154 155 156 |
# File 'lib/active_fedora/attributes.rb', line 147 def has_attributes(*fields) = fields.pop datastream = .delete(:datastream).to_s raise ArgumentError, "You must provide a datastream to has_attributes" if datastream.blank? define_attribute_methods fields fields.each do |f| create_attribute_reader(f, datastream, ) create_attribute_setter(f, datastream, ) end end |
#local_attributes ⇒ Object
Attributes that are asserted about this RdfSource (not on a datastream)
117 118 119 |
# File 'lib/active_fedora/attributes.rb', line 117 def local_attributes association_attributes + properties.keys - system_attributes end |
#multiple?(field) ⇒ Boolean
Reveal if the attribute is multivalued
168 169 170 171 |
# File 'lib/active_fedora/attributes.rb', line 168 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
173 174 175 176 177 178 179 180 |
# File 'lib/active_fedora/attributes.rb', line 173 def property name, properties={}, &block warn_duplicate_predicates name, properties properties = { multiple: true }.merge(properties) find_or_create_defined_attribute(name, nil, properties) raise ArgumentError, "#{name} is a keyword and not an acceptable property name." if protected_property_name? name reflection = ActiveFedora::Attributes::PropertyBuilder.build(self, name, properties, &block) ActiveTriples::Reflection.add_reflection self, name, reflection end |
#system_attributes ⇒ Object
Attributes that are required by ActiveFedora and Fedora
122 123 124 |
# File 'lib/active_fedora/attributes.rb', line 122 def system_attributes ['has_model', 'create_date', 'modified_date'] end |
#unique?(field) ⇒ Boolean
Reveal if the attribute has been declared unique
161 162 163 |
# File 'lib/active_fedora/attributes.rb', line 161 def unique?(field) !multiple?(field) end |