Class: Soryo::SendCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/commands/sendcommand.rb

Instance Attribute Summary

Attributes inherited from Command

#config

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

add_options, descendants, #get_settings_file

Constructor Details

#initialize(template, email, options, instructions) ⇒ SendCommand

Returns a new instance of SendCommand.



5
6
7
8
9
10
# File 'lib/commands/sendcommand.rb', line 5

def initialize(template, email, options, instructions)
    super(options)
    @template = Soryo::FileInstance.new template
    @email = Soryo::FileInstance.new email
    @instructions = Soryo::FileInstance.new instructions
end

Class Method Details

.add_command(program) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/commands/sendcommand.rb', line 29

def self.add_command(program)
    program.command(:send) do |c|
        c.syntax "send <template> <json> <email instructions> [options]"
        c.description "Build an email using a template and send it to the world"

        c.option "test_type", "--test_type", "choose the type of testing you want"

        c.action do |args, options|
            if args.length != 3
                abort('Please enter a template, email, and instructions')
            end
            command = Soryo::SendCommand.new(args[0], args[1], options, args[2])
            command.build
        end

        self.add_options(c)
    end
end

Instance Method Details

#buildObject



12
13
14
15
16
17
# File 'lib/commands/sendcommand.rb', line 12

def build
    template_builder = Soryo::Template.new(@template.to_s, @email.to_hash)
    final_email = template_builder.compile
    # Run the plugins
    send final_email
end

#send(email) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/commands/sendcommand.rb', line 20

def send(email)
    Soryo::Sender.descendants.each do |c|
        if c.sender_name == @config["send_type"]
            sender = c.new
            sender.run(email, @config)
        end
    end
end