Class: Courier::Service::Base

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

Direct Known Subclasses

ActiveMailer, Facebook, GritterNotice

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configObject



32
33
34
# File 'lib/courier/service/base.rb', line 32

def config
  @config
end

.configure {|@config| ... } ⇒ Object

Yields:



28
29
30
# File 'lib/courier/service/base.rb', line 28

def configure
  yield @config
end

.inherited(subclass) ⇒ Object



23
24
25
26
# File 'lib/courier/service/base.rb', line 23

def inherited(subclass)
  subclass.instance_variable_set('@config', OpenStruct.new)
  super
end

Instance Method Details

#check_args(owner, template, args) ⇒ Object



37
38
39
# File 'lib/courier/service/base.rb', line 37

def check_args owner, template, args
  # args[:text]||=template.get_text(self, args)
end

#deliver_all!Object



66
67
68
69
70
# File 'lib/courier/service/base.rb', line 66

def deliver_all!
  messages.fresh.each do |message|
    deliver_message(message) and message.mark_as_delivered!
  end
end

#deliver_message(message) ⇒ Object



58
59
60
# File 'lib/courier/service/base.rb', line 58

def deliver_message(message)
  raise 'inherit and implement me'
end

#message(owner, template, args) ⇒ Object



41
42
43
44
# File 'lib/courier/service/base.rb', line 41

def message(owner, template, args)
  check_args owner, template, args
  Courier::Message.create! :owner=>owner, :template=>template.name, :service=>name, :options=>args
end

#messagesObject



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

def messages
  Courier::Message.by_service(name)
end

#nameObject



54
55
56
# File 'lib/courier/service/base.rb', line 54

def name
  self.class.name.demodulize.underscore.to_sym
end

#to_labelObject



50
51
52
# File 'lib/courier/service/base.rb', line 50

def to_label
  I18n::translate(:label, :scope=>[:courier, :services, name] )
end

#to_sObject



46
47
48
# File 'lib/courier/service/base.rb', line 46

def to_s
  name
end