Module: FedoraLens::Core::ClassMethods
- Defined in:
- lib/fedora_lens/core.rb
Instance Method Summary collapse
- #create(data) ⇒ Object
- #find(id) ⇒ Object
- #id_to_uri(id) ⇒ Object
- #orm_to_hash ⇒ Object
- #uri_to_id(uri) ⇒ Object
Instance Method Details
#create(data) ⇒ Object
195 196 197 198 199 |
# File 'lib/fedora_lens/core.rb', line 195 def create(data) model = self.new(data) model.save model end |
#find(id) ⇒ Object
181 182 183 184 185 |
# File 'lib/fedora_lens/core.rb', line 181 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
187 188 189 |
# File 'lib/fedora_lens/core.rb', line 187 def id_to_uri(id) FedoraLens.id_to_uri(id) end |
#orm_to_hash ⇒ Object
201 202 203 204 205 206 207 208 209 210 |
# File 'lib/fedora_lens/core.rb', line 201 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
191 192 193 |
# File 'lib/fedora_lens/core.rb', line 191 def uri_to_id(uri) FedoraLens.uri_to_id(uri) end |