summaryrefslogtreecommitdiff
path: root/lib/declarative_policy
diff options
context:
space:
mode:
Diffstat (limited to 'lib/declarative_policy')
-rw-r--r--lib/declarative_policy/base.rb6
-rw-r--r--lib/declarative_policy/cache.rb4
-rw-r--r--lib/declarative_policy/condition.rb2
-rw-r--r--lib/declarative_policy/rule.rb24
-rw-r--r--lib/declarative_policy/runner.rb6
5 files changed, 21 insertions, 21 deletions
diff --git a/lib/declarative_policy/base.rb b/lib/declarative_policy/base.rb
index cd6e1606f22..3386f2935c2 100644
--- a/lib/declarative_policy/base.rb
+++ b/lib/declarative_policy/base.rb
@@ -165,7 +165,7 @@ module DeclarativePolicy
condition = Condition.new(name, opts, &value)
- self.own_conditions[name] = condition
+ own_conditions[name] = condition
define_method(:"#{name}?") { condition(name).pass? }
end
@@ -308,14 +308,14 @@ module DeclarativePolicy
# A list of other policies that we've delegated to (see `Base.delegate`)
def delegated_policies
- @delegated_policies ||= self.class.delegations.transform_values do |block|
+ @delegated_policies ||= self.class.delegations.transform_values { |block|
new_subject = instance_eval(&block)
# never delegate to nil, as that would immediately prevent_all
next if new_subject.nil?
policy_for(new_subject)
- end
+ }
end
def policy_for(other_subject)
diff --git a/lib/declarative_policy/cache.rb b/lib/declarative_policy/cache.rb
index 13006e56454..e51d6aa8851 100644
--- a/lib/declarative_policy/cache.rb
+++ b/lib/declarative_policy/cache.rb
@@ -4,7 +4,7 @@ module DeclarativePolicy
module Cache
class << self
def user_key(user)
- return '<anonymous>' if user.nil?
+ return "<anonymous>" if user.nil?
id_for(user)
end
@@ -16,7 +16,7 @@ module DeclarativePolicy
end
def subject_key(subject)
- return '<nil>' if subject.nil?
+ return "<nil>" if subject.nil?
return subject.inspect if subject.is_a?(Symbol)
"#{subject.class.name}:#{id_for(subject)}"
diff --git a/lib/declarative_policy/condition.rb b/lib/declarative_policy/condition.rb
index b77f40b1093..a0e4aa6facf 100644
--- a/lib/declarative_policy/condition.rb
+++ b/lib/declarative_policy/condition.rb
@@ -90,7 +90,7 @@ module DeclarativePolicy
when :user then "/dp/condition/#{@condition.key}/#{user_key}"
when :subject then "/dp/condition/#{@condition.key}/#{subject_key}"
when :global then "/dp/condition/#{@condition.key}"
- else raise 'invalid scope'
+ else raise "invalid scope"
end
end
diff --git a/lib/declarative_policy/rule.rb b/lib/declarative_policy/rule.rb
index f38f4f0a50f..dd3d13bc5a0 100644
--- a/lib/declarative_policy/rule.rb
+++ b/lib/declarative_policy/rule.rb
@@ -18,20 +18,20 @@ module DeclarativePolicy
# `context` is a policy - an instance of
# DeclarativePolicy::Base.
def pass?(context)
- raise 'abstract'
+ raise "abstract"
end
# same as #pass? except refuses to do any I/O,
# returning nil if the result is not yet cached.
# used for accurately scoring And/Or
def cached_pass?(context)
- raise 'abstract'
+ raise "abstract"
end
# abstractly, how long would it take to compute
# this rule? lower-scored rules are tried first.
def score(context)
- raise 'abstract'
+ raise "abstract"
end
# unwrap double negatives and nested and/or
@@ -52,9 +52,9 @@ module DeclarativePolicy
Not.make(self)
end
- alias_method :|, :or
- alias_method :&, :and
- alias_method :~@, :negate
+ alias | or
+ alias & and
+ alias ~ negate
def inspect
"#<Rule #{repr}>"
@@ -184,13 +184,13 @@ module DeclarativePolicy
end
def simplify
- simplified_rules = @rules.flat_map do |rule|
+ simplified_rules = @rules.flat_map { |rule|
simplified = rule.simplify
case simplified
when And then simplified.rules
else [simplified]
end
- end
+ }
And.new(simplified_rules)
end
@@ -222,7 +222,7 @@ module DeclarativePolicy
end
def repr
- "all?(#{rules.map(&:repr).join(', ')})"
+ "all?(#{rules.map(&:repr).join(", ")})"
end
end
@@ -241,13 +241,13 @@ module DeclarativePolicy
end
def simplify
- simplified_rules = @rules.flat_map do |rule|
+ simplified_rules = @rules.flat_map { |rule|
simplified = rule.simplify
case simplified
when Or then simplified.rules
else [simplified]
end
- end
+ }
Or.new(simplified_rules)
end
@@ -269,7 +269,7 @@ module DeclarativePolicy
end
def repr
- "any?(#{@rules.map(&:repr).join(', ')})"
+ "any?(#{@rules.map(&:repr).join(", ")})"
end
end
diff --git a/lib/declarative_policy/runner.rb b/lib/declarative_policy/runner.rb
index f739fe5e16e..fd17b1a2b5f 100644
--- a/lib/declarative_policy/runner.rb
+++ b/lib/declarative_policy/runner.rb
@@ -184,9 +184,9 @@ module DeclarativePolicy
def inspect_step(step, original_score, passed)
symbol =
case passed
- when true then '+'
- when false then '-'
- when nil then ' '
+ when true then "+"
+ when false then "-"
+ when nil then " "
end
"#{symbol} [#{original_score.to_i}] #{step.repr}\n"