Skip to content

Commit

Permalink
style(rubocop): Naming/MemoizedInstanceVariableName
Browse files Browse the repository at this point in the history
  • Loading branch information
adamcooke committed Feb 12, 2024
1 parent 00a02f2 commit 9563f30
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
2 changes: 2 additions & 0 deletions app/jobs/unqueue_message_job.rb
Expand Up @@ -455,12 +455,14 @@ def perform

private

# rubocop:disable Naming/MemoizedInstanceVariableName
def cached_sender(klass, *args)
@sender ||= begin
sender = klass.new(*args)
sender.start
sender
end
end
# rubocop:enable Naming/MemoizedInstanceVariableName

end
10 changes: 5 additions & 5 deletions app/models/incoming_message_prototype.rb
Expand Up @@ -24,11 +24,11 @@ def from_address
end

def route
@routes ||= if @to.present?
uname, domain = @to.split("@", 2)
uname, _tag = uname.split("+", 2)
@server.routes.includes(:domain).where(domains: { name: domain }, name: uname).first
end
@route ||= if @to.present?
uname, domain = @to.split("@", 2)
uname, _tag = uname.split("+", 2)
@server.routes.includes(:domain).where(domains: { name: domain }, name: uname).first
end
end

def attachments
Expand Down
10 changes: 4 additions & 6 deletions app/models/outgoing_message_prototype.rb
Expand Up @@ -49,13 +49,11 @@ def domain
end

def find_domain
@domain ||= begin
domain = @server.authenticated_domain_for_address(@from)
if @server.allow_sender? && domain.nil?
domain = @server.authenticated_domain_for_address(@sender)
end
domain || :none
domain = @server.authenticated_domain_for_address(@from)
if @server.allow_sender? && domain.nil?
domain = @server.authenticated_domain_for_address(@sender)
end
domain || :none
end

def to_addresses
Expand Down
6 changes: 3 additions & 3 deletions lib/postal/query_string.rb
Expand Up @@ -8,12 +8,12 @@ def initialize(string)
end

def [](value)
to_hash[value.to_s]
hash[value.to_s]
end

delegate :empty?, to: :to_hash
delegate :empty?, to: :hash

def to_hash
def hash
@hash ||= @string.scan(/([a-z]+):\s*(?:(\d{2,4}-\d{2}-\d{2}\s\d{2}:\d{2})|"(.*?)"|(.*?))(\s|\z)/).each_with_object({}) do |(key, date, string_with_spaces, value), hash|
if date
actual_value = date
Expand Down
2 changes: 1 addition & 1 deletion lib/postal/worker.rb
Expand Up @@ -202,7 +202,7 @@ def logger
end

def job_channel
@channel ||= Postal::RabbitMQ.create_channel
@job_channel ||= Postal::RabbitMQ.create_channel
end

def job_queue(name)
Expand Down
22 changes: 11 additions & 11 deletions spec/lib/postal/query_string_spec.rb
Expand Up @@ -5,40 +5,40 @@
describe Postal::QueryString do
it "should work with a single item" do
qs = Postal::QueryString.new("to: test@example.com")
expect(qs.to_hash["to"]).to eq "test@example.com"
expect(qs.hash["to"]).to eq "test@example.com"
end

it "should work with a multiple items" do
qs = Postal::QueryString.new("to: test@example.com from: another@example.com")
expect(qs.to_hash["to"]).to eq "test@example.com"
expect(qs.to_hash["from"]).to eq "another@example.com"
expect(qs.hash["to"]).to eq "test@example.com"
expect(qs.hash["from"]).to eq "another@example.com"
end

it "should not require a space after the field name" do
qs = Postal::QueryString.new("to:test@example.com from:another@example.com")
expect(qs.to_hash["to"]).to eq "test@example.com"
expect(qs.to_hash["from"]).to eq "another@example.com"
expect(qs.hash["to"]).to eq "test@example.com"
expect(qs.hash["from"]).to eq "another@example.com"
end

it "should return nil when it receives blank" do
qs = Postal::QueryString.new("to:[blank]")
expect(qs.to_hash["to"]).to eq nil
expect(qs.hash["to"]).to eq nil
end

it "should handle dates with spaces" do
qs = Postal::QueryString.new("date: 2017-02-12 15:20")
expect(qs.to_hash["date"]).to eq("2017-02-12 15:20")
expect(qs.hash["date"]).to eq("2017-02-12 15:20")
end

it "should return an array for multiple items" do
qs = Postal::QueryString.new("to: test@example.com to: another@example.com")
expect(qs.to_hash["to"]).to be_a(Array)
expect(qs.to_hash["to"][0]).to eq "test@example.com"
expect(qs.to_hash["to"][1]).to eq "another@example.com"
expect(qs.hash["to"]).to be_a(Array)
expect(qs.hash["to"][0]).to eq "test@example.com"
expect(qs.hash["to"][1]).to eq "another@example.com"
end

it "should work with a z in the string" do
qs = Postal::QueryString.new("to: testaz@example.com")
expect(qs.to_hash["to"]).to eq "testaz@example.com"
expect(qs.hash["to"]).to eq "testaz@example.com"
end
end

0 comments on commit 9563f30

Please sign in to comment.