Skip to content

Commit

Permalink
Merge pull request #7 from brodock/feature/templates
Browse files Browse the repository at this point in the history
Add message templates for slack and default
  • Loading branch information
esigler committed Aug 22, 2015
2 parents 6eba48b + f38cee5 commit 95e10e8
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions .rspec
@@ -0,0 +1 @@
--color --profile 5
5 changes: 4 additions & 1 deletion lib/lita-dig.rb
Expand Up @@ -5,5 +5,8 @@
)]

require 'net/dns'

require 'lita/handlers/dig'

Lita::Handlers::Dig.template_root File.expand_path(
File.join('..', '..', 'templates'), __FILE__
)
8 changes: 2 additions & 6 deletions lib/lita/handlers/dig.rb
Expand Up @@ -49,15 +49,11 @@ def lookup(argument, type, server = nil)
end

def format_lookup(lookup, compact = false)
result = ''
if compact
lookup.each_address do |ip|
result += "#{ip}\n"
end
render_template('compact', lookup: lookup)
else
result = lookup.to_s
render_template('full', lookup: lookup)
end
result
end
end

Expand Down
6 changes: 4 additions & 2 deletions spec/lita/handlers/dig_spec.rb
Expand Up @@ -31,7 +31,9 @@

let(:resolve_short) do
list = double
allow(list).to receive(:each_address).and_yield('1.2.3.4')
allow(list).to receive(:each_address)
.and_yield('1.2.3.4')
.and_yield('5.6.7.8')
client = double
allow(client).to receive(:nameservers=) { '' }
expect(client).to receive(:query) { list }
Expand All @@ -58,7 +60,7 @@
it 'shows a short record if the domain exists' do
expect(Net::DNS::Resolver).to receive(:new) { resolve_short }
send_command('dig example.com +short')
expect(replies.last).to eq("1.2.3.4\n")
expect(replies.last).to eq("1.2.3.4\n5.6.7.8\n")
end

it 'shows a warning if the domain does not exist' do
Expand Down
3 changes: 3 additions & 0 deletions templates/compact.erb
@@ -0,0 +1,3 @@
<% @lookup.each_address do |ip| %>
<%= "#{ip}\n" %>
<% end %>
3 changes: 3 additions & 0 deletions templates/compact.slack.erb
@@ -0,0 +1,3 @@
<% @lookup.each_address do |ip| %>
`<%= ip %>`
<% end %>
1 change: 1 addition & 0 deletions templates/full.erb
@@ -0,0 +1 @@
<%= @lookup %>
1 change: 1 addition & 0 deletions templates/full.slack.erb
@@ -0,0 +1 @@
```<%= @lookup %>```

0 comments on commit 95e10e8

Please sign in to comment.