lib/maglev/active_job/arguments.rb
# defines an argument that is expected to be passed in to the job. You can configure type checking, guards and defaults.
# An advantage of using this method over a standard initializer is that it will pull its value from the "arguments"
# value instead of just using a separate instance variable. When combined with the optional setter method,
# this is even futher useful by ensuring that anything you set will be properly enqueued.
defines an argument that is expected to be passed in to the job. You can configure type checking, guards and defaults.
An advantage of using this method over a standard initializer is that it will pull its value from the "arguments"
value instead of just using a separate instance variable. When combined with the optional setter method,
this is even futher useful by ensuring that anything you set will be properly enqueued.
defines an argument that is expected to be passed in to the job . You can configure type checking guards and defaults . An advantage of using this method over a standard initializer is that it will pull its value from the " arguments " value instead of just using a separate instance variable . When combined with the optional setter method this is even futher useful by ensuring that anything you set will be properly enqueued .
def argument(name, type: nil, guard: nil, default: nil, named: false, getter: true, setter: false, &block)
          ndx = arguments.count
          if getter
            define_method name do
              if named
                if arguments.count > self.class.arguments.count
                  arguments.last[name]
                end
              else
                arguments[ndx]
              end
            end
          end
          if setter
            define_method "#{name}=" do |value|
              if named
                if arguments.count > self.class.arguments.count
                  arguments.last[name] = value
                end
              else
                arguments[ndx] = value
              end
            end
          end
          store = named ? named_arguments : arguments
          store[name] = Proc.new do |job, value|
            value = if block
              job.instance_exec(value, &block)
            elsif value.nil?
              case default
                when Proc then default.call
                when Hash, Array then default.dup
                else default
              end
            else
              value
            end
            Guard.type(name, value, type, allow_nil: true) if type
            Guard.send(guard, name, value) if guard
            value
          end
        end
def argument ( name , type : nil , guard : nil , default : nil , named : false , getter : true , setter : false , & block ) ndx = arguments . count if getter define_method name do if named if arguments . count > self . class . arguments . count arguments . last [ name ] end else arguments [ ndx ] end end end if setter define_method "#{name}=" do | value | if named if arguments . count > self . class . arguments . count arguments . last [ name ] = value end else arguments [ ndx ] = value end end end store = named ? named_arguments : arguments store [ name ] = Proc . new do | job , value | value = if block job . instance_exec ( value , & block ) elsif value . nil? case default when Proc then default . call when Hash , Array then default . dup else default end else value end Guard . type ( name , value , type , allow_nil : true ) if type Guard . send ( guard , name , value ) if guard value end end
defines an argument that is expected to be passed in to the job.
defines an argument that is expected to be passed in to the job .
# named values are stored in a nested hash. They should always be last # transform the value before running any guards on it
name
<not_specific>
type
<not_specific>
guard
<not_specific>
default
<not_specific>
named
<not_specific>
getter
<not_specific>
setter
<not_specific>
block
<not_specific>