module FedoraLens::Core::ClassMethods
Public Instance Methods
create(data)
click to toggle source
# File lib/fedora_lens/core.rb, line 189 def create(data) model = self.new(data) model.save model end
find(id)
click to toggle source
# File lib/fedora_lens/core.rb, line 172 def find(id) resource = Ldp::Resource::RdfSource.new(FedoraLens.connection, id_to_uri(id)) raise Ldp::NotFound if resource.new? self.new(resource) end
id_to_uri(id)
click to toggle source
# File lib/fedora_lens/core.rb, line 178 def id_to_uri(id) id = "/#{id}" unless id.start_with? '/' id = FedoraLens.base_path + id unless id.start_with? "#{FedoraLens.base_path}/" FedoraLens.host + id end
orm_to_hash()
click to toggle source
# File lib/fedora_lens/core.rb, line 195 def orm_to_hash if @orm_to_hash.nil? aggregate_lens = attributes_as_lenses.inject({}) do |acc, (name, path)| lens = path.inject {|outer, inner| Lenses.compose(outer, inner)} acc.merge(name => lens) end @orm_to_hash = Lenses.orm_to_hash(aggregate_lens) end @orm_to_hash end
uri_to_id(uri)
click to toggle source
# File lib/fedora_lens/core.rb, line 184 def uri_to_id(uri) id = uri.to_s.sub(FedoraLens.host + FedoraLens.base_path, '') id.start_with?('/') ? id[1..-1] : id end