Class: RoRmaily::Subscription

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/maily_herald/subscription.rb

Instance Method Summary collapse

Instance Method Details

#activate!Object


36
37
38
# File 'app/models/maily_herald/subscription.rb', line 36

def activate!
  update_attribute(:active, true)
end

#active?Boolean

Returns:

  • (Boolean)

28
29
30
# File 'app/models/maily_herald/subscription.rb', line 28

def active?
  !new_record? && read_attribute(:active)
end

#deactivate!Object


32
33
34
# File 'app/models/maily_herald/subscription.rb', line 32

def deactivate!
  update_attribute(:active, false)
end

#logsObject


63
64
65
# File 'app/models/maily_herald/subscription.rb', line 63

def logs
  self.list.logs.for_entity(self.entity)
end

#to_liquidObject


48
49
50
51
52
# File 'app/models/maily_herald/subscription.rb', line 48

def to_liquid
  {
    "token_url" => token_url
  }
end

#toggle!Object


40
41
42
# File 'app/models/maily_herald/subscription.rb', line 40

def toggle!
  active? ? deactivate! : activate!
end

#token_urlObject


44
45
46
# File 'app/models/maily_herald/subscription.rb', line 44

def token_url
  RoRmaily::Engine.routes.url_helpers.ubsubscribe_url(self)
end

#update_schedulesObject


54
55
56
57
58
59
60
61
# File 'app/models/maily_herald/subscription.rb', line 54

def update_schedules
  PeriodicalMailing.where(list_id: self.list).each do |m|
    m.set_schedule_for self.entity
  end
  Sequence.where(list_id: self.list).each do |s|
    s.set_schedule_for self.entity
  end
end