Module: ActiveWorker::Templatable

Defined in:
lib/active_worker/templatable.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



10
11
12
13
14
15
# File 'lib/active_worker/templatable.rb', line 10

def self.included(base)
  base.field :renderable, :type => Boolean, :default => true
  base.field :template_name

  base.extend(ClassMethods)
end

Instance Method Details

#find_templateObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/active_worker/templatable.rb', line 17

def find_template
  child_template_ids = configurations.map(&:find_template).map(&:id)

  attributes_for_template = {}
  attributes_for_template[:configuration_type] = self.class.name

  if child_template_ids.any?
    attributes_for_template[:child_template_ids] = child_template_ids
  end

  self.class.template_fields.each do |field|
    attributes_for_template[field] = read_attribute(field)
  end

  template = Template.find_or_create_by(attributes_for_template)
  template.name = template_name if template_name && (! template_name.empty?)
  template.save!
  template
end

#template_name_or(input_string) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/active_worker/templatable.rb', line 37

def template_name_or(input_string)
  if template_name && (! template_name.empty?)
    template_name
  else
    input_string
  end
end