Module: FedoraLens::ClassMethods

Defined in:
lib/fedora_lens.rb

Instance Method Summary collapse

Instance Method Details

#create(data) ⇒ Object



200
201
202
203
204
# File 'lib/fedora_lens.rb', line 200

def create(data)
  model = self.new(data)
  model.save
  model
end

#find(id) ⇒ Object

Raises:

  • (Ldp::NotFound)


186
187
188
189
190
# File 'lib/fedora_lens.rb', line 186

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) ⇒ Object



192
193
194
# File 'lib/fedora_lens.rb', line 192

def id_to_uri(id)
  FedoraLens.id_to_uri(id)
end

#orm_to_hashObject



206
207
208
209
210
211
212
213
214
215
# File 'lib/fedora_lens.rb', line 206

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) ⇒ Object



196
197
198
# File 'lib/fedora_lens.rb', line 196

def uri_to_id(uri)
  FedoraLens.uri_to_id(uri)
end