permissive 0.2.1.alpha → 0.2.2.alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  *.gem
2
+ *.gemspec
2
3
  coverage/
3
4
  pkg/
4
5
  **/*.log
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1.alpha
1
+ 0.2.2.alpha
@@ -85,10 +85,11 @@ module Permissive
85
85
  permission_setter = options[:on].nil? || options[:on] == :global ? 'permissions=' : "#{options[:on].to_s.singularize}_permissions="
86
86
  class_eval <<-eoc
87
87
  def #{permission_setter}(values)
88
+ values ||= []
88
89
  if values.all? {|value| value.is_a?(String) || value.is_a?(Symbol)}
89
90
  can!(values, :reset => true, :on => #{options[:on].inspect})
90
91
  else
91
- super
92
+ super(values)
92
93
  end
93
94
  end
94
95
  eoc
@@ -125,7 +126,7 @@ module Permissive
125
126
  revoke(#{[permissions, args].flatten.join(', ').inspect}, :on => scope)
126
127
  end
127
128
  end_eval
128
- return can!(*[permissions, options].flatten)
129
+ return revoke(*[permissions, options].flatten)
129
130
  elsif setter
130
131
  class_eval <<-end_eval
131
132
  def #{method}(scope = nil)
@@ -29,14 +29,15 @@ module Permissive
29
29
  end
30
30
 
31
31
  def normalize_scope(model, scope)
32
- case scope
32
+ scope = case scope
33
33
  when Class
34
34
  scope.name.tableize
35
35
  when String, Symbol
36
36
  interpolate_scope(model, scope).to_s.tableize
37
37
  else
38
38
  :global
39
- end.to_s.gsub('/', '_').to_sym
39
+ end
40
+ scope.to_s.gsub('/', '_').to_sym
40
41
  end
41
42
  end
42
43
 
@@ -80,7 +81,7 @@ module Permissive
80
81
  names.each do |name|
81
82
  @role = name.to_s.to_sym
82
83
  roles[@role] ||= []
83
- instance_eval(&block)
84
+ instance_eval(&block) if block_given?
84
85
  end
85
86
  unless model.instance_methods.include?('role=')
86
87
  model.class_eval do
@@ -287,6 +287,13 @@ describe Permissive::Permission do
287
287
  @user.can_manage_games_in?(@organization).should be_true
288
288
  end
289
289
  end
290
+
291
+ it "should support revoking, too" do
292
+ @user.can_manage_games!
293
+ @user.can_manage_games?.should be_true
294
+ @user.cannot_manage_games!
295
+ @user.can_manage_games?.should be_false
296
+ end
290
297
  end
291
298
 
292
299
  describe "roles" do
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 1
8
+ - 2
9
9
  - alpha
10
- version: 0.2.1.alpha
10
+ version: 0.2.2.alpha
11
11
  platform: ruby
12
12
  authors:
13
13
  - Flip Sasser