johnsbrn-has_permission 0.2.7 → 0.2.8
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/VERSION.yml +1 -1
- data/lib/permission/array.rb +15 -0
- data/test/array_test.rb +16 -0
- metadata +3 -1
data/VERSION.yml
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Permission
|
2
|
+
module Array
|
3
|
+
|
4
|
+
# helper method for adding to an array based on permission i.e. [].push_if("some feature", Feature.with_permission(current_user).can_write?)
|
5
|
+
def push_if(*args)
|
6
|
+
raise ArgumentError.new "wrong number of arguments (#{args.length} for 2)" if args.length < 2
|
7
|
+
if args.pop
|
8
|
+
push(*args)
|
9
|
+
else
|
10
|
+
self
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
data/test/array_test.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class ArrayTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
should "have method push_if" do
|
6
|
+
assert_equal true, [].methods.include?("push_if")
|
7
|
+
end
|
8
|
+
|
9
|
+
should "not push if condition is false" do
|
10
|
+
assert_equal [], [].push_if("test", false)
|
11
|
+
end
|
12
|
+
|
13
|
+
should "push if condition is true" do
|
14
|
+
assert_equal ["test"], [].push_if("test", true)
|
15
|
+
end
|
16
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: johnsbrn-has_permission
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Johnson
|
@@ -31,8 +31,10 @@ files:
|
|
31
31
|
- lib/active_record/has/permission.rb
|
32
32
|
- lib/has_permission.rb
|
33
33
|
- lib/permission
|
34
|
+
- lib/permission/array.rb
|
34
35
|
- lib/permission/base.rb
|
35
36
|
- lib/permission_exception.rb
|
37
|
+
- test/array_test.rb
|
36
38
|
- test/has_permission_test.rb
|
37
39
|
- test/test_helper.rb
|
38
40
|
has_rdoc: true
|