Class: PerformLater::ArgsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/perform_later/args_parser.rb

Constant Summary collapse

CLASS_STRING_FORMAT =

inspired by DelayedJob

/^CLASS\:([A-Z][\w\:]+)$/
AR_STRING_FORMAT =
/^AR\:([A-Z][\w\:]+)\:(\d+)$/
YAML_STRING_FORMAT =
/\A---/

Class Method Summary collapse

Class Method Details

.args_from_resque(args) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/perform_later/args_parser.rb', line 16

def self.args_from_resque(args)
  args = args.map { |o|
    if o
      o = args_from_resque(o) if o.is_a?(Array)
      case o
        when CLASS_STRING_FORMAT
          $1.constantize
        when AR_STRING_FORMAT
          runner_class = $1.constantize
          id = $2

          if PerformLater::Plugins.finder_class
            PerformLater::Plugins.finder_class.find(runner_class, id)
          else
            runner_class.where(id: id).first  
          end
        when YAML_STRING_FORMAT
          YAML.load(o)
        else 
          o
      end
    end
  } if args
end

.args_to_resque(args) ⇒ Object



10
11
12
13
14
# File 'lib/perform_later/args_parser.rb', line 10

def self.args_to_resque(args)
  return nil unless args
  return arg_to_resque(args) unless args.is_a?(Array)
  return args.map { |o| arg_to_resque o }
end