BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
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
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
5 deletions
+7
-5
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"
end
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
self
.
class
.
column_for_attribute
(
attribute
).
type_cast_from_database
(
value
)
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