Skip to content
Snippets Groups Projects
Commit e8fd2af5 authored by Mauricio Giacomini Girardello's avatar Mauricio Giacomini Girardello
Browse files

adding new verifications for bookmarks and has_bookmarks? methods

parent 4dc92b22
No related branches found
No related tags found
No related merge requests found
......@@ -6,7 +6,7 @@ class Collection
validates_presence_of :name, :created_at, :owner, :learning_objects
validates_with Validators::CollectionOwnerValidator
def initialize(params={})
def initialize(params = {})
super(params.merge(defaults))
end
......
......@@ -3,8 +3,7 @@ module OrientDb
include OrientDb::Methods::EdgeMethods
def build_object(args={})
Collection.new(args.merge(id: args['@rid'],
name: args['name']))
Collection.new(args)
end
def create_bookmarks_collection(user)
......@@ -16,9 +15,8 @@ module OrientDb
end
def destroy_bookmarks_collection(user)
bookmarks = Bookmarks.new(owner: user)
if has_bookmarks?(user)
bookmarks = user.bookmarks
if has_bookmarks? bookmarks
destroy bookmarks
end
end
......@@ -39,10 +37,22 @@ module OrientDb
def bookmarks(user)
result = connection.query(sprintf("select expand(in('BelongsTo')) from %s where name = '%s'", user.rid, 'Bookmarks'))
build_object(result.first)
if !result.empty?
return build_object(result.first)
end
# returns a null object
Bookmarks.new(owner: user)
end
def has_bookmarks?(user)
# checks if bookmarks id is defined
if user.bookmarks.id.nil?
return false
end
# checks if edge exists
edge_exists? 'BelongsTo', user.bookmarks.id, user.rid
end
......
......@@ -2,7 +2,6 @@
class Repository::Environments
def self.create(env)
env = env
environments[env] = Repository::Repository.new
yield(environments[env]) if block_given?
end
......
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