Module: MayI

Defined in:
lib/mayi.rb,
lib/mayi/methods.rb

Defined Under Namespace

Classes: AccessDeniedError

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/mayi/methods.rb', line 4

def method_missing(meth, *args, &block)
  if is_a_may_i_method?(meth)
    if self.send(meth.to_s[0..-2].to_sym,*args)
      yield if block_given?
      true
    else
      meth.to_s.end_with?("!") ? raise_may_i_error(meth) : false
    end
  else
    super(meth,*args,&block)  
  end
ensure
  @may_i_error_message = nil
end

Instance Method Details

#error_message(message) ⇒ Object



27
28
29
30
# File 'lib/mayi/methods.rb', line 27

def error_message(message)
  @custom_may_i_error_message = message
  self
end

#respond_to?(meth) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
# File 'lib/mayi/methods.rb', line 19

def respond_to?(meth)
  if is_a_may_i_method?(meth)
    super(meth.to_s[0..-2].to_sym)
  else
    super(meth)  
  end
end