Module: ActiveFedora::Core::ClassMethods
- Defined in:
- lib/active_fedora/core.rb
Constant Summary collapse
- SLASH =
'/'.freeze
Instance Method Summary collapse
-
#from_uri(uri, _) ⇒ Object
Provides the common interface for ActiveTriples::Identifiable.
- #generated_association_methods ⇒ Object
-
#id_to_uri(id) ⇒ Object
Transforms an id into a uri if translate_id_to_uri is set it uses that proc, otherwise just the default.
-
#to_class_uri(attrs = {}) ⇒ Object
Returns a suitable uri object for :has_model Should reverse Model#from_class_uri TODO this is a poorly named method.
-
#uri_to_id(uri) ⇒ Object
Transforms a uri into an id if translate_uri_to_id is set it uses that proc, otherwise just the default.
Instance Method Details
#from_uri(uri, _) ⇒ Object
Provides the common interface for ActiveTriples::Identifiable
162 163 164 165 166 167 168 |
# File 'lib/active_fedora/core.rb', line 162 def from_uri(uri,_) begin self.find(uri_to_id(uri)) rescue ActiveFedora::ObjectNotFoundError, Ldp::Gone ActiveTriples::Resource.new(uri) end end |
#generated_association_methods ⇒ Object
118 119 120 121 122 123 124 |
# File 'lib/active_fedora/core.rb', line 118 def generated_association_methods @generated_association_methods ||= begin mod = const_set(:GeneratedAssociationMethods, Module.new) include mod mod end end |
#id_to_uri(id) ⇒ Object
Transforms an id into a uri if translate_id_to_uri is set it uses that proc, otherwise just the default
136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/active_fedora/core.rb', line 136 def id_to_uri(id) if translate_id_to_uri translate_id_to_uri.call(id) else id = "/#{id}" unless id.start_with? SLASH unless ActiveFedora.fedora.base_path == SLASH || id.start_with?("#{ActiveFedora.fedora.base_path}/") id = ActiveFedora.fedora.base_path + id end ActiveFedora.fedora.host + id end end |
#to_class_uri(attrs = {}) ⇒ Object
Returns a suitable uri object for :has_model Should reverse Model#from_class_uri TODO this is a poorly named method
129 130 131 |
# File 'lib/active_fedora/core.rb', line 129 def to_class_uri(attrs = {}) name end |
#uri_to_id(uri) ⇒ Object
Transforms a uri into an id if translate_uri_to_id is set it uses that proc, otherwise just the default
151 152 153 154 155 156 157 158 |
# File 'lib/active_fedora/core.rb', line 151 def uri_to_id(uri) if translate_uri_to_id translate_uri_to_id.call(uri) else id = uri.to_s.sub(ActiveFedora.fedora.host + ActiveFedora.fedora.base_path, '') id.start_with?('/') ? id[1..-1] : id end end |