Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cleaning-portalmec
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Richard Fernando Heise Ferreira
cleaning-portalmec
Commits
ce9a034f
Commit
ce9a034f
authored
9 years ago
by
Mauricio Giacomini Girardello
Browse files
Options
Downloads
Patches
Plain Diff
create builder for collection models
parent
9b160a10
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/builders/collection_builder.rb
+40
-0
40 additions, 0 deletions
app/builders/collection_builder.rb
app/repositories/orient_db/collection_repository.rb
+1
-12
1 addition, 12 deletions
app/repositories/orient_db/collection_repository.rb
with
41 additions
and
12 deletions
app/builders/collection_builder.rb
0 → 100644
+
40
−
0
View file @
ce9a034f
class
CollectionBuilder
extend
RepositoriesProxy
##
# receive a list of ids and return a list of collections
def
self
.
build
(
objects
=
[])
lo
=
[]
objects
.
each
do
|
object
|
unless
object
[
'rid'
].
blank?
o
=
Rails
.
cache
.
fetch
(
cache_key
(
object
[
'rid'
],
object
[
'last_modified'
]))
o
=
collection_repository
.
find
object
[
'rid'
]
if
o
.
nil?
lo
<<
o
end
end
lo
end
def
self
.
build_from_orientdb
(
args
=
{})
lo
=
nil
unless
args
.
nil?
# cache object when build
lo
=
Rails
.
cache
.
fetch
(
cache_key
(
args
[
'@rid'
],
args
[
'last_modified'
]),
expires_in:
12
.
hours
)
do
obj
=
Collection
.
new
(
learning_objects:
LearningObjectBuilder
.
build
(
args
[
'learning_objects'
]
||
[]),
privacy:
args
[
'privacy'
],
name:
args
[
'name'
],
id:
args
[
'@rid'
]
)
obj
.
created_at
=
DateTime
.
strptime
(
args
[
'created_at'
],
"%Y-%m-%d %H:%M:%S"
)
unless
args
[
'created_at'
].
nil?
obj
.
last_modified
=
DateTime
.
strptime
(
args
[
'last_modified'
],
"%Y-%m-%d %H:%M:%S"
)
unless
args
[
'last_modified'
].
nil?
obj
end
end
lo
end
def
self
.
cache_key
(
rid
,
last_modified
)
rid
+
'/'
+
last_modified
end
end
This diff is collapsed.
Click to expand it.
app/repositories/orient_db/collection_repository.rb
+
1
−
12
View file @
ce9a034f
...
...
@@ -4,7 +4,7 @@ module OrientDb
include
OrientDb
::
Methods
::
FinderMethods
def
build_object
(
args
=
{})
Collection
.
new
(
map_object_hash
(
args
))
Collection
Builder
.
build_from_orientdb
args
end
def
save
(
collection
=
Collection
.
new
)
...
...
@@ -85,17 +85,6 @@ module OrientDb
private
def
map_object_hash
(
hash
=
{})
{
created_at:
hash
[
'created_at'
],
last_modified:
hash
[
'last_modified'
],
learning_objects:
hash
[
'created_at'
],
privacy:
hash
[
'privacy'
],
name:
hash
[
'name'
],
id:
hash
[
'@rid'
]
}
end
def
odb_class
'Collection'
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment