Class: NowAndLater::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/now_and_later/service.rb

Overview

Later with Delayed::Job you can also run your service later with delayed job later e.g. SendWelcomeEmail.later @user

Direct Known Subclasses

Enqueue::WithDelayedJob, Enqueue::WithResque

Defined Under Namespace

Modules: WithResque

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Service

Initialize takes any number of args which are set as instance variables



62
63
64
# File 'lib/now_and_later/service.rb', line 62

def initialize(*args)
  set_instance_variables args
end

Class Method Details

.can_find(arg, opt = {}) ⇒ Object

ActiveRecord Args setup an arg so that it be passed as ActiveRecord instance or integer calling sets up two instance methods #arg (instance) and #arg_id (int) which should be used to access arg instead of @arg e.g. can_find :account sets up:

  • Service#account #=> Account instance
  • Service#account_id #=> 1 Override Class Name use opt to set ActiveRecord class name as a string when class can't be inferred from arg name


43
44
45
46
47
48
# File 'lib/now_and_later/service.rb', line 43

def self.can_find(arg,opt={})
  @finders ||= {}
  @finders[arg] = opt
  define_record_getter arg
  define_id_getter arg
end

.later(*args) ⇒ Object



56
57
58
# File 'lib/now_and_later/service.rb', line 56

def self.later(*args)
  NowAndLater::Queue.add self, *args
end

.now(*args) ⇒ Object

Runners



52
53
54
# File 'lib/now_and_later/service.rb', line 52

def self.now(*args)
  new(*args).run
end

.takes(*names) ⇒ Object

Args setup args for runners



28
29
30
31
# File 'lib/now_and_later/service.rb', line 28

def self.takes(*names)
  return @takes if names.empty?
  @takes = names
end

Instance Method Details

#runObject Also known as: perform

Run called by Service.now override with app logic

Raises:

  • (NotImplementedError)


68
# File 'lib/now_and_later/service.rb', line 68

def run; raise NotImplementedError; end