Module: Middle::ClassMethods
- Defined in:
- lib/middle.rb
Instance Attribute Summary collapse
-
#current_user ⇒ Object
Returns the value of attribute current_user.
Instance Method Summary collapse
- #actions ⇒ Object
- #can(action, subject, *args, &block) ⇒ Object
- #define_action(*args) ⇒ Object
- #rules ⇒ Object
Instance Attribute Details
#current_user ⇒ Object
Returns the value of attribute current_user.
15 16 17 |
# File 'lib/middle.rb', line 15 def current_user @current_user end |
Instance Method Details
#actions ⇒ Object
29 30 31 |
# File 'lib/middle.rb', line 29 def actions @@actions ||= {} end |
#can(action, subject, *args, &block) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/middle.rb', line 40 def can(action, subject, *args, &block) = args. block = args.pop if args.last.kind_of?(Proc) if defined_action_exists?(action) collection = fetch_action_from_collection(action) collection.each { |name| define_rule(name, subject, , &block) } end define_rule(action, subject, , &block) end |
#define_action(*args) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/middle.rb', line 33 def define_action(*args) = args. .each do |key, value| actions[key] = value end end |
#rules ⇒ Object
25 26 27 |
# File 'lib/middle.rb', line 25 def rules @@rules ||= {} end |