Skip to content
Snippets Groups Projects
Commit 2d0a197e authored by Mateus Rambo Strey's avatar Mateus Rambo Strey
Browse files

add generic builder

parent 96c0f0d3
No related branches found
No related tags found
No related merge requests found
class AttributeBuilder < Builder class AttributeBuilder < Builder
extend RepositoriesProxy
## ##
# receive a list of ids and return a list of attributes # receive a list of ids and return a list of attributes
# #
......
class Builder class Builder
extend RepositoriesProxy
protected protected
......
class CollectionBuilder < Builder class CollectionBuilder < Builder
extend RepositoriesProxy
## ##
# Receive a list of ids and return a list of collections # Receive a list of ids and return a list of collections
# Each element, must be a Hash with rid and last_modified # Each element, must be a Hash with rid and last_modified
......
class ComplaintBuilder < Builder class ComplaintBuilder < Builder
extend RepositoriesProxy
## ##
# receive a list of ids and return a list of complaints # receive a list of ids and return a list of complaints
# #
......
class GenericBuilder < Builder
##
# receive a list of ids and return a list of learning objects
# useful for search pagination
#
def self.build(objects = [])
build_array(objects, true, 'rid')
end
private
def self.build_array(objects = [], cache = true, id = '@rid', last_modified = 'last_modified')
array = []
objects = [objects] if objects.class == String || objects.class == Hash
objects.each do |object|
next if object[id].blank?
if cache && !object[last_modified].blank?
o = Rails.cache.fetch(cache_key(object[id], object[last_modified]))
end
o = repository(object['@class']).find object[id] if o.nil?
array << o
end
array
end
def repository(klass)
case klass
when 'Attribute' then attribute_repository
when 'Collection' then collection_repository
when 'Complaint' then complaint_repository
when 'Institution' then institution_repository
when 'LearningObject' then learning_object_repository
when 'Subject' then subject_repository
else nil
end
end
end
class InstitutionBuilder < Builder class InstitutionBuilder < Builder
extend RepositoriesProxy
## ##
# receive a list of ids and return a list of institutions # receive a list of ids and return a list of institutions
# #
......
class LearningObjectBuilder < Builder class LearningObjectBuilder < Builder
extend RepositoriesProxy
## ##
# receive a list of ids and return a list of learning objects # receive a list of ids and return a list of learning objects
# useful for search pagination # useful for search pagination
......
class SubjectBuilder < Builder class SubjectBuilder < Builder
extend RepositoriesProxy
## ##
# receive a list of ids and return a list of subjects # receive a list of ids and return a list of subjects
# #
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment