can_opener 0.0.4 → 0.0.5

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.
@@ -2,30 +2,36 @@ module CanOpener
2
2
  class Ability
3
3
  extend Forwardable
4
4
 
5
- def_delegators :@base, *CanCan::Ability.public_instance_methods
5
+ class << self;
6
+ attr_accessor :initializer_arguments
7
+ end
8
+ # superclass_delegating_reader :initializer_arguments
6
9
 
10
+ def_delegators :@base, *CanCan::Ability.public_instance_methods
11
+
7
12
  attr_accessor :user
8
13
  protected :user=
9
14
 
10
15
  def initialize(base, *args)
16
+ raise "You should only work with subclasses of CanOpener::Ability" if self.class == CanOpener::Ability
11
17
  @base = base
12
18
  setup_vars(*args)
13
19
  abilities
14
20
  end
15
21
 
16
22
  def self.additional_ability_arguments(*args)
17
- @@initializer_arguments = [:user]
23
+ self.initializer_arguments = [:user]
18
24
  args.each_with_index do |arg, idx|
19
25
  raise ArgumentError, "user cannot be an additional argument as it is required as the first arg" if arg.to_sym == :user
20
- @@initializer_arguments << arg.to_sym
26
+ self.initializer_arguments << arg.to_sym
21
27
  end
22
28
  end
23
-
29
+
24
30
  protected
25
31
 
26
32
  def setup_vars(*args)
27
- if @@initializer_arguments && @@initializer_arguments.length > 0
28
- @@initializer_arguments.each_with_index do |arg, idx|
33
+ if has_additional_ability_arguments?
34
+ initializer_arguments.each_with_index do |arg, idx|
29
35
  self.class.send(:attr_accessor, arg)
30
36
  self.send("#{arg}=", args[idx])
31
37
  end
@@ -33,5 +39,13 @@ module CanOpener
33
39
  @user = args[0]
34
40
  end
35
41
  end
42
+
43
+ def has_additional_ability_arguments?
44
+ initializer_arguments && initializer_arguments.length > 0
45
+ end
46
+
47
+ def initializer_arguments
48
+ self.class.superclass.initializer_arguments
49
+ end
36
50
  end
37
51
  end
@@ -1,3 +1,3 @@
1
1
  module CanOpener
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: can_opener
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brendon Murphy