Class: DigestEmail::PerformableDigest

Inherits:
Object
  • Object
show all
Defined in:
lib/digest_email/performable_digest.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, method_name, args) ⇒ PerformableDigest

Returns a new instance of PerformableDigest.

Raises:

  • (NoMethodError)


7
8
9
10
11
12
13
14
15
16
17
# File 'lib/digest_email/performable_digest.rb', line 7

def initialize(object, method_name, args)
  raise NoMethodError, "undefined method `#{method_name}' for #{object.inspect}" unless object.respond_to?(method_name, true)

  if object.respond_to?(:new_record?) && object.new_record?
    raise(ArgumentError, 'Digest cannot be created for records before they\'ve been persisted')
  end

  self.object       = object
  self.args         = args
  self.method_name  = method_name.to_sym
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



3
4
5
# File 'lib/digest_email/performable_digest.rb', line 3

def args
  @args
end

#method_nameObject

Returns the value of attribute method_name.



3
4
5
# File 'lib/digest_email/performable_digest.rb', line 3

def method_name
  @method_name
end

#objectObject

Returns the value of attribute object.



3
4
5
# File 'lib/digest_email/performable_digest.rb', line 3

def object
  @object
end

Instance Method Details

#ensure_digest_groupObject



27
28
29
# File 'lib/digest_email/performable_digest.rb', line 27

def ensure_digest_group
  DigestEmailGroup.find_or_create_by_mailer_name_and_method_name mailer_name, method_name
end

#mailer_nameObject



19
20
21
# File 'lib/digest_email/performable_digest.rb', line 19

def mailer_name
  object.class.to_s
end