Class: Soryo::TestCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/commands/testcommand.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) ⇒ TestCommand

Returns a new instance of TestCommand.



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

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

Class Method Details

.add_command(program) ⇒ Object



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

def self.add_command(program)
    program.command(:test) do |c|
        c.syntax "test <template> <json> [options]"
        c.description "Build an email using a template"

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

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

        self.add_options(c)
    end
end

Instance Method Details

#buildObject



11
12
13
14
15
16
# File 'lib/commands/testcommand.rb', line 11

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

#test(email) ⇒ Object



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

def test(email)
    Soryo::Tester.descendants.each do |c|
        if c.tester_name == @config["test_type"]
            tester = c.new
            tester.run(email, @config)
        end
    end
end