Class: Inkcite::Cli::Preview

Inherits:
Object
  • Object
show all
Defined in:
lib/inkcite/cli/preview.rb

Class Method Summary collapse

Class Method Details

.invoke(email, to, opt) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/inkcite/cli/preview.rb', line 7

def self.invoke email, to, opt

  # Push the browser preview(s) up to the server to ensure that the
  # latest images and "view in browser" versions are available.
  email.upload unless opt[:'no-upload']

  also = opt[:also]
  unless also.blank?

    # Sometimes people use commas to separate the --also addresses so
    # explode those into an array for convenience. Email is already
    # hard enough.
    if also.any? { |a| a.match(',') }
      also = also.collect { |a| a.split(',') }.flatten

      # Since opt is frozen by Thor we need to make a copy of it in order
      # to inject the new array of recipients back into it.
      opt = opt.dup
      opt[:also] = also

    end
  end

  case to.to_sym
    when :client
      Inkcite::Mailer.client(email, opt)
    when :internal
      Inkcite::Mailer.internal(email, opt)
    when :developer
      Inkcite::Mailer.developer(email, opt)
    else
      abort <<-USAGE.strip_heredoc

        Oops!  Inkcite doesn't recognize that distribution list.  It needs
        to be one of 'client', 'internal' or 'developer':

          inkcite preview internal

      USAGE
  end

end