Module: IdPlease::ModelExtensions::ForObject

Defined in:
lib/id_please/model_extensions/for_object.rb

Instance Method Summary collapse

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.

Parameters:

  • role_name (Symbol, String)

    Role name

  • subject (Subject)

    Subject to remove role from

See Also:

  • Acl9::ModelExtensions::Subject#has_no_role!


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.

Parameters:

  • role_name (Symbol, String)

    Role name

  • subject (Subject)

    Subject to add role for

See Also:

  • Acl9::ModelExtensions::Subject#has_role!


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.

Parameters:

  • role_name (Symbol, String)

    Role name

  • subject (Subject)

    Subject to add role for

Returns:

  • (Boolean)

    Returns true if subject has a role role_name on this object.

See Also:

  • Acl9::ModelExtensions::Subject#has_role?


12
13
14
# File 'lib/id_please/model_extensions/for_object.rb', line 12

def accepts_role?(role_name, subject, options = {})
  subject.has_role?(role_name, self, options)
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)
  options = args.extract_options!
  
  find_subjects(nil, options)
  
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)
  options = args.extract_options!
  
  find_subjects(role_name, options)
end