Module: NoNotifierNeeded::Translate

Defined in:
lib/no_notifier_needed/translate.rb

Instance Method Summary collapse

Instance Method Details

#args_to_instance_vars(args) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/no_notifier_needed/translate.rb', line 27

def args_to_instance_vars(args)
  #take each key, if a model, make it an @#{model} = model.find(value)
  #else make it a @#{name}=#{value}

  args.each do |k,v|
    k, v = k.to_s, v.to_s
    if Object.const_defined?(k.classify) && known_models.include?(k.classify.constantize)
      self.instance_eval("@#{k}= #{k.classify}.find(#{v})")
    else
      if v.is_a?(String)
        self.instance_eval("@#{k} = %|#{v}|")
      else
        self.instance_eval("@#{k}=#{v}")
      end
    end
  end

  if args.has_key?("current_user")
    k = NoNotifierNeeded.send(:current_user_model)
    self.instance_eval("@current_user = #{k.classify}.find(#{args['current_user']})")
  end
end

#get_send_hash(template) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/no_notifier_needed/translate.rb', line 3

def get_send_hash(template)
  send_hash = {}
  NoNotifierNeeded::Config::VALID_OPTIONS_KEYS.each do |k|
    send_hash[k] = NoNotifierNeeded.send(k)
  end

  send_hash[:subject] = render_template_subject_type(@template)

  send_hash[:to] = @to if @to
  send_hash[:to] ||= @user.email if @user
  send_hash[:to] ||= template.sent_to.split(',')

  send_hash[:from] = @from unless @from.blank?
  send_hash[:from] ||= "#{send_hash.delete(:from_name)} <#{send_hash.delete(:from_email)}>"
  send_hash[:from] ||= "#{template.from_name} <#{template.from_email}>" unless template.from_name.blank? || template.from_email.blank?

  send_hash[:cc] = @cc.nil? ? nil : @cc

  send_hash[:reply_to] = @reply_to unless @reply_to.blank?
  send_hash[:reply_to] ||= "#{template.reply_to}" unless template.reply_to.blank?

  send_hash
end

#known_modelsObject



50
51
52
53
54
55
56
# File 'lib/no_notifier_needed/translate.rb', line 50

def known_models
  @known_models if @known_models
  @known_models = ActiveRecord::Base.send( :descendants ).flatten.uniq
  @known_models += @known_models.collect{|k| k.send(:descendants) }.flatten.uniq
  @known_models.uniq!
  @known_models
end