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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
af246a26
Commit
af246a26
authored
Aug 27, 2020
by
Arturo Herrero
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move prop_accessor and boolean_accessor up
parent
e8a767a4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
49 deletions
+47
-49
app/models/service.rb
app/models/service.rb
+47
-49
No files found.
app/models/service.rb
View file @
af246a26
...
@@ -82,6 +82,53 @@ class Service < ApplicationRecord
...
@@ -82,6 +82,53 @@ class Service < ApplicationRecord
scope
:alert_hooks
,
->
{
where
(
alert_events:
true
,
active:
true
)
}
scope
:alert_hooks
,
->
{
where
(
alert_events:
true
,
active:
true
)
}
scope
:deployment
,
->
{
where
(
category:
'deployment'
)
}
scope
:deployment
,
->
{
where
(
category:
'deployment'
)
}
# Provide convenient accessor methods for each serialized property.
# Also keep track of updated properties in a similar way as ActiveModel::Dirty
def
self
.
prop_accessor
(
*
args
)
args
.
each
do
|
arg
|
class_eval
<<~
RUBY
,
__FILE__
,
__LINE__
+
1
unless method_defined?(arg)
def
#{
arg
}
properties['
#{
arg
}
']
end
end
def
#{
arg
}
=(value)
self.properties ||= {}
updated_properties['
#{
arg
}
'] =
#{
arg
}
unless
#{
arg
}
_changed?
self.properties['
#{
arg
}
'] = value
end
def
#{
arg
}
_changed?
#{
arg
}
_touched? &&
#{
arg
}
!=
#{
arg
}
_was
end
def
#{
arg
}
_touched?
updated_properties.include?('
#{
arg
}
')
end
def
#{
arg
}
_was
updated_properties['
#{
arg
}
']
end
RUBY
end
end
# Provide convenient boolean accessor methods for each serialized property.
# Also keep track of updated properties in a similar way as ActiveModel::Dirty
def
self
.
boolean_accessor
(
*
args
)
self
.
prop_accessor
(
*
args
)
args
.
each
do
|
arg
|
class_eval
<<~
RUBY
,
__FILE__
,
__LINE__
+
1
def
#{
arg
}
?
# '!!' is used because nil or empty string is converted to nil
!!ActiveRecord::Type::Boolean.new.cast(
#{
arg
}
)
end
RUBY
end
end
def
activated?
def
activated?
active
active
end
end
...
@@ -215,55 +262,6 @@ class Service < ApplicationRecord
...
@@ -215,55 +262,6 @@ class Service < ApplicationRecord
!
instance?
!
instance?
end
end
# Provide convenient accessor methods
# for each serialized property.
# Also keep track of updated properties in a similar way as ActiveModel::Dirty
def
self
.
prop_accessor
(
*
args
)
args
.
each
do
|
arg
|
class_eval
<<~
RUBY
,
__FILE__
,
__LINE__
+
1
unless method_defined?(arg)
def
#{
arg
}
properties['
#{
arg
}
']
end
end
def
#{
arg
}
=(value)
self.properties ||= {}
updated_properties['
#{
arg
}
'] =
#{
arg
}
unless
#{
arg
}
_changed?
self.properties['
#{
arg
}
'] = value
end
def
#{
arg
}
_changed?
#{
arg
}
_touched? &&
#{
arg
}
!=
#{
arg
}
_was
end
def
#{
arg
}
_touched?
updated_properties.include?('
#{
arg
}
')
end
def
#{
arg
}
_was
updated_properties['
#{
arg
}
']
end
RUBY
end
end
# Provide convenient boolean accessor methods
# for each serialized property.
# Also keep track of updated properties in a similar way as ActiveModel::Dirty
def
self
.
boolean_accessor
(
*
args
)
self
.
prop_accessor
(
*
args
)
args
.
each
do
|
arg
|
class_eval
<<~
RUBY
,
__FILE__
,
__LINE__
+
1
def
#{
arg
}
?
# '!!' is used because nil or empty string is converted to nil
!!ActiveRecord::Type::Boolean.new.cast(
#{
arg
}
)
end
RUBY
end
end
# Returns a hash of the properties that have been assigned a new value since last save,
# Returns a hash of the properties that have been assigned a new value since last save,
# indicating their original values (attr => original value).
# indicating their original values (attr => original value).
# ActiveRecord does not provide a mechanism to track changes in serialized keys,
# ActiveRecord does not provide a mechanism to track changes in serialized keys,
...
...
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