Module: IdPlease::ModelExtensions::ForObject
- Defined in:
- lib/id_please/model_extensions/for_object.rb
Instance Method Summary collapse
-
#accepts_no_role!(role_name, subject) ⇒ Object
Free specified subject of a role on this object.
-
#accepts_role!(role_name, subject) ⇒ Object
Add role on the object to specified subject.
-
#accepts_role?(role_name, subject, options = {}) ⇒ Boolean
Role check.
- #list_subjects_all_roles(*args) ⇒ Object
- #list_subjects_for(role_name, *args) ⇒ Object
- #method_missing(method_sym, *arguments, &block) ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_sym, *arguments, &block) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/id_please/model_extensions/for_object.rb', line 44 def method_missing(method_sym, *arguments, &block) # the first argument is a Symbol, so you need to_s it if you want to pattern match if method_sym.to_s =~ /^list_(.+)$/ list_subjects_for($1.singularize, *arguments) else super end end |
Instance Method Details
#accepts_no_role!(role_name, subject) ⇒ Object
Free specified subject of a role on this object.
60 61 62 |
# File 'lib/id_please/model_extensions/for_object.rb', line 60 def accepts_no_role!(role_name, subject) subject.has_no_role!(role_name, self) end |
#accepts_role!(role_name, subject) ⇒ Object
Add role on the object to specified subject.
24 25 26 |
# File 'lib/id_please/model_extensions/for_object.rb', line 24 def accepts_role!(role_name, subject) subject.has_role!(role_name, self) end |
#accepts_role?(role_name, subject, options = {}) ⇒ Boolean
Role check.
12 13 14 |
# File 'lib/id_please/model_extensions/for_object.rb', line 12 def accepts_role?(role_name, subject, = {}) subject.has_role?(role_name, self, ) end |
#list_subjects_all_roles(*args) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/id_please/model_extensions/for_object.rb', line 29 def list_subjects_all_roles(*args) = args. find_subjects(nil, ) end |
#list_subjects_for(role_name, *args) ⇒ Object
36 37 38 39 40 |
# File 'lib/id_please/model_extensions/for_object.rb', line 36 def list_subjects_for(role_name, *args) = args. find_subjects(role_name, ) end |