Sha256: e51d0ea117adbf1a3a253e676c30c4218188e3910ece192d60eef98a5e9ddcd3

Contents?: true

Size: 961 Bytes

Versions: 1

Compression:

Stored size: 961 Bytes

Contents

module Backgrounded
  module ClassMethods
    def backgrounded(*args)
      options = args.extract_options!
      methods_with_options = args.inject({}) do |hash, method| hash[method] = {}; hash end
      methods_with_options.merge! options
      methods_with_options.each_pair do |method, options|
        method_basename, punctuation = method.to_s.sub(/([?!=])$/, ''), $1
        if options[:class_method]
          class_eval <<-EOS
            def self.#{method_basename}_backgrounded#{punctuation}(*args)
              Backgrounded.handler.request(self, :#{method}, *args)
            end
          EOS
        else
          define_method "#{method_basename}_backgrounded#{punctuation}" do |*args|
            Backgrounded.handler.request(self, method, *args)
          end
        end
      end
      cattr_accessor :backgrounded_options
      self.backgrounded_options ||= {}
      self.backgrounded_options.merge! methods_with_options
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
phene-backgrounded-0.6.2 lib/backgrounded/class_methods.rb