Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
2ebafdfb
Commit
2ebafdfb
authored
May 18, 2018
by
Kamil Trzciński
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve cacheable module
parent
17c4e53e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
5 deletions
+7
-5
app/models/concerns/redis_cacheable.rb
app/models/concerns/redis_cacheable.rb
+7
-5
No files found.
app/models/concerns/redis_cacheable.rb
View file @
2ebafdfb
...
...
@@ -7,11 +7,11 @@ module RedisCacheable
class_methods
do
def
cached_attr_reader
(
*
attributes
)
attributes
.
each
do
|
attribute
|
define_method
(
attribute
)
do
unless
self
.
has_attribute?
(
attribute
)
raise
ArgumentError
,
"`cached_attr_reader` requires the
#{
self
.
class
.
name
}
\#
#{
attribute
}
attribute to have a database column"
unless
self
.
column_names
.
include?
(
attribute
.
to_s
)
raise
ArgumentError
,
"`cached_attr_reader` requires the
#{
self
.
name
}
#
#{
attribute
}
to be a database attribute"
end
define_method
(
attribute
)
do
cached_attribute
(
attribute
)
||
read_attribute
(
attribute
)
end
end
...
...
@@ -50,7 +50,9 @@ module RedisCacheable
if
Gitlab
.
rails5?
self
.
class
.
type_for_attribute
(
attribute
).
cast
(
value
)
else
ActiveSupport
::
Deprecation
.
silence
do
self
.
class
.
column_for_attribute
(
attribute
).
type_cast_from_database
(
value
)
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment