From 7f6e4abb1f9d7b6a7faf80d34e54662cae55dd80 Mon Sep 17 00:00:00 2001 From: Mauricio Giacomini Girardello <mgg12@inf.ufpr.br> Date: Mon, 18 Jan 2016 11:38:02 -0200 Subject: [PATCH] creating attachment builder --- .../learning_object/attachment_builder.rb | 30 +++++++++++++++++++ app/models/learning_object/attachment.rb | 2 ++ 2 files changed, 32 insertions(+) create mode 100644 app/builders/learning_object/attachment_builder.rb diff --git a/app/builders/learning_object/attachment_builder.rb b/app/builders/learning_object/attachment_builder.rb new file mode 100644 index 00000000..3f6421ee --- /dev/null +++ b/app/builders/learning_object/attachment_builder.rb @@ -0,0 +1,30 @@ +module LearningObject + class AttachmentBuilder < ::Builder + + ##disable method + # build attachments with id's is out of scope. + def self.build(objects = []) + raise NotImplementedError, 'LearningObject::AttachmentBuilder#build is out of scope.' + end + + def self.build_from_orientdb(args = {}) + build_from_cache args do + ::LearningObject::Attachment.new(args) + end + end + + private + + def self.build_from_cache(args={}) + object = nil + + unless args.nil? || !block_given? + # cache object when build + object = Rails.cache.fetch(cache_key(args['id'], args['link']), expires_in: 12.hours) { yield } + end + + object + end + + end +end \ No newline at end of file diff --git a/app/models/learning_object/attachment.rb b/app/models/learning_object/attachment.rb index a40cb335..1aff7410 100644 --- a/app/models/learning_object/attachment.rb +++ b/app/models/learning_object/attachment.rb @@ -1,4 +1,6 @@ class LearningObject::Attachment include ActiveModel::Model + + #this attributes mirror Dspace bitstream values attr_accessor :id, :name, :link, :retrieve_link, :description, :format, :mime_type, :size end -- GitLab