Module: ActsAsAsync::Helper::SharedMethods

Defined in:
lib/acts_as_async/helper.rb

Constant Summary collapse

METHOD_REGEXP =
/\Aasync_([a-zA-Z]\w*?)(_at|_in)?(!)?\z/

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/acts_as_async/helper.rb', line 58

def method_missing(method_id, *args, &block)
  if method_id.to_s =~ METHOD_REGEXP
    # Compose the method to be async'd, with an optional bang
    method = "#{$1}#{$3}"

    if respond_to? method
      # If we're not using the _at or _in methods, just call async
      if $2.nil?
        __send__(:async, method, *args)

      # Otherwise compose the Helper method
      else
        __send__("async#{$2}", args.shift, method, *args)
      end
    else
      message = "Tried to async the method #{method} but it isn't defined."
      raise NoMethodError, message
    end
  else
    super
  end
end

Instance Method Details

#respond_to?(method_id) ⇒ Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/acts_as_async/helper.rb', line 91

def respond_to?(method_id, *)
  !!(method_id.to_s =~ METHOD_REGEXP) || super
end

#respond_to_missing?(method_id) ⇒ Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/acts_as_async/helper.rb', line 87

def respond_to_missing?(method_id, *)
  !!(method_id =~ METHOD_REGEXP) || super
end