Module: CanSelfDoIt::Base

Defined in:
lib/can_self_do_it/base.rb

Instance Method Summary collapse

Instance Method Details

#can_create?(obj_class, parent = self) ⇒ Boolean

parent: parent of the object created Examples:

  • session_user.can_create?(Proposal, project)

  • session_user.can_create?(Project)

Returns:

  • (Boolean)


19
20
21
22
# File 'lib/can_self_do_it/base.rb', line 19

def can_create?(obj_class, parent = self)
  method = "can_create_#{CanSelfDoIt::Helper.class_2_method_sub_str(obj_class)}?"
  self.public_methods.include?(method.to_sym) ?  send(method,parent) : can_create_default?(parent)
end

#can_delete?(obj) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
# File 'lib/can_self_do_it/base.rb', line 24

def can_delete?(obj)
  method = "can_delete_#{CanSelfDoIt::Helper.class_2_method_sub_str(obj.class)}?"
  self.public_methods.include?(method.to_sym) ?  send(method,obj) : can_delete_default?(obj)
end

#can_edit?(obj) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
# File 'lib/can_self_do_it/base.rb', line 10

def can_edit?(obj)
  method = "can_edit_#{CanSelfDoIt::Helper.class_2_method_sub_str(obj.class)}?"
  self.public_methods.include?(method.to_sym) ? send(method,obj) : can_edit_default?(obj)
end

#can_see?(obj) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
8
# File 'lib/can_self_do_it/base.rb', line 5

def can_see?(obj)
  method = "can_see_#{CanSelfDoIt::Helper.class_2_method_sub_str(obj.class)}?"
  self.public_methods.include?(method.to_sym) ?  self.send(method,obj) : can_see_default?(obj)
end

#respond_to_without_can_self_do_it_method?(sym) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/can_self_do_it/base.rb', line 29

def respond_to_without_can_self_do_it_method?(sym)
  self.public_methods.include?(sym.to_sym)
end