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



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/acts_as_async/helper.rb', line 65

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, true
      # 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)


98
99
100
# File 'lib/acts_as_async/helper.rb', line 98

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

#respond_to_missing?(method_id) ⇒ Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/acts_as_async/helper.rb', line 94

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