Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cancan
Manage
Activity
Members
Plan
External wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
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
Github Mirror
coopdevs
cancan
Commits
dbc15380
Commit
dbc15380
authored
14 years ago
by
Yura Sokolov
Browse files
Options
Downloads
Patches
Plain Diff
small refactoring: CanDefinition #definitive? #conditions_empty?
parent
46f03013
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/cancan/ability.rb
+14
-18
14 additions, 18 deletions
lib/cancan/ability.rb
lib/cancan/can_definition.rb
+9
-2
9 additions, 2 deletions
lib/cancan/can_definition.rb
with
23 additions
and
20 deletions
lib/cancan/ability.rb
+
14
−
18
View file @
dbc15380
...
...
@@ -202,10 +202,7 @@ module CanCan
def
conditions
(
action
,
subject
,
options
=
{})
matched
=
matching_can_definition
(
action
,
subject
)
unless
matched
.
empty?
if
matched
.
any?
{
|
can_definition
|
cond
=
can_definition
.
conditions
(
cond
.
nil?
||
cond
.
empty?
)
&&
can_definition
.
block
}
if
matched
.
any?
{
|
can_definition
|
can_definition
.
conditions_empty?
&&
can_definition
.
block
}
raise
Error
,
"Cannot determine ability conditions from block for
#{
action
.
inspect
}
#{
subject
.
inspect
}
"
end
matched
.
map
{
|
can_definition
|
...
...
@@ -239,20 +236,19 @@ module CanCan
false_cond
=
subject
.
send
(
:sanitize_sql
,
[
'?=?'
,
true
,
false
])
conds
.
reverse
.
inject
(
nil
)
do
|
sql
,
action
|
behavior
,
condition
=
action
if
condition
&&
!
condition
.
empty?
if
condition
&&
condition
!=
{}
condition
=
"
#{
subject
.
send
(
:sanitize_sql
,
condition
)
}
"
condition
=
"not (
#{
condition
}
)"
if
behavior
==
false
case
sql
when
nil
then
condition
when
true_cond
behavior
?
true_cond
:
"not (
#{
condition
}
)"
when
false_cond
behavior
?
condition
:
false_cond
else
behavior
?
"(
#{
condition
}
) OR (
#{
sql
}
)"
:
"not (
#{
condition
}
) AND (
#{
sql
}
)"
end
else
condition
=
behavior
?
true_cond
:
false_cond
end
case
sql
when
nil
then
condition
when
true_cond
behavior
?
true_cond
:
condition
when
false_cond
behavior
?
condition
:
false_cond
else
behavior
?
"(
#{
condition
}
) OR (
#{
sql
}
)"
:
"
#{
condition
}
AND (
#{
sql
}
)"
behavior
?
true_cond
:
false_cond
end
end
end
...
...
@@ -262,7 +258,7 @@ module CanCan
def
association_joins
(
action
,
subject
)
can_definitions
=
matching_can_definition
(
action
,
subject
)
unless
can_definitions
.
empty?
if
can_definitions
.
any?
{
|
can_definition
|
can_definition
.
conditions
.
nil
?
&&
can_definition
.
block
}
if
can_definitions
.
any?
{
|
can_definition
|
can_definition
.
conditions
_empty
?
&&
can_definition
.
block
}
raise
Error
,
"Cannot determine association joins from block for
#{
action
.
inspect
}
#{
subject
.
inspect
}
"
end
collect_association_joins
(
can_definitions
)
...
...
@@ -283,7 +279,7 @@ module CanCan
can_definition
.
expand_actions
(
aliased_actions
)
if
can_definition
.
matches?
action
,
subject
yield
can_definition
break
if
can_definition
.
conditions
.
nil?
&&
can_definition
.
block
.
nil
?
break
if
can_definition
.
definitive
?
end
end
else
...
...
This diff is collapsed.
Click to expand it.
lib/cancan/can_definition.rb
+
9
−
2
View file @
dbc15380
...
...
@@ -51,7 +51,16 @@ module CanCan
end
end
def
definitive?
conditions_empty?
&&
@block
.
nil?
end
def
conditions_empty?
@conditions
==
{}
||
@conditions
.
nil?
end
def
association_joins
(
conditions
=
@conditions
)
return
nil
unless
conditions
.
kind_of?
(
Hash
)
joins
=
[]
conditions
.
each
do
|
name
,
value
|
if
value
.
kind_of?
Hash
...
...
@@ -81,8 +90,6 @@ module CanCan
call_block
(
action
,
subject
,
extra_args
)
elsif
@conditions
.
kind_of?
(
Hash
)
&&
subject
.
class
!=
Class
matches_conditions?
(
subject
)
elsif
[
true
,
false
,
:_NOT_MATCHES
].
include?
@conditions
@conditions
else
true
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